Browse Source

Fix for the empty capture on string.match

mingodad 7 years ago
parent
commit
568f8aa706
2 changed files with 14 additions and 1 deletions
  1. 5 1
      SquiLu/squirrel/sqbaselib.cpp
  2. 9 0
      SquiLu/tests/squilu-test.nut

+ 5 - 1
SquiLu/squirrel/sqbaselib.cpp

@@ -1619,7 +1619,11 @@ SQRESULT string_gmatch_base(HSQUIRRELVM v, int isGmatch, const SQChar *src, SQIn
     if(ms.error) return sq_throwerror(v, ms.error);
     if(ms.error) return sq_throwerror(v, ms.error);
     if(_rc_ < 0) sq_pushnull(v);
     if(_rc_ < 0) sq_pushnull(v);
     else if(ms.level){
     else if(ms.level){
-        if(ms.level == 1) sq_pushstring(v, ms.capture[0].init, ms.capture[0].len);
+        if(ms.level == 1)
+        {
+            if(ms.capture[0].len == CAP_POSITION) sq_pushinteger(v, ms.capture[0].init - ms.src_init);
+            else sq_pushstring(v, ms.capture[0].init, ms.capture[0].len);
+        }
         else {
         else {
             sq_newarray(v, ms.level);
             sq_newarray(v, ms.level);
             for(int i=0; i < ms.level; ++i){
             for(int i=0; i < ms.level; ++i){

+ 9 - 0
SquiLu/tests/squilu-test.nut

@@ -705,6 +705,13 @@ sqt.run("pattern matching", function(){
 
 
 	sqt.ok(a.len() == 0)
 	sqt.ok(a.len() == 0)
 
 
+	local src_str = "abcdef";
+	local re_str = "c()";
+	sqt.ok(src_str.match(re_str) == 3);
+
+	re = regexp(re_str);
+	sqt.ok(re.match(src_str) == 3);
+
 });
 });
 
 
 sqt.run("regexp", function(){
 sqt.run("regexp", function(){
@@ -1538,6 +1545,8 @@ sqt.run("number", function(){
 
 
 	sqt.ok((5 * 3) == 15);
 	sqt.ok((5 * 3) == 15);
 	sqt.ok((12.34 * 0.3) == 3.702);
 	sqt.ok((12.34 * 0.3) == 3.702);
+	
+	sqt.ok(format("%.17g", 1e16 + 2.9999) == "10000000000000002");
 
 
 });
 });