summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-05-11 14:31:07 -0600
committermo khan <mo.khan@gmail.com>2020-05-11 14:31:07 -0600
commitbcc5db98b162b5a621fae1f633139a6d8abda6b2 (patch)
tree974c696f090322f9f2fd6bab6f50c8f1a9e15908 /ext
parent8776ba84032e76578296754d18ab1ac45d940fb1 (diff)
define an enum to toggle the state
Diffstat (limited to 'ext')
-rw-r--r--ext/spandx/spandx.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/ext/spandx/spandx.c b/ext/spandx/spandx.c
index 9004bab..83d165f 100644
--- a/ext/spandx/spandx.c
+++ b/ext/spandx/spandx.c
@@ -12,7 +12,8 @@ static VALUE parse(VALUE self, VALUE line)
char current_value[length];
int current_value_length = 0;
char current_charactor;
- int state = 1;
+ enum {open, closed} state;
+ state = open;
int items_in_array = 0;
for (int i = 1; i < length; i++) {
@@ -20,19 +21,19 @@ static VALUE parse(VALUE self, VALUE line)
switch(current_charactor) {
case '"':
- if (state == 0) {
- state = 1;
+ if (state == closed) {
+ state = open;
} else {
rb_ary_push(items, rb_str_new(current_value, current_value_length));
items_in_array++;
if (items_in_array == 3) return items;
current_value_length = 0;
- state = 0;
+ state = closed;
}
break;
case ',':
- if (state == 1)
+ if (state == open)
current_value[current_value_length++] = current_charactor;
break;
default: