summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-05-11 21:46:13 -0600
committermo khan <mo.khan@gmail.com>2020-05-11 21:46:13 -0600
commit40460a4d5d7d6265f8adf85eb7255c6fac739ed0 (patch)
tree36f8d35791a8a52ecdbeffdf972d564563c1b3b8 /ext
parentc1ecdae5559d357ce4364bf251b15a68f7fe4f6e (diff)
Use quick parse for easy parsing and fallback to csv for more complicated scenarios
Diffstat (limited to 'ext')
-rw-r--r--ext/spandx/spandx.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/ext/spandx/spandx.c b/ext/spandx/spandx.c
index c52382a..fda2a54 100644
--- a/ext/spandx/spandx.c
+++ b/ext/spandx/spandx.c
@@ -15,18 +15,18 @@ static VALUE parse(VALUE self, VALUE line)
if (ptr[i] == '"')
indexes[k++] = i;
- if (k >= 6) break;
+ if (k > 6) return Qnil;
}
VALUE items = rb_ary_new2(sizeof(indexes) / 2);
+ int start = 0;
for (int i = 0, j = 1; i < k; i += 2, j=i+1) {
if (indexes[i] + 1 == indexes[j]) {
rb_ary_push(items, rb_str_new_cstr(""));
} else {
- int start = indexes[i] + 1;
- int value_length = indexes[j] - start;
- rb_ary_push(items, rb_str_substr(line, start, value_length));
+ start = indexes[i] + 1;
+ rb_ary_push(items, rb_str_substr(line, start, indexes[j] - start));
}
}
return items;