1#ifndef __EEL__STRINGS_H__
2#define __EEL__STRINGS_H__
60#ifndef EEL_STRING_MAXUSERSTRING_LENGTH_HINT
61#define EEL_STRING_MAXUSERSTRING_LENGTH_HINT 16384
64#ifndef EEL_STRING_MAX_USER_STRINGS
66#define EEL_STRING_MAX_USER_STRINGS 1024
69#ifndef EEL_STRING_LITERAL_BASE
71#define EEL_STRING_LITERAL_BASE 10000
75#ifndef EEL_STRING_NAMED_BASE
76#define EEL_STRING_NAMED_BASE 90000
80#ifndef EEL_STRING_UNNAMED_BASE
81#define EEL_STRING_UNNAMED_BASE 190000
85#ifndef EEL_STRING_MUTEXLOCK_SCOPE
86 #ifdef EEL_STRING_WANT_MUTEX
88 #define EEL_STRING_MUTEXLOCK_SCOPE WDL_MutexLock __lock(&(EEL_STRING_GET_CONTEXT_POINTER(opaque)->m_mutex));
90 #define EEL_STRING_MUTEXLOCK_SCOPE
95#ifndef EEL_STRING_GET_FOR_INDEX
96#define EEL_STRING_GET_FOR_INDEX(x, wr) (EEL_STRING_GET_CONTEXT_POINTER(opaque)->GetStringForIndex(x, wr, false))
99#ifndef EEL_STRING_GET_FOR_WRITE
100#define EEL_STRING_GET_FOR_WRITE(x, wr) (EEL_STRING_GET_CONTEXT_POINTER(opaque)->GetStringForIndex(x, wr, true))
103#ifndef EEL_STRING_GETFMTVAR
104#define EEL_STRING_GETFMTVAR(x) (EEL_STRING_GET_CONTEXT_POINTER(opaque)->GetVarForFormat(x))
107#ifndef EEL_STRING_GETNAMEDVAR
108#define EEL_STRING_GETNAMEDVAR(x,createOK,altOut) (EEL_STRING_GET_CONTEXT_POINTER(opaque)->GetNamedVar(x,createOK,altOut))
115#ifndef EEL_STRING_STORAGECLASS
116#define EEL_STRING_STORAGECLASS WDL_FastString
168 EEL_F *
GetNamedVar(
const char *
s,
bool createIfNotExists, EEL_F *altOut)
170 if (!
s || !*
s)
return NULL;
174 if (!
s[1] || !altOut)
return NULL;
177 if (!idx && createIfNotExists)
183 if (!idx)
return NULL;
185 *altOut = (EEL_F) idx;
190 if (
r || !createIfNotExists || !
m_vm)
return r;
200 int idx = (
int) (
val+0.5);
203 if (stringContainerOut)
217 if (stringContainerOut) *stringContainerOut=
s;
222 #ifdef EEL_STRINGS_MUTABLE_LITERALS
223 if (stringContainerOut) *stringContainerOut=
s;
225 if (stringContainerOut) *stringContainerOut=is_for_write ?
NULL :
s;
228 return s ?
s->Get() :
NULL;
240#ifdef EEL_STRING_WANT_MUTEX
248 if (!_this)
return -1.0;
249#ifdef EEL_STRING_NAMEDSTRINGCALLBACK_HOOK
250 EEL_STRING_NAMEDSTRINGCALLBACK_HOOK
261 if (
a)
return (EEL_F)
a;
275 if (!_this)
return -1.0;
288#ifdef EEL_STRINGS_MUTABLE_LITERALS
292 const int l = ns->GetLength();
298 if (ns->GetLength() ==
l && !strcmp(
s->Get(),ns->Get()))
break;
317 char *fmtOut,
int fmtOut_sz,
318 char *varOut,
int varOut_sz,
322 const char *
fmt = fmt_in+1;
324 if (fmt_in[0] !=
'%')
return 0;
329 if (fmtOut_sz-- < 2)
return 0;
334 const char c = *
fmt++;
335 if (fmtOut_sz < 2)
return 0;
337 if (
c ==
'f'||
c==
'e' ||
c==
'E' ||
c==
'g' ||
c==
'G' ||
c ==
'd' ||
c ==
'u' ||
338 c ==
'x' ||
c ==
'X' ||
c ==
'c' ||
c ==
'C' ||
c ==
's' ||
c==
'S' ||
c==
'i')
343 return (
int) (
fmt - fmt_in);
347 *fmtOut++ =
c; fmtOut_sz--;
348 if (state&(2))
break;
353 *fmtOut++ =
c; fmtOut_sz--;
354 if (state&(32|16|8|4))
break;
357 else if (
c ==
'-' ||
c ==
' ')
359 *fmtOut++ =
c; fmtOut_sz--;
360 if (state&(32|16|8|4))
break;
363 else if (
c >=
'0' &&
c <=
'9')
365 *fmtOut++ =
c; fmtOut_sz--;
370 if (state & 64)
break;
372 if (*
fmt ==
'.' || (*
fmt >=
'0' && *
fmt <=
'9'))
return 0;
376 if ((*
fmt >=
'a' && *
fmt <=
'z') ||
377 (*
fmt >=
'A' && *
fmt <=
'Z') ||
378 (*
fmt >=
'0' && *
fmt <=
'9') ||
379 *
fmt ==
'_' || *
fmt ==
'.' || *
fmt ==
'#')
381 if (varOut_sz < 2)
return 0;
406 while ((fmt_end ?
fmt < fmt_end : *
fmt) && op < buf+buf_sz-128)
408 if (
fmt[0] ==
'%' &&
fmt[1] ==
'%')
413 else if (
fmt[0] ==
'%')
427 const EEL_F *varptr =
NULL;
430#ifdef EEL_STRING_GETNAMEDVAR
436 if (fmt_parmpos < num_fmt_parms) varptr = fmt_parms[fmt_parmpos];
437#ifdef EEL_STRING_GETFMTVAR
442 double v = varptr ? (double)*varptr : 0.0;
444 if (ct ==
's' || ct==
'S')
448 const int maxl=(
int) (buf+buf_sz - 2 - op);
451 int wl = wr->GetLength();
452 if (wl > maxl) wl=maxl;
459 snprintf(op,maxl,fs,str ? str :
"");
467 v = str ? atof(str) : 0.0;
470 if (ct ==
'x' || ct ==
'X' || ct ==
'd' || ct ==
'u' || ct==
'i')
472 snprintf(op,64,fs,(
int) (
v));
481 const unsigned int iv = (
unsigned int)
v;
483 if (iv & 0xff000000) bs=24;
484 else if (iv & 0x00ff0000) bs=16;
485 else if (iv & 0x0000ff00) bs=8;
488 const char c=(char) (iv>>bs);
496 snprintf(op,64,fs,
v);
511 return (
int) (op - buf);
516static int eel_string_match(
void *
opaque,
const char *
fmt,
const char *
msg,
int match_fmt_pos,
int ignorecase,
const char *fmt_endptr,
const char *msg_endptr,
int num_fmt_parms, EEL_F **fmt_parms)
529 if (
msg>=msg_endptr)
return 1;
534 if (
msg>=msg_endptr && *
fmt !=
'*' && *
fmt !=
'%')
return 0;
541 if (
fmt+1>=fmt_endptr || (
fmt[1] ==
'?' &&
fmt+2>=fmt_endptr))
return *
fmt ==
'*' ||
msg<msg_endptr;
552 return msg<msg_endptr;
557 int len = (
int) (msg_endptr-
msg);
558 while (len >= 0 && !
eel_string_match(
opaque,
fmt,
msg+len,match_fmt_pos,ignorecase,fmt_endptr, msg_endptr,num_fmt_parms,fmt_parms)) len--;
569 unsigned short fmt_minlen = 1, fmt_maxlen = 0;
570 if (*
fmt >=
'0' && *
fmt <=
'9')
572 fmt_minlen = *
fmt++ -
'0';
573 while (*
fmt >=
'0' && *
fmt <=
'9') fmt_minlen = fmt_minlen * 10 + (*
fmt++ -
'0');
574 fmt_maxlen = fmt_minlen;
580 while (*
fmt >=
'0' && *
fmt <=
'9') fmt_maxlen = fmt_maxlen * 10 + (*
fmt++ -
'0');
582 const char *dest_varname=
NULL;
587 if (
fmt >= fmt_endptr-1 || *
fmt !=
'}')
return 0;
591 char fmt_char = *
fmt++;
592 if (!fmt_char)
return 0;
594 if (fmt_char ==
'*' ||
599 if (*
msg++ != fmt_char)
return 0;
601 else if (fmt_char ==
'c')
603 EEL_F *varOut =
NULL;
607 if (match_fmt_pos < num_fmt_parms) varOut = fmt_parms[match_fmt_pos];
608#ifdef EEL_STRING_GETFMTVAR
615#ifdef EEL_STRING_GETNAMEDVAR
618 while (dest_varname < fmt_endptr && *dest_varname && *dest_varname !=
'}' && idx<(
int)
sizeof(tmp)-1) tmp[idx++] = *dest_varname++;
623 if (
msg >= msg_endptr)
return 0;
631 if (wr) wr->Set(
msg,1);
635 *varOut = (EEL_F)*(
unsigned char *)
msg;
644 if (fmt_char>=
'A'&&fmt_char<=
'Z') { lazy=1; fmt_char +=
'a' -
'A'; }
648 len = (
int) (msg_endptr-
msg);
650 else if (fmt_char ==
'x')
652 while ((
msg[len] >=
'0' &&
msg[len] <=
'9') ||
653 (
msg[len] >=
'A' &&
msg[len] <=
'F') ||
654 (
msg[len] >=
'a' &&
msg[len] <=
'f')) len++;
656 else if (fmt_char ==
'f')
658 if (
msg[len] ==
'-') len++;
659 while (
msg[len] >=
'0' &&
msg[len] <=
'9') len++;
663 while (
msg[len] >=
'0' &&
msg[len] <=
'9') len++;
666 else if (fmt_char ==
'd' || fmt_char ==
'u' || fmt_char ==
'i')
668 if (fmt_char !=
'u' &&
msg[len] ==
'-') len++;
669 while (
msg[len] >=
'0' &&
msg[len] <=
'9') len++;
677 if (fmt_maxlen>0 && len > fmt_maxlen) len = fmt_maxlen;
679 if (!dest_varname) match_fmt_pos++;
683 if (fmt_maxlen<1 || fmt_maxlen>len) fmt_maxlen=len;
685 while (len <= fmt_maxlen && !
eel_string_match(
opaque,
fmt,
msg+len,match_fmt_pos,ignorecase,fmt_endptr, msg_endptr,num_fmt_parms,fmt_parms)) len++;
686 if (len > fmt_maxlen)
return 0;
690 while (len >= fmt_minlen && !
eel_string_match(
opaque,
fmt,
msg+len,match_fmt_pos,ignorecase,fmt_endptr, msg_endptr,num_fmt_parms,fmt_parms)) len--;
691 if (len < fmt_minlen)
return 0;
695 EEL_F *varOut =
NULL;
698 if (match_fmt_pos>0 && match_fmt_pos-1 < num_fmt_parms) varOut = fmt_parms[match_fmt_pos-1];
699#ifdef EEL_STRING_GETFMTVAR
705#ifdef EEL_STRING_GETNAMEDVAR
708 while (dest_varname < fmt_endptr && *dest_varname && *dest_varname !=
'}' && idx<(
int)
sizeof(tmp)-1) tmp[idx++] = *dest_varname++;
721 if (msg_endptr >= wr->Get() && msg_endptr <= wr->Get() + wr->GetLength())
723#ifdef EEL_STRING_DEBUGOUT
724 EEL_STRING_DEBUGOUT(
"match: destination specifier passed is also haystack, will not update");
727 else if (fmt_endptr >= wr->Get() && fmt_endptr <= wr->Get() + wr->GetLength())
729#ifdef EEL_STRING_DEBUGOUT
730 EEL_STRING_DEBUGOUT(
"match: destination specifier passed is also format, will not update");
740#ifdef EEL_STRING_DEBUGOUT
741 EEL_STRING_DEBUGOUT(
"match: bad destination specifier passed as %d: %f",match_fmt_pos,*varOut);
753 if (wr) wr->Set(tmp);
759 *varOut = (EEL_F)strtoul(tmp,&
bl,10);
760 else if (fmt_char ==
'x')
761 *varOut = (EEL_F)strtoul(
msg,&
bl,16);
763 *varOut = (EEL_F)atof(tmp);
772 if (ignorecase ? (toupper(*
fmt) != toupper(*
msg)) : (*
fmt!= *
msg))
return 0;
784 if (num_param<2)
return 0.0;
793#ifdef EEL_STRING_DEBUGOUT
794 EEL_STRING_DEBUGOUT(
"sprintf: bad destination specifier passed %f",*(parms[0]));
808 wr->SetRaw(buf,fmt_len);
812#ifdef EEL_STRING_DEBUGOUT
813 EEL_STRING_DEBUGOUT(
"sprintf: bad format string %s",
fmt);
819#ifdef EEL_STRING_DEBUGOUT
820 EEL_STRING_DEBUGOUT(
"sprintf: bad format specifier passed %f",*(parms[1]));
838#ifdef EEL_STRING_DEBUGOUT
839 EEL_STRING_DEBUGOUT(
"str%scat: bad destination specifier passed %f",maxlen ?
"n":
"",*strOut);
849#ifdef EEL_STRING_DEBUGOUT
850 EEL_STRING_DEBUGOUT(
"str%scat: will not grow string since it is already %d bytes",maxlen ?
"n":
"",wr->GetLength());
856 if (maxlen && *maxlen > 0)
ml = (
int)*maxlen;
860 if (wr_src == wr) *(wr_src=&tmp) = *wr;
861 wr->AppendRaw(wr_src->Get(),
ml > 0 &&
ml < wr_src->GetLength() ?
ml : wr_src->GetLength());
869#ifdef EEL_STRING_DEBUGOUT
870 EEL_STRING_DEBUGOUT(
"str%scat: bad format specifier passed %f",maxlen ?
"n":
"",*fmt_index);
887#ifdef EEL_STRING_DEBUGOUT
888 EEL_STRING_DEBUGOUT(
"strcpy_substr: bad destination specifier passed %f",parms[0][0]);
896 const int fmt_len = wr_src ? wr_src->GetLength() : (
int) strlen(
fmt);
897 int maxlen, o = (
int) parms[2][0];
903 maxlen = fmt_len - o;
906 const int a = (
int) parms[3][0];
907 if (
a<0) maxlen +=
a;
908 else if (
a<maxlen) maxlen=
a;
911 if (maxlen < 1 || o >= fmt_len)
920 if (wr->GetLength() > maxlen) wr->SetLen(maxlen);
924 wr->SetRaw(
fmt+o,maxlen);
930#ifdef EEL_STRING_DEBUGOUT
931 EEL_STRING_DEBUGOUT(
"strcpy_substr: bad format specifier passed %f",parms[1][0]);
950#ifdef EEL_STRING_DEBUGOUT
951 EEL_STRING_DEBUGOUT(
"str%scpy: bad destination specifier passed %f",maxlen ?
"n":
"",*strOut);
960 if (maxlen && *maxlen >= 0)
ml = (
int)*maxlen;
969 else wr->Set(
fmt,
ml);
973#ifdef EEL_STRING_DEBUGOUT
974 EEL_STRING_DEBUGOUT(
"str%scpy: bad format specifier passed %f",maxlen ?
"n":
"",*fmt_index);
988 if (
ml > 0 && pos ==
ml)
return 0.0;
989 const bool a_end = a_len >= 0 ? pos == a_len : !
a[pos];
990 const bool b_end = b_len >= 0 ? pos == b_len : !
b[pos];
993 if (!b_end)
return -1.0;
994 if (!a_end)
return 1.0;
1004 if (bv > av)
return -1.0;
1005 if (av > bv)
return 1.0;
1021#ifdef EEL_STRING_DEBUGOUT
1022 EEL_STRING_DEBUGOUT(
"str%scmp: bad specifier(s) passed %f/%f",maxlen ?
"n" :
"",*aa,*
bb);
1027 const int ml = maxlen ? (
int) *maxlen : -1;
1028 if (!
ml ||
a==
b)
return 0;
1030 return _eel_strcmp_int(
a,wr_a ? wr_a->GetLength() : -1,
b,wr_b ? wr_b->GetLength() : -1,
ml,
false);
1046#ifdef EEL_STRING_DEBUGOUT
1047 EEL_STRING_DEBUGOUT(
"str%sicmp: bad specifier(s) passed %f/%f",maxlen ?
"n" :
"",*aa,*
bb);
1052 const int ml = maxlen ? (
int) *maxlen : -1;
1053 if (!
ml ||
a==
b)
return 0;
1054 return _eel_strcmp_int(
a,wr_a ? wr_a->GetLength() : -1,
b,wr_b ? wr_b->GetLength() : -1,
ml,
true);
1092#ifdef EEL_STRING_DEBUGOUT
1093 EEL_STRING_DEBUGOUT(
"str_getchar: bad specifier passed %f",*strOut);
1098 const int wl=(wr?wr->GetLength():(
int)strlen(
fmt));
1100 if (*idx < 0.0)
l+=wl;
1101 if (
l>=0 &&
l < wl)
return ((
unsigned char *)
fmt)[
l];
1107#define EEL_GETCHAR_FLAG_ENDIANSWAP 0x10
1108#define EEL_GETCHAR_FLAG_UNSIGNED 0x20
1109#define EEL_GETCHAR_FLAG_FLOAT 0x40
1123 else type +=
'A'-
'a';
1129 case 'S':
return ret|2;
1130 case 'I':
return ret|4;
1146 unsigned int asUInt;
1147 unsigned short asUShort;
1148 unsigned char asUChar;
1150 const int type_sz=
flag&0xf;
1154 if (type_sz==8)
a.asDouble=
val;
1155 else a.asFloat=(float)
val;
1159 if (type_sz==4)
a.asUInt=(
unsigned int)
val;
1160 else if (type_sz==2)
a.asUShort=(
unsigned short)
val;
1161 else a.asUChar=(
unsigned char)
val;
1163 else if (type_sz==4)
a.asInt=(
int)
val;
1164 else if (type_sz==2)
a.asShort=(short)
val;
1165 else a.asChar=(char)
val;
1171 for(
x=0;
x<type_sz;
x++) *--dest=
a.buf[
x];
1189 unsigned int asUInt;
1190 unsigned short asUShort;
1191 unsigned char asUChar;
1193 const int type_sz=
flag&0xf;
1195 memset(&
a, 0,
sizeof(
a));
1200 for(
x=0;
x<type_sz;
x++)
a.buf[
x]=*--src;
1207 if (type_sz==8)
return a.asDouble;
1212 if (type_sz==4)
return a.asUInt;
1213 if (type_sz==2)
return a.asUShort;
1216 if (type_sz==4)
return a.asInt;
1217 if (type_sz==2)
return a.asShort;
1230#ifdef EEL_STRING_DEBUGOUT
1231 EEL_STRING_DEBUGOUT(
"str_getchar: bad specifier passed %f",parms[0][0]);
1236 const int wl=(wr?wr->GetLength():(
int)strlen(
fmt));
1238 int l = (
int) parms[1][0];
1239 if (parms[1][0] < 0.0)
l+=wl;
1241 if (
l>=0 &&
l <= wl-(flags&0xf))
1259#ifdef EEL_STRING_DEBUGOUT
1260 EEL_STRING_DEBUGOUT(
"str_setchar: bad destination specifier passed %f",parms[0][0]);
1265 const int wl=wr->GetLength();
1267 int l = (
int) parms[1][0];
1268 if (parms[1][0] < 0.0)
l+=wl;
1269 if (
l>=0 &&
l <= wl)
1276#ifdef EEL_STRING_DEBUGOUT
1277 EEL_STRING_DEBUGOUT(
"str_setchar: will not grow string since it is already %d bytes",wl);
1284 wr->AppendRaw(buf,flags&0xf);
1304#ifdef EEL_STRING_DEBUGOUT
1305 EEL_STRING_DEBUGOUT(
"str_setchar: bad destination specifier passed %f",*strOut);
1310 const int wl=wr->GetLength();
1312 if (*idx < 0.0)
l+=wl;
1313 if (
l>=0 &&
l <= wl)
1315 const unsigned char v=((
int)*
val)&255;
1320#ifdef EEL_STRING_DEBUGOUT
1321 EEL_STRING_DEBUGOUT(
"str_setchar: will not grow string since it is already %d bytes",wl);
1325 wr->AppendRaw((
const char*)&
v,1);
1328 ((
unsigned char *)wr->Get())[
l]=
v;
1344#ifdef EEL_STRING_DEBUGOUT
1345 EEL_STRING_DEBUGOUT(
"str_insert: bad destination specifier passed %f",*strOut);
1354 if (wr_src == wr) *(wr_src=&tmp) = *wr;
1358 int insert_l = wr_src ? wr_src->GetLength() : (
int)strlen(
fmt);
1370#ifdef EEL_STRING_DEBUGOUT
1371 EEL_STRING_DEBUGOUT(
"str_insert: will not grow string since it is already %d bytes",wr->GetLength());
1378 wr->InsertRaw(
fmt,
p, insert_l);
1389#ifdef EEL_STRING_DEBUGOUT
1390 EEL_STRING_DEBUGOUT(
"str_insert: bad source specifier passed %f",*fmt_index);
1407#ifdef EEL_STRING_DEBUGOUT
1408 EEL_STRING_DEBUGOUT(
"str_delsub: bad destination specifier passed %f",*strOut);
1436#ifdef EEL_STRING_DEBUGOUT
1437 EEL_STRING_DEBUGOUT(
"str_setlen: bad destination specifier passed %f",*strOut);
1442 int l = (
int) *newlen;
1446#ifdef EEL_STRING_DEBUGOUT
1466 if (wr)
return (EEL_F) wr->GetLength();
1467 if (
fmt)
return (EEL_F) strlen(
fmt);
1477 if (num_param>0 &&
opaque)
1489#ifdef EEL_STRING_STDOUT_WRITE
1496#ifdef EEL_STRING_DEBUGOUT
1497 EEL_STRING_DEBUGOUT(
"printf: bad format string %s",
fmt);
1503#ifdef EEL_STRING_DEBUGOUT
1504 EEL_STRING_DEBUGOUT(
"printf: bad format specifier passed %f",*(parms[0]));
1515 if (
opaque && num_parms >= 2)
1528 if (
opaque && num_parms >= 2)
1578#ifdef EEL_WANT_DOCUMENTATION
1579static const char *eel_strings_function_reference =
1580#ifdef EEL_STRING_STDOUT_WRITE
1581"printf\t\"format\"[, ...]\tOutput formatted string to system-specific destination, see sprintf() for more information\0"
1583"sprintf\t#dest,\"format\"[, ...]\tFormats a string and stores it in #dest. Format specifiers begin with %, and may include:\3\n"
1585 "\4 %s = string from parameter\n"
1586 "\4 %d = parameter as integer\n"
1587 "\4 %i = parameter as integer\n"
1588 "\4 %u = parameter as unsigned integer\n"
1589 "\4 %x = parameter as hex (lowercase) integer\n"
1590 "\4 %X = parameter as hex (uppercase) integer\n"
1591 "\4 %c = parameter as character\n"
1592 "\4 %f = parameter as floating point\n"
1593 "\4 %e = parameter as floating point (scientific notation, lowercase)\n"
1594 "\4 %E = parameter as floating point (scientific notation, uppercase)\n"
1595 "\4 %g = parameter as floating point (shortest representation, lowercase)\n"
1596 "\4 %G = parameter as floating point (shortest representation, uppercase)\n"
1598 "Many standard C printf() modifiers can be used, including:\3\n"
1599 "\4 %.10s = string, but only print up to 10 characters\n"
1600 "\4 %-10s = string, left justified to 10 characters\n"
1601 "\4 %10s = string, right justified to 10 characters\n"
1602 "\4 %+f = floating point, always show sign\n"
1603 "\4 %.4f = floating point, minimum of 4 digits after decimal point\n"
1604 "\4 %10d = integer, minimum of 10 digits (space padded)\n"
1605 "\4 %010f = integer, minimum of 10 digits (zero padded)\n"
1607 "Values for format specifiers can be specified as additional parameters to sprintf, or within {} in the format specifier (such as %{varname}d, in that case a global variable is always used).\0"
1609 "matchi\t\"needle\",\"haystack\"[, ...]\tCase-insensitive version of match().\0"
1610 "match\t\"needle\",\"haystack\"[, ...]\tSearches for the first parameter in the second parameter, using a simplified regular expression syntax.\3\n"
1611 "\4* = match 0 or more characters\n"
1612 "\4*? = match 0 or more characters, lazy\n"
1613 "\4+ = match 1 or more characters\n"
1614 "\4+? = match 1 or more characters, lazy\n"
1615 "\4? = match one character\n"
1617 "You can also use format specifiers to match certain types of data, and optionally put that into a variable:\3\n"
1618 "\4%s means 1 or more chars\n"
1619 "\4%0s means 0 or more chars\n"
1620 "\4%5s means exactly 5 chars\n"
1621 "\4%5-s means 5 or more chars\n"
1622 "\4%-10s means 1-10 chars\n"
1623 "\4%3-5s means 3-5 chars\n"
1624 "\4%0-5s means 0-5 chars\n"
1625 "\4%x, %d, %u, and %f are available for use similarly\n"
1626 "\4%c can be used, but can't take any length modifiers\n"
1627 "\4Use uppercase (%S, %D, etc) for lazy matching\n"
1629 "See also sprintf() for other notes, including specifying direct variable references via {}.\0"
1631 "strlen\t\"str\"\tReturns the length of the string passed as a parameter\0"
1632 "strcpy\t#str,\"srcstr\"\tCopies the contents of srcstr to #str, and returns #str\0"
1633 "strcat\t#str,\"srcstr\"\tAppends srcstr to #str, and returns #str\0"
1634 "strcmp\t\"str\",\"str2\"\tCompares strings, returning 0 if equal\0"
1635 "stricmp\t\"str\",\"str2\"\tCompares strings ignoring case, returning 0 if equal\0"
1636 "strncmp\t\"str\",\"str2\",maxlen\tCompares strings giving up after maxlen characters, returning 0 if equal\0"
1637 "strnicmp\t\"str\",\"str2\",maxlen\tCompares strings giving up after maxlen characters, ignoring case, returning 0 if equal\0"
1638 "strncpy\t#str,\"srcstr\",maxlen\tCopies srcstr to #str, stopping after maxlen characters. Returns #str.\0"
1639 "strncat\t#str,\"srcstr\",maxlen\tAppends srcstr to #str, stopping after maxlen characters of srcstr. Returns #str.\0"
1640 "strcpy_from\t#str,\"srcstr\",offset\tCopies srcstr to #str, but starts reading srcstr at offset offset\0"
1641 "strcpy_substr\t#str,\"srcstr\",offs,ml)\tPHP-style (start at offs, offs<0 means from end, ml for maxlen, ml<0 = reduce length by this amt)\0"
1642 "str_getchar\t\"str\",offset[,type]\tReturns the data at byte-offset offset of str. If offset is negative, position is relative to end of string."
1643 "type defaults to signed char, but can be specified to read raw binary data in other formats (note the single quotes, these are single/multi-byte characters):\3\n"
1644 "\4'c' - signed char\n"
1645 "\4'cu' - unsigned char\n"
1646 "\4's' - signed short\n"
1647 "\4'S' - signed short, big endian\n"
1648 "\4'su' - unsigned short\n"
1649 "\4'Su' - unsigned short, big endian\n"
1650 "\4'i' - signed int\n"
1651 "\4'I' - signed int, big endian\n"
1652 "\4'iu' - unsigned int\n"
1653 "\4'Iu' - unsigned int, big endian\n"
1655 "\4'F' - float, big endian\n"
1657 "\4'D' - double, big endian\n"
1659 "str_setchar\t#str,offset,val[,type])\tSets value at offset offset, type optional. offset may be negative to refer to offset relative to end of string, or between 0 and length, inclusive, and if set to length it will lengthen string. See str_getchar() for more information on types.\0"
1660 "str_setlen\t#str,len\tSets length of #str (if increasing, will be space-padded), and returns #str.\0"
1661 "str_delsub\t#str,pos,len\tDeletes len characters at offset pos from #str, and returns #str.\0"
1662 "str_insert\t#str,\"srcstr\",pos\tInserts srcstr into #str at offset pos. Returns #str\0"
uint8_t a
Definition Spc_Cpu.h:141
CAdPlugDatabase::CRecord::RecordType type
Definition adplugdb.cpp:93
Definition assocarray.h:320
VAL Get(KEY key, VAL notfound=0) const
Definition assocarray.h:328
int Insert(KEY key, VAL val)
Definition assocarray.h:53
PTRTYPE * Add(PTRTYPE *item)
Definition ptrlist.h:82
int GetSize(void) const
Definition ptrlist.h:58
Definition assocarray.h:376
EEL_F * GetVarForFormat(int formatidx)
Definition eel_strings.h:162
void clear_state(bool full)
Definition eel_strings.h:136
WDL_PtrList< EEL_STRING_STORAGECLASS > m_literal_strings
Definition eel_strings.h:231
WDL_AssocArray< const char *, EEL_F_PTR > m_varname_cache
Definition eel_strings.h:237
~eel_string_context_state()
Definition eel_strings.h:131
EEL_F * GetNamedVar(const char *s, bool createIfNotExists, EEL_F *altOut)
Definition eel_strings.h:168
int AddString(EEL_STRING_STORAGECLASS *ns)
Definition eel_strings.h:286
static EEL_F addNamedStringCallback(void *opaque, const char *name)
Definition eel_strings.h:244
WDL_PtrList< EEL_STRING_STORAGECLASS > m_unnamed_strings
Definition eel_strings.h:232
EEL_STRING_STORAGECLASS * m_user_strings[EEL_STRING_MAX_USER_STRINGS]
Definition eel_strings.h:236
const char * GetStringForIndex(EEL_F val, EEL_STRING_STORAGECLASS **stringContainerOut=NULL, bool is_for_write=false)
Definition eel_strings.h:198
eel_string_context_state()
Definition eel_strings.h:126
NSEEL_VMCTX m_vm
Definition eel_strings.h:239
WDL_PtrList< EEL_STRING_STORAGECLASS > m_named_strings
Definition eel_strings.h:233
static int cmpistr(const char **a, const char **b)
Definition eel_strings.h:124
void update_named_vars(NSEEL_VMCTX vm)
Definition eel_strings.h:154
static EEL_F addStringCallback(void *opaque, struct eelStringSegmentRec *list)
Definition eel_strings.h:270
WDL_StringKeyedArray< int > m_named_strings_names
Definition eel_strings.h:234
static int varEnumProc(const char *name, EEL_F *val, void *ctx)
Definition eel_strings.h:306
int * l
Definition inflate.c:1579
G bb
Definition inflate.c:1057
unsigned v[N_MAX]
Definition inflate.c:1584
unsigned ml
Definition inflate.c:944
unsigned bl
Definition inflate.c:935
unsigned s
Definition inflate.c:1555
unsigned x[BMAX+1]
Definition inflate.c:1586
#define NSEEL_addfunc_varparm(name, min_np, pproc, fptr)
Definition eel_import.h:63
#define NSEEL_addfunc_exparms(name, np, pproc, fptr)
Definition eel_import.h:67
void(* NSEEL_VM_SetStringFunc)(NSEEL_VMCTX ctx, EEL_F(*onString)(void *caller_this, struct eelStringSegmentRec *list), EEL_F(*onNamedString)(void *caller_this, const char *name))
Definition eel_import.h:32
EEL_F *(* nseel_int_register_var)(compileContext *ctx, const char *name, int isReg, const char **namePtrOut)
Definition eel_import.h:21
int(* nseel_stringsegments_tobuf)(char *bufOut, int bufout_sz, struct eelStringSegmentRec *list)
Definition eel_import.h:37
#define NSEEL_addfunc_retval(name, np, pproc, fptr)
Definition eel_import.h:51
void(* NSEEL_VM_enumallvars)(NSEEL_VMCTX ctx, int(*func)(const char *name, EEL_F *val, void *ctx), void *userctx)
Definition eel_import.h:22
void *(* NSEEL_PProc_THIS)(void *data, int data_size, struct _compileContext *ctx)
Definition eel_import.h:40
static EEL_F NSEEL_CGEN_CALL _eel_strinsert(void *opaque, EEL_F *strOut, EEL_F *fmt_index, EEL_F *pos)
Definition eel_strings.h:1335
static EEL_F eel_getchar_do(int flag, const char *src)
Definition eel_strings.h:1179
static EEL_F NSEEL_CGEN_CALL _eel_strcpysubstr(void *opaque, INT_PTR nparm, EEL_F **parms)
Definition eel_strings.h:878
void EEL_string_register()
Definition eel_strings.h:1540
static EEL_F NSEEL_CGEN_CALL _eel_strncat(void *opaque, EEL_F *strOut, EEL_F *fmt_index, EEL_F *maxlen)
Definition eel_strings.h:829
static void eel_setchar_do(int flag, char *dest, EEL_F val)
Definition eel_strings.h:1136
#define EEL_STRING_GETFMTVAR(x)
Definition eel_strings.h:104
#define EEL_STRING_GETNAMEDVAR(x, createOK, altOut)
Definition eel_strings.h:108
static EEL_F NSEEL_CGEN_CALL _eel_strdelsub(void *opaque, EEL_F *strOut, EEL_F *pos, EEL_F *len)
Definition eel_strings.h:1398
static int eel_getchar_flag(int type)
Definition eel_strings.h:1110
#define EEL_STRING_UNNAMED_BASE
Definition eel_strings.h:81
static EEL_F NSEEL_CGEN_CALL _eel_strcmp(void *opaque, EEL_F *strOut, EEL_F *fmt_index)
Definition eel_strings.h:1072
static EEL_F NSEEL_CGEN_CALL _eel_printf(void *opaque, INT_PTR num_param, EEL_F **parms)
Definition eel_strings.h:1475
#define EEL_GETCHAR_FLAG_UNSIGNED
Definition eel_strings.h:1108
static EEL_F NSEEL_CGEN_CALL _eel_stricmp(void *opaque, EEL_F *strOut, EEL_F *fmt_index)
Definition eel_strings.h:1077
static EEL_F NSEEL_CGEN_CALL _eel_match(void *opaque, INT_PTR num_parms, EEL_F **parms)
Definition eel_strings.h:1513
#define EEL_STRING_GET_FOR_WRITE(x, wr)
Definition eel_strings.h:100
#define EEL_STRING_LITERAL_BASE
Definition eel_strings.h:71
static EEL_F NSEEL_CGEN_CALL _eel_strncpy(void *opaque, EEL_F *strOut, EEL_F *fmt_index, EEL_F *maxlen)
Definition eel_strings.h:941
static int eel_validate_format_specifier(const char *fmt_in, char *typeOut, char *fmtOut, int fmtOut_sz, char *varOut, int varOut_sz, int *varOut_used)
Definition eel_strings.h:316
void eel_string_initvm(NSEEL_VMCTX vm)
Definition eel_strings.h:1573
#define EEL_STRING_GET_FOR_INDEX(x, wr)
Definition eel_strings.h:96
static EEL_F NSEEL_CGEN_CALL _eel_strnicmp(void *opaque, EEL_F *aa, EEL_F *bb, EEL_F *maxlen)
Definition eel_strings.h:1036
#define EEL_STRING_STORAGECLASS
Definition eel_strings.h:116
#define EEL_STRING_NAMED_BASE
Definition eel_strings.h:76
static EEL_F NSEEL_CGEN_CALL _eel_sprintf(void *opaque, INT_PTR num_param, EEL_F **parms)
Definition eel_strings.h:782
#define EEL_GETCHAR_FLAG_ENDIANSWAP
Definition eel_strings.h:1107
static int eel_string_match(void *opaque, const char *fmt, const char *msg, int match_fmt_pos, int ignorecase, const char *fmt_endptr, const char *msg_endptr, int num_fmt_parms, EEL_F **fmt_parms)
Definition eel_strings.h:516
static EEL_F NSEEL_CGEN_CALL _eel_matchi(void *opaque, INT_PTR num_parms, EEL_F **parms)
Definition eel_strings.h:1526
static EEL_F NSEEL_CGEN_CALL _eel_strncmp(void *opaque, EEL_F *aa, EEL_F *bb, EEL_F *maxlen)
Definition eel_strings.h:1011
static EEL_F NSEEL_CGEN_CALL _eel_strgetchar2(void *opaque, INT_PTR np, EEL_F **parms)
Definition eel_strings.h:1221
#define EEL_STRING_MAX_USER_STRINGS
Definition eel_strings.h:66
static EEL_F _eel_strcmp_int(const char *a, int a_len, const char *b, int b_len, int ml, bool ignorecase)
Definition eel_strings.h:982
static EEL_F NSEEL_CGEN_CALL _eel_strsetchar(void *opaque, EEL_F *strOut, EEL_F *idx, EEL_F *val)
Definition eel_strings.h:1295
static EEL_F NSEEL_CGEN_CALL _eel_strcpy(void *opaque, EEL_F *strOut, EEL_F *fmt_index)
Definition eel_strings.h:1066
#define EEL_STRING_MUTEXLOCK_SCOPE
Definition eel_strings.h:90
static EEL_F NSEEL_CGEN_CALL _eel_strcat(void *opaque, EEL_F *strOut, EEL_F *fmt_index)
Definition eel_strings.h:1061
int eel_format_strings(void *opaque, const char *fmt, const char *fmt_end, char *buf, int buf_sz, int num_fmt_parms, EEL_F **fmt_parms)
Definition eel_strings.h:402
static EEL_F NSEEL_CGEN_CALL _eel_strgetchar(void *opaque, EEL_F *strOut, EEL_F *idx)
Definition eel_strings.h:1083
static EEL_F NSEEL_CGEN_CALL _eel_strlen(void *opaque, EEL_F *fmt_index)
Definition eel_strings.h:1459
#define EEL_GETCHAR_FLAG_FLOAT
Definition eel_strings.h:1109
static EEL_F NSEEL_CGEN_CALL _eel_strsetchar2(void *opaque, INT_PTR np, EEL_F **parms)
Definition eel_strings.h:1250
static EEL_F NSEEL_CGEN_CALL _eel_strsetlen(void *opaque, EEL_F *strOut, EEL_F *newlen)
Definition eel_strings.h:1427
#define opaque
Definition eelscript.h:281
#define EEL_STRING_GET_CONTEXT_POINTER(opaque)
Definition eelscript.h:168
static const char * name
Definition pugl.h:1582
int val
Definition jpeglib.h:956
const char * msg
Definition missing_descriptor.c:20
struct _compileContext compileContext
#define NSEEL_CGEN_CALL
Definition ns-eel.h:44
void * NSEEL_VMCTX
Definition ns-eel.h:117
#define false
Definition ordinals.h:83
Definition eel_import.h:27
static WDL_Mutex m_mutex
Definition swell-ini.cpp:67
#define stricmp(x, y)
Definition swell-types.h:68
intptr_t INT_PTR
Definition swell-types.h:42
uch * p
Definition crypt.c:594
return c
Definition crypt.c:175
memcpy(hh, h, RAND_HEAD_LEN)
int r
Definition crypt.c:458
fmt[0]
Definition fileio.c:2503
int flag
Definition unix.c:754
typedef int(UZ_EXP MsgFn)()
_WDL_CSTRING_PREFIX void lstrcpyn_safe(char *o, const char *in, INT_PTR count)
Definition wdlcstring.h:129
#define wdl_min(x, y)
Definition wdltypes.h:107
#define EEL_STRING_STDOUT_WRITE(x, len)
Definition ysfx_api_eel.cpp:30
#define EEL_STRING_MAXUSERSTRING_LENGTH_HINT
Definition ysfx_api_eel.cpp:35