removed quote_string: use glib regex
From 7eb9d24a5d9124ca959778dda3f7ff4a0f87a6d4
This commit is contained in:
parent
de54e6311c
commit
49443fe20b
|
@ -264,22 +264,6 @@ void gtk_completion_line_last_history_item(GtkCompletionLine* object) {
|
|||
}
|
||||
}
|
||||
|
||||
string quote_string(const string& str)
|
||||
{
|
||||
string res;
|
||||
const char* i = str.c_str();
|
||||
while (*i) {
|
||||
char c = *i++;
|
||||
switch (c) {
|
||||
case ' ':
|
||||
res += '\\';
|
||||
default:
|
||||
res += c;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static void
|
||||
get_token(istream& is, string& s)
|
||||
{
|
||||
|
@ -341,19 +325,24 @@ set_words(GtkCompletionLine *object, const vector<string>& words, int pos = -1)
|
|||
int cur = 0;
|
||||
|
||||
vector<string>::const_iterator
|
||||
i = words.begin(),
|
||||
i_end = words.end();
|
||||
i = words.begin(),
|
||||
i_end = words.end();
|
||||
|
||||
GRegex *regex = g_regex_new (" ", G_REGEX_OPTIMIZE, G_REGEX_MATCH_NOTEMPTY, NULL);
|
||||
while (i != i_end) {
|
||||
ss << quote_string(*i++);
|
||||
gchar *quoted = g_regex_replace_literal (
|
||||
regex, (*i++).c_str(), -1, 0, "\\ ", G_REGEX_MATCH_NOTEMPTY, NULL);
|
||||
ss << quoted;
|
||||
if (i != i_end)
|
||||
ss << ' ';
|
||||
if (!pos && !cur)
|
||||
cur = ss.tellp();
|
||||
else
|
||||
--pos;
|
||||
g_free(quoted);
|
||||
}
|
||||
ss << ends;
|
||||
g_regex_unref (regex);
|
||||
|
||||
if (words.size() == 1) {
|
||||
const string& s = words.back();
|
||||
|
|
|
@ -304,8 +304,12 @@ ext_check(GtkCompletionLine *cl, struct gigi *g)
|
|||
i = words.begin(),
|
||||
i_end = words.end();
|
||||
|
||||
|
||||
GRegex *regex = g_regex_new (" ", G_REGEX_OPTIMIZE, G_REGEX_MATCH_NOTEMPTY, NULL);
|
||||
while (i != i_end) {
|
||||
const string& w = quote_string(*i++);
|
||||
gchar *quoted = g_regex_replace_literal (
|
||||
regex, (*i++).c_str(), -1, 0, "\\ ", G_REGEX_MATCH_NOTEMPTY, NULL);
|
||||
const string w = quoted;
|
||||
if (w[0] == '/') {
|
||||
// absolute path, check for extension
|
||||
size_t pos = w.rfind('.');
|
||||
|
@ -325,9 +329,11 @@ ext_check(GtkCompletionLine *cl, struct gigi *g)
|
|||
}
|
||||
}
|
||||
}
|
||||
g_free(quoted);
|
||||
// FIXME: for now we check only one entry
|
||||
break;
|
||||
}
|
||||
g_regex_unref(regex);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue