ext/ccsv.c in ccsv-1.0.4 vs ext/ccsv.c in ccsv-1.1.0

- old
+ new

@@ -10,11 +10,11 @@ }; #define MAX_INTERVALS 1024 static VALUE foreach(int argc, VALUE* argv, VALUE self) { - char DELIM=DEF_DELIM; + char *DELIM=DEF_DELIM; char *line = NULL; size_t len = 0; char *token,*start,*nobackslash,*t2, *str; int idx,count,pairs_count,searchfield,flag,i,array_length,range_i,len2; long check; @@ -42,12 +42,11 @@ rb_raise(rb_eRuntimeError, "File not found"); } if (argc >1 ) { /* delimiter */ tmp_value=rb_ary_entry(rest_args,0); - str=StringValueCStr(tmp_value); - DELIM=str[0]; + DELIM=StringValueCStr(tmp_value);; } if (argc >2 ) { /* search index */ tmp_value=rb_ary_entry(rest_args,1); searchfield=NUM2INT(tmp_value); @@ -99,11 +98,11 @@ } /*rb_warning("4\n");*/ ary = rb_ary_new(); start=line; nobackslash=line; - while(token=index(nobackslash, DELIM)){ + while(token=strstr(nobackslash, DELIM)){ /*rb_warning("5\n");*/ count=0; t2=token-1; while((t2>=line) && (*t2=='\\')) {++count;--t2;} @@ -136,17 +135,17 @@ if(flag==0) break; rb_ary_store(ary, idx, rb_str_new(start, token-start)); idx++; - nobackslash=start=token+1; - while(token=index(nobackslash, DELIM)){ + nobackslash=start=token+strlen(DELIM); + while(token=strstr(nobackslash, DELIM)){ count=0; t2=token-1; while((t2>=line) && (*t2=='\\')) {++count;--t2;} if(count%2 ==1){ /* backslashed! skip */ - nobackslash=token; + nobackslash=token+strlen(DELIM); continue; } break; } }