[latexila] Completion: use string.get_prev_char() (finished)
- From: SÃbastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila] Completion: use string.get_prev_char() (finished)
- Date: Wed, 18 Jul 2012 21:24:00 +0000 (UTC)
commit feda3855987a095667470d1c2a7578310faa8f22
Author: SÃbastien Wilmet <swilmet src gnome org>
Date: Wed Jul 18 23:18:21 2012 +0200
Completion: use string.get_prev_char() (finished)
In in_latex_command_argument().
The reason to make several commits for the same thing is to ease the
finding of a potential bug in this (tricky) code. git bisect will tell
exactly where is the bug.
Obviously, I hope there is no regressions ;)
src/completion.vala | 22 ++++------------------
src/utils.vala | 15 ---------------
2 files changed, 4 insertions(+), 33 deletions(-)
---
diff --git a/src/completion.vala b/src/completion.vala
index 5dee00e..073e105 100644
--- a/src/completion.vala
+++ b/src/completion.vala
@@ -549,10 +549,9 @@ public class CompletionProvider : GLib.Object, SourceCompletionProvider
/* Fetch the argument's contents */
while (true)
{
- int prev_index = cur_index;
unichar cur_char;
- bool first_char = ! Utils.string_get_prev_char (text,
- ref prev_index, out cur_char);
+ if (! text.get_prev_char (ref cur_index, out cur_char))
+ return false;
// End of the argument's contents.
bool opening_bracket = cur_char == '{' || cur_char == '[';
@@ -560,15 +559,8 @@ public class CompletionProvider : GLib.Object, SourceCompletionProvider
{
info.args_types.insert (0, cur_char == '[');
info.arg_contents = text[cur_index + 1 : last_index];
- cur_index = prev_index;
break;
}
-
- // Not in an argument.
- if (first_char)
- return false;
-
- cur_index = prev_index;
}
/* Traverse the previous arguments, and find the command name */
@@ -577,10 +569,9 @@ public class CompletionProvider : GLib.Object, SourceCompletionProvider
while (true)
{
- int prev_index = cur_index;
unichar cur_char;
- bool first_char = ! Utils.string_get_prev_char (text,
- ref prev_index, out cur_char);
+ if (! text.get_prev_char (ref cur_index, out cur_char))
+ return false;
// In the contents of a previous argument.
if (in_prev_arg)
@@ -611,11 +602,6 @@ public class CompletionProvider : GLib.Object, SourceCompletionProvider
// Spaces are allowed between arguments.
else if (! cur_char.isspace ())
return false;
-
- if (first_char)
- return false;
-
- cur_index = prev_index;
}
}
diff --git a/src/utils.vala b/src/utils.vala
index 56337dd..9898575 100644
--- a/src/utils.vala
+++ b/src/utils.vala
@@ -52,21 +52,6 @@ namespace Utils
return escaped;
}
- // The opposite of string.get_next_char ().
- // TODO remove this function when it is included upstream
- // See https://bugzilla.gnome.org/show_bug.cgi?id=655185
- public bool string_get_prev_char (string str, ref int index, out unichar c)
- {
- c = str.get_char (index);
- if (index <= 0)
- return false;
-
- unowned string str_at_index = (string) ((char*) str + index);
- unowned string str_prev = str_at_index.prev_char ();
- index = (int) ((char*) str_prev - (char*) str);
- return true;
- }
-
public unowned string? get_string_from_resource (string resource_path)
{
try
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]