mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Implemented parse_args with unicode compatibility
This commit is contained in:
parent
60cad8d296
commit
51786f67a6
@ -65,11 +65,18 @@ parse_args(const char * const inp, int min, int max)
|
|||||||
int token_size = 0;
|
int token_size = 0;
|
||||||
GSList *tokens = NULL;
|
GSList *tokens = NULL;
|
||||||
|
|
||||||
|
|
||||||
// add tokens to GSList
|
// add tokens to GSList
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < inp_size; i++) {
|
for (i = 0; i < inp_size; i++) {
|
||||||
gchar *curr_ch = g_utf8_offset_to_pointer(copy, i);
|
gchar *curr_ch = g_utf8_offset_to_pointer(copy, i);
|
||||||
gunichar curr_uni = g_utf8_get_char(curr_ch);
|
gunichar curr_uni = g_utf8_get_char(curr_ch);
|
||||||
|
|
||||||
|
gchar *character = malloc(7);
|
||||||
|
gint num_written = 0;
|
||||||
|
num_written = g_unichar_to_utf8(curr_uni, character);
|
||||||
|
character[num_written] = '\0';
|
||||||
|
|
||||||
if (!in_token) {
|
if (!in_token) {
|
||||||
if (curr_uni == ' ') {
|
if (curr_uni == ' ') {
|
||||||
continue;
|
continue;
|
||||||
@ -78,10 +85,15 @@ parse_args(const char * const inp, int min, int max)
|
|||||||
if (curr_uni == '"') {
|
if (curr_uni == '"') {
|
||||||
in_quotes = TRUE;
|
in_quotes = TRUE;
|
||||||
i++;
|
i++;
|
||||||
}
|
gchar *next_ch = g_utf8_next_char(curr_ch);
|
||||||
|
gunichar next_uni = g_utf8_get_char(next_ch);
|
||||||
|
token_start = next_ch;
|
||||||
|
token_size += g_unichar_to_utf8(next_uni, NULL);
|
||||||
|
} else {
|
||||||
token_start = curr_ch;
|
token_start = curr_ch;
|
||||||
token_size += g_unichar_to_utf8(curr_uni, NULL);
|
token_size += g_unichar_to_utf8(curr_uni, NULL);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (in_quotes) {
|
if (in_quotes) {
|
||||||
if (curr_uni == '"') {
|
if (curr_uni == '"') {
|
||||||
@ -101,13 +113,14 @@ parse_args(const char * const inp, int min, int max)
|
|||||||
in_token = FALSE;
|
in_token = FALSE;
|
||||||
} else {
|
} else {
|
||||||
token_size += g_unichar_to_utf8(curr_uni, NULL);
|
token_size += g_unichar_to_utf8(curr_uni, NULL);
|
||||||
token_size++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (in_token) {
|
||||||
tokens = g_slist_append(tokens, g_strndup(token_start, token_size));
|
tokens = g_slist_append(tokens, g_strndup(token_start, token_size));
|
||||||
|
}
|
||||||
|
|
||||||
int num = g_slist_length(tokens) - 1;
|
int num = g_slist_length(tokens) - 1;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user