Sha256: ed93c159ebf3dc48bff43366ea564e0ffa26a53c211e9c4b5904992c1e50431c
Contents?: true
Size: 1.16 KB
Versions: 4
Compression:
Stored size: 1.16 KB
Contents
#include "spandx.h" #define NEWLINE 10 VALUE rb_mSpandx; VALUE rb_mCore; VALUE rb_mCsvParser; // "name","version","license" // "name","version","license"\n // "name","version","license"\r // "name","version","license"\r\n // "name","version",""\r\n VALUE parse(VALUE self, VALUE line) { if (NIL_P(line)) return Qnil; char *p; p = RSTRING_PTR(line); if (*p != '"') return Qnil; const VALUE items = rb_ary_new2(3); const char *s, *n; const long len = RSTRING_LEN(line); enum { open, closed } state = closed; for (int i = 0; i < len && *p; i++) { if (*p == '"') { n = p; if (i < (len - 1)) *n++; if (state == closed) { s = n; state = open; } else if (state == open) { if (!*n || n == p || *n == ',' || *n == NEWLINE) { rb_ary_push(items, rb_str_new(s, p - s)); state = closed; } } } *(p++); } return items; } void Init_spandx(void) { rb_mSpandx = rb_define_module("Spandx"); rb_mCore = rb_define_module_under(rb_mSpandx, "Core"); rb_mCsvParser = rb_define_module_under(rb_mCore, "CsvParser"); rb_define_module_function(rb_mCsvParser, "parse", parse, 1); }
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
spandx-0.15.0 | ext/spandx/spandx.c |
spandx-0.14.0 | ext/spandx/spandx.c |
spandx-0.13.5 | ext/spandx/spandx.c |
spandx-0.13.4 | ext/spandx/spandx.c |