3 #include <sqstdstring.h> 11 #define scstrchr wcschr 12 #define scsnprintf wsnprintf 14 #define scstrtok wcstok 16 #define scstrchr strchr 17 #define scsnprintf snprintf 19 #define scstrtok strtok 21 #define MAX_FORMAT_LEN 20 22 #define MAX_WFORMAT_LEN 3 23 #define ADDITIONAL_FORMAT_SPACE (100*sizeof(SQChar)) 31 while (
scstrchr(_SC(
"-+ #0"), src[n])) n++;
32 while (scisdigit(src[n])) {
49 while (scisdigit(src[n])) {
63 memcpy(&fmt[1],&src[start],((n-start)+1)*
sizeof(
SQChar));
64 fmt[(n-start)+2] =
'\0';
69 SQRESULT
sqstd_format(HSQUIRRELVM v,SQInteger nformatstringidx,SQInteger *outlen,
SQChar **output)
77 SQInteger n = 0,i = 0, nparam = nformatstringidx+1, w = 0;
78 while(format[n] !=
'\0') {
79 if(format[n] !=
'%') {
80 assert(i < allocated);
81 dest[i++] = format[n];
84 else if(format[n+1] ==
'%') {
92 return sq_throwerror(v,_SC(
"not enough parameters for the given format string"));
96 SQInteger valtype = 0;
103 return sq_throwerror(v,_SC(
"string expected for the specified format"));
107 case 'i':
case 'd':
case 'c':
case 'o':
case 'u':
case 'x':
case 'X':
109 return sq_throwerror(v,_SC(
"integer expected for the specified format"));
113 case 'f':
case 'g':
case 'G':
case 'e':
case 'E':
115 return sq_throwerror(v,_SC(
"float expected for the specified format"));
123 allocated += addlen +
sizeof(
SQChar);
126 case 's': i += scsprintf(&dest[i],fmt,ts);
break;
127 case 'i': i += scsprintf(&dest[i],fmt,ti);
break;
128 case 'f': i += scsprintf(&dest[i],fmt,tf);
break;
142 SQInteger length = 0;
152 while(((*t) !=
'\0') && scisspace(*t)){ t++; }
162 const SQChar *t = &str[len-1];
163 while(t != str && scisspace(*t)) { t--; }
169 const SQChar *str,*start,*end;
206 memcpy(stemp,str,memsize);
209 while( tok !=
NULL ) {
217 #define SETUP_REX(v) \ 218 SQRex *self = NULL; \ 219 sq_getinstanceup(v,1,(SQUserPointer *)&self,0); 257 const SQChar *str,*begin,*end;
271 const SQChar *str,*begin,*end;
279 for(SQInteger i = 0;i < n; i++) {
301 const SQChar *error,*pattern;
316 #define _DECL_REX_FUNC(name,nparams,pmask) {_SC(#name),_regexp_##name,nparams,pmask} 327 #define _DECL_FUNC(name,nparams,pmask) {_SC(#name),_string_##name,nparams,pmask} SQRESULT sq_newclass(HSQUIRRELVM v, SQBool hasbase)
static void _addrexmatch(HSQUIRRELVM v, const SQChar *str, const SQChar *begin, const SQChar *end)
static SQInteger _regexp__typeof(HSQUIRRELVM v)
SQRESULT sq_throwerror(HSQUIRRELVM v, const SQChar *err)
void sqstd_rex_free(SQRex *exp)
void sq_newtable(HSQUIRRELVM v)
SQRESULT sq_rawset(HSQUIRRELVM v, SQInteger idx)
static void __strip_r(const SQChar *str, SQInteger len, const SQChar **end)
SQBool sqstd_rex_search(SQRex *exp, const SQChar *text, const SQChar **out_begin, const SQChar **out_end)
static SQInteger _regexp_subexpcount(HSQUIRRELVM v)
static void __strip_l(const SQChar *str, const SQChar **start)
SQRESULT sq_arrayappend(HSQUIRRELVM v, SQInteger idx)
static SQInteger _string_rstrip(HSQUIRRELVM v)
static SQRegFunction stringlib_funcs[]
SQRESULT sq_getinteger(HSQUIRRELVM v, SQInteger idx, SQInteger *i)
SQInteger sq_getsize(HSQUIRRELVM v, SQInteger idx)
SQInteger sq_gettop(HSQUIRRELVM v)
void sq_pushinteger(HSQUIRRELVM v, SQInteger n)
void sq_newclosure(HSQUIRRELVM v, SQFUNCTION func, SQUnsignedInteger nfreevars)
SQBool sqstd_rex_getsubexp(SQRex *exp, SQInteger n, SQRexMatch *subexp)
static SQRegFunction rexobj_funcs[]
SQRESULT sq_setnativeclosurename(HSQUIRRELVM v, SQInteger idx, const SQChar *name)
static SQInteger _rexobj_releasehook(SQUserPointer p, SQInteger)
static SQInteger _regexp_capture(HSQUIRRELVM v)
static SQInteger _regexp_constructor(HSQUIRRELVM v)
SQRESULT sq_getfloat(HSQUIRRELVM v, SQInteger idx, SQFloat *f)
SQInteger sqstd_register_stringlib(HSQUIRRELVM v)
static SQInteger _string_strip(HSQUIRRELVM v)
static SQInteger _string_split(HSQUIRRELVM v)
SQRESULT sq_setparamscheck(HSQUIRRELVM v, SQInteger nparamscheck, const SQChar *typemask)
SQRex * sqstd_rex_compile(const SQChar *pattern, const SQChar **error)
void sq_pushstring(HSQUIRRELVM v, const SQChar *s, SQInteger len)
SQRESULT sq_setinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer p)
SQRESULT sq_getstring(HSQUIRRELVM v, SQInteger idx, const SQChar **c)
static SQInteger _string_lstrip(HSQUIRRELVM v)
SQBool sqstd_rex_match(SQRex *exp, const SQChar *text)
#define _DECL_REX_FUNC(name, nparams, pmask)
void sq_pushbool(HSQUIRRELVM v, SQBool b)
void sq_newarray(HSQUIRRELVM v, SQInteger size)
SQChar * sq_getscratchpad(HSQUIRRELVM v, SQInteger minsize)
SQInteger sqstd_rex_getsubexpcount(SQRex *exp)
static SQInteger _regexp_match(HSQUIRRELVM v)
void sq_setreleasehook(HSQUIRRELVM v, SQInteger idx, SQRELEASEHOOK hook)
static SQInteger _regexp_search(HSQUIRRELVM v)
#define _DECL_FUNC(name, nparams, pmask)