MCPcopy Create free account
hub / github.com/albertodemichelis/squirrel / validate_format

Function validate_format

sqstdlib/sqstdstring.cpp:25–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23}
24
25static SQInteger validate_format(HSQUIRRELVM v, SQChar *fmt, const SQChar *src, SQInteger n,SQInteger &width)
26{
27 SQChar *dummy;
28 SQChar swidth[MAX_WFORMAT_LEN];
29 SQInteger wc = 0;
30 SQInteger start = n;
31 fmt[0] = '%';
32 while (isfmtchr(src[n])) n++;
33 while (scisdigit(src[n])) {
34 swidth[wc] = src[n];
35 n++;
36 wc++;
37 if(wc>=MAX_WFORMAT_LEN)
38 return sq_throwerror(v,_SC("width format too long"));
39 }
40 swidth[wc] = '\0';
41 if(wc > 0) {
42 width = scstrtol(swidth,&dummy,10);
43 }
44 else
45 width = 0;
46 if (src[n] == '.') {
47 n++;
48
49 wc = 0;
50 while (scisdigit(src[n])) {
51 swidth[wc] = src[n];
52 n++;
53 wc++;
54 if(wc>=MAX_WFORMAT_LEN)
55 return sq_throwerror(v,_SC("precision format too long"));
56 }
57 swidth[wc] = '\0';
58 if(wc > 0) {
59 width += scstrtol(swidth,&dummy,10);
60
61 }
62 }
63 if (n-start > MAX_FORMAT_LEN )
64 return sq_throwerror(v,_SC("format too long"));
65 memcpy(&fmt[1],&src[start],((n-start)+1)*sizeof(SQChar));
66 fmt[(n-start)+2] = '\0';
67 return n;
68}
69
70SQRESULT sqstd_format(HSQUIRRELVM v,SQInteger nformatstringidx,SQInteger *outlen,SQChar **output)
71{

Callers 1

sqstd_formatFunction · 0.85

Calls 2

isfmtchrFunction · 0.85
sq_throwerrorFunction · 0.85

Tested by

no test coverage detected