Ver Fonte

Fix bug wrong interpretation of return value of string.find that return -1 when not found.

mingodad há 10 anos atrás
pai
commit
debc0f18a0
2 ficheiros alterados com 4 adições e 4 exclusões
  1. 2 2
      SquiLu/samples/csv2array.nut
  2. 2 2
      SquiLu/samples/test-replace.nut

+ 2 - 2
SquiLu/samples/csv2array.nut

@@ -13,13 +13,13 @@ function fromCSV (s){
 //print(f, f.replace("\"\"", "\""));
 //print(f, f.replace("\"\"", "\""));
       t.push(f.replace("\"\"", "\""));
       t.push(f.replace("\"\"", "\""));
        local nextc = s.find(",", i);
        local nextc = s.find(",", i);
-       if(!nextc) nextc=slen-1;
+       if(nextc < 0) nextc=slen-1;
       fieldstart = nextc + 1;
       fieldstart = nextc + 1;
     }  
     }  
     else                // unquoted; find next comma
     else                // unquoted; find next comma
     {
     {
       local nexti = s.find(",", fieldstart);
       local nexti = s.find(",", fieldstart);
-      if(!nexti) nexti = slen-1;
+      if(nexti < 0) nexti = slen-1;
 //print("nn", fieldstart, nexti, s.slice(fieldstart, nexti))
 //print("nn", fieldstart, nexti, s.slice(fieldstart, nexti))
       t.push(s.slice(fieldstart, nexti));
       t.push(s.slice(fieldstart, nexti));
       fieldstart = nexti + 1;
       fieldstart = nexti + 1;

+ 2 - 2
SquiLu/samples/test-replace.nut

@@ -31,13 +31,13 @@ function fromCSV (s){
 //print(f, f.replace("\"\"", "\""));
 //print(f, f.replace("\"\"", "\""));
       t.push(f.replace("\"\"", "\""));
       t.push(f.replace("\"\"", "\""));
        local nextc = s.find(",", i);
        local nextc = s.find(",", i);
-       if(!nextc) nextc=slen-1;
+       if(nextc < 0) nextc=slen-1;
       fieldstart = nextc + 1;
       fieldstart = nextc + 1;
     }  
     }  
     else                // unquoted; find next comma
     else                // unquoted; find next comma
     {
     {
       local nexti = s.find(",", fieldstart);
       local nexti = s.find(",", fieldstart);
-      if(!nexti) nexti = slen-1;
+      if(nexti < 0) nexti = slen-1;
 //print("nn", fieldstart, nexti, s.slice(fieldstart, nexti))
 //print("nn", fieldstart, nexti, s.slice(fieldstart, nexti))
       t.push(s.slice(fieldstart, nexti));
       t.push(s.slice(fieldstart, nexti));
       fieldstart = nexti + 1;
       fieldstart = nexti + 1;