diff options
author | koekeishiya <aasvi93@hotmail.com> | 2017-08-24 13:40:46 +0200 |
---|---|---|
committer | koekeishiya <aasvi93@hotmail.com> | 2017-08-24 13:40:46 +0200 |
commit | d6bcc6167b79814171071406161a3f5d57a8cf42 (patch) | |
tree | bf958374c3d190dc0c647c72a59a918d7b92ef33 /src | |
parent | b9040ee1b687b3d8407e0009be16374d3556ddef (diff) | |
download | skhd-d6bcc6167b79814171071406161a3f5d57a8cf42.tar.gz skhd-d6bcc6167b79814171071406161a3f5d57a8cf42.zip |
#2 get rid of strncmp
Diffstat (limited to 'src')
-rw-r--r-- | src/parse.c | 10 | ||||
-rw-r--r-- | src/tokenize.c | 9 |
2 files changed, 8 insertions, 11 deletions
diff --git a/src/parse.c b/src/parse.c index 0ec0209..b279ead 100644 --- a/src/parse.c +++ b/src/parse.c @@ -32,12 +32,6 @@ read_file(const char *file) return buffer; } -internal inline bool -same_string(char *text, unsigned length, const char *match) -{ - return strncmp(text, match, length) == 0; -} - internal char * copy_string_count(char *s, int length) { @@ -109,7 +103,7 @@ parse_key_literal(struct parser *parser) // NOTE(koekeishiya): Might want to replace this mapping with a hashtable for(int i = 0; i < array_count(literal_keycode_str); ++i) { - if(same_string(key.text, key.length, literal_keycode_str[i])) { + if(token_equals(key, literal_keycode_str[i])) { keycode = literal_keycode_value[i]; printf("\tkey: '%.*s' (0x%02x)\n", key.length, key.text, keycode); break; @@ -135,7 +129,7 @@ parse_modifier(struct parser *parser) // NOTE(koekeishiya): Might want to replace this mapping with a hashtable for(int i = 0; i < array_count(modifier_flags_str); ++i) { - if(same_string(modifier.text, modifier.length, modifier_flags_str[i])) { + if(token_equals(modifier, modifier_flags_str[i])) { flags |= modifier_flags_value[i]; printf("\tmod: '%s'\n", modifier_flags_str[i]); break; diff --git a/src/tokenize.c b/src/tokenize.c index 5f83084..822bc70 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -7,9 +7,12 @@ internal int token_equals(struct token token, const char *match) { const char *at = match; - unsigned index = 0; - while(*at++ == token.text[index++] && index < token.length); - return (*at == '\0' && index == token.length) ? 1 : 0; + for(int i = 0; i < token.length; ++i, ++at) { + if((*at == 0) || (token.text[i] != *at)) { + return false; + } + } + return (*at == 0); } internal void |