Prechádzať zdrojové kódy

Fixed the return value of str_find to return -1 when not found, before it was returning 0.
Removed an offset of -1 on the end_pos of find it was incorrect for zero based strings.

mingodad 13 rokov pred
rodič
commit
47626cab1f
1 zmenil súbory, kde vykonal 3 pridanie a 3 odobranie
  1. 3 3
      squirrel/lua-regex.c

+ 3 - 3
squirrel/lua-regex.c

@@ -382,7 +382,7 @@ static int str_find_aux (LuaMatchState *ms, int find, const char *s, int ls,
   ms->src_end = s + ls;
 
 do_again:
-  result = 0; /* not found */
+  result = -1; /* not found */
   /* explicit request or no special characters? */
   if (find && (raw_find || nospecials(p, lp))) {
     /* do a plain search */
@@ -405,7 +405,7 @@ do_again:
       ms->level = 0;
       if ((res=match(ms, s1, p)) != NULL) {
           ms->start_pos = s1-s;
-          result = ms->end_pos = res-s;
+          result = ms->end_pos = res-s-1;
           goto eofunc;
       }
     } while (s1++ < ms->src_end && !anchor);
@@ -413,7 +413,7 @@ do_again:
 
 eofunc:
 
-  if(result){
+  if(result >= 0){
       int i;
       for(i=0; i<ms->level; ++i){
           if(ms->capture[i].len == CAP_UNFINISHED){