diff options
author | James Booth <boothj5@gmail.com> | 2013-07-14 00:14:36 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2013-07-14 00:14:36 +0100 |
commit | 51786f67a6f453ff5ac96aee08cf814eb3bcfd4d (patch) | |
tree | eda7fcea695bd1ca86ba668218e15c3adb686de3 /src/tools | |
parent | 60cad8d29631443a5787b2052dd22716b284ee35 (diff) | |
download | profani-tty-51786f67a6f453ff5ac96aee08cf814eb3bcfd4d.tar.gz |
Implemented parse_args with unicode compatibility
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/parser.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/tools/parser.c b/src/tools/parser.c index c8335879..42b1165f 100644 --- a/src/tools/parser.c +++ b/src/tools/parser.c @@ -65,11 +65,18 @@ parse_args(const char * const inp, int min, int max) int token_size = 0; GSList *tokens = NULL; + // add tokens to GSList int i; for (i = 0; i < inp_size; i++) { gchar *curr_ch = g_utf8_offset_to_pointer(copy, i); 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 (curr_uni == ' ') { continue; @@ -78,9 +85,14 @@ parse_args(const char * const inp, int min, int max) if (curr_uni == '"') { in_quotes = TRUE; 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_size += g_unichar_to_utf8(curr_uni, NULL); } - token_start = curr_ch; - token_size += g_unichar_to_utf8(curr_uni, NULL); } } else { if (in_quotes) { @@ -101,13 +113,14 @@ parse_args(const char * const inp, int min, int max) in_token = FALSE; } else { token_size += g_unichar_to_utf8(curr_uni, NULL); - token_size++; } } } } - tokens = g_slist_append(tokens, g_strndup(token_start, token_size)); + if (in_token) { + tokens = g_slist_append(tokens, g_strndup(token_start, token_size)); + } int num = g_slist_length(tokens) - 1; |