Pārlūkot izejas kodu

Add new function to string delegate find_close_quote will find a single quote on a string starting at the given start point default to 0, any adjacent double quotes are skipped.
Ex: "\"a day \"\"BLUE\"\" is a nice day\"" starting at position 1 (past first quote) i will give the position of the last single quote after day.

mingodad 13 gadi atpakaļ
vecāks
revīzija
ded4631ac8
1 mainītis faili ar 18 papildinājumiem un 0 dzēšanām
  1. 18 0
      squirrel/sqbaselib.cpp

+ 18 - 0
squirrel/sqbaselib.cpp

@@ -1242,6 +1242,23 @@ static SQInteger string_replace(HSQUIRRELVM v) {
     return 1;
 }
 
+static SQInteger string_find_close_quote(HSQUIRRELVM v) {
+    SQ_FUNC_VARS(v);
+    SQ_GET_STRING(v, 1, src);
+    SQ_OPT_INTEGER(v, 2, init, 0);
+    if(init >= src_size) return sq_throwerror(v, _SC("invalid start position"));
+
+    for(; init < src_size; ++init) {
+        if(src[init] == '"'){
+             if(src[init+1] == '"') ++init; //skip quoted quote
+             else break;
+        }
+    }
+    if(src[init] != '"') init = -1;
+    sq_pushinteger(v, init);
+    return 1;
+}
+
 static SQInteger string_getdelegate(HSQUIRRELVM v)
 {
 	return SQ_SUCCEEDED(sq_getdelegate(v,-1))?1:SQ_ERROR;
@@ -1258,6 +1275,7 @@ SQRegFunction SQSharedState::_string_default_delegate_funcz[]={
 	{_SC("replace"),string_replace,3, _SC("sss")},
 	{_SC("find"),string_find,-2, _SC("s s n ")},
 	{_SC("find_lua"),string_find_lua,-3, _SC("ss a|t|c nb")},
+	{_SC("find_close_quote"),string_find_close_quote,-1, _SC("sn")},
 	{_SC("gsub"),string_gsub,-3, _SC("s s s|a|t|c n")},
 	{_SC("gmatch"),string_gmatch, 3, _SC("s s c")},
 	{_SC("tolower"),string_tolower,1, _SC("s")},