diff options
author | yexo <yexo@openttd.org> | 2009-08-15 21:21:52 +0000 |
---|---|---|
committer | yexo <yexo@openttd.org> | 2009-08-15 21:21:52 +0000 |
commit | 03d711add39db01cde68821d879fe4da14db6300 (patch) | |
tree | 8cc353d66aadf9bf022d836d2358b7d70c9b655d /src/3rdparty/squirrel/sqstdlib/sqstdstring.cpp | |
parent | 75f8a9db0adcb89a24f4624907298b87196ba26f (diff) | |
download | openttd-03d711add39db01cde68821d879fe4da14db6300.tar.xz |
(svn r17195) -Update: squirrel to 2.2.3 stable
Diffstat (limited to 'src/3rdparty/squirrel/sqstdlib/sqstdstring.cpp')
-rw-r--r-- | src/3rdparty/squirrel/sqstdlib/sqstdstring.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/3rdparty/squirrel/sqstdlib/sqstdstring.cpp b/src/3rdparty/squirrel/sqstdlib/sqstdstring.cpp index 00b1667e0..681029aa7 100644 --- a/src/3rdparty/squirrel/sqstdlib/sqstdstring.cpp +++ b/src/3rdparty/squirrel/sqstdlib/sqstdstring.cpp @@ -79,15 +79,16 @@ static void _append_string(SQInteger &i, SQChar *dest, SQInteger allocated, cons va_end(va); } -static SQInteger _string_format(HSQUIRRELVM v) + +SQRESULT sqstd_format(HSQUIRRELVM v,SQInteger nformatstringidx,SQInteger *outlen,SQChar **output) { const SQChar *format; SQChar *dest; SQChar fmt[MAX_FORMAT_LEN]; - sq_getstring(v,2,&format); - SQInteger allocated = (sq_getsize(v,2)+1)*sizeof(SQChar); + sq_getstring(v,nformatstringidx,&format); + SQInteger allocated = (sq_getsize(v,nformatstringidx)+2)*sizeof(SQChar); dest = sq_getscratchpad(v,allocated); - SQInteger n = 0,i = 0, nparam = 3, w = 0; + SQInteger n = 0,i = 0, nparam = nformatstringidx+1, w = 0; while(format[n] != '\0') { if(format[n] != '%') { assert(i < allocated); @@ -132,7 +133,7 @@ static SQInteger _string_format(HSQUIRRELVM v) return sq_throwerror(v,_SC("invalid format")); } n++; - allocated += addlen; + allocated += addlen + sizeof(SQChar); dest = sq_getscratchpad(v,allocated); switch(valtype) { case 's': _append_string(i,dest,allocated,fmt,ts); break; @@ -142,7 +143,19 @@ static SQInteger _string_format(HSQUIRRELVM v) nparam ++; } } - sq_pushstring(v,dest,i); + *outlen = i; + dest[i] = '\0'; + *output = dest; + return SQ_OK; +} + +static SQInteger _string_format(HSQUIRRELVM v) +{ + SQChar *dest = NULL; + SQInteger length = 0; + if(SQ_FAILED(sqstd_format(v,2,&length,&dest))) + return -1; + sq_pushstring(v,dest,length); return 1; } |