-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTinyJS_StringFunctions.cpp
574 lines (535 loc) · 24.5 KB
/
TinyJS_StringFunctions.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
/*
* 42TinyJS
*
* A fork of TinyJS with the goal to makes a more JavaScript/ECMA compliant engine
*
* Authored By Armin Diedering <[email protected]>
*
* Copyright (C) 2010-2015 ardisoft
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <algorithm>
#include "TinyJS.h"
#ifndef NO_REGEXP
# if defined HAVE_TR1_REGEX
# include <tr1/regex>
using namespace std::tr1;
# elif defined HAVE_BOOST_REGEX
# include <boost/regex.hpp>
using namespace boost;
# else
# include <regex>
# endif
#endif
using namespace std;
// ----------------------------------------------- Actual Functions
#define CheckObjectCoercible(var) do { \
if(var->isUndefined() || var->isNull())\
c->throwError(TypeError, "can't convert undefined to object");\
}while(0)
#if PTRDIFF_MAX == INT32_MAX
# define ptr2int32(p) ((int32_t)p)
#else
# define ptr2int32(p) ((int32_t)((ptrdiff_t)p) & 0x7FFF)
#endif
static string this2string(const CFunctionsScopePtr &c) {
CScriptVarPtr This = c->getArgument("this");
CheckObjectCoercible(This);
return This->toString();
}
static void scStringCharAt(const CFunctionsScopePtr &c, void *) {
string str = this2string(c);
int p = c->getArgument("pos")->toNumber().toInt32();
if (p>=0 && p<(int)str.length())
c->setReturnVar(c->newScriptVar(str.substr(p, 1)));
else
c->setReturnVar(c->newScriptVar(""));
}
static void scStringCharCodeAt(const CFunctionsScopePtr &c, void *) {
string str = this2string(c);
int p = c->getArgument("pos")->toNumber().toInt32();
if (p>=0 && p<(int)str.length())
c->setReturnVar(c->newScriptVar((unsigned char)str.at(p)));
else
c->setReturnVar(c->constScriptVar(NaN));
}
static void scStringConcat(const CFunctionsScopePtr &c, void *userdata) {
int length = c->getArgumentsLength();
string str = this2string(c);
for(int32_t i=ptr2int32(userdata); i<length; i++)
str.append(c->getArgument(i)->toString());
c->setReturnVar(c->newScriptVar(str));
}
static void scStringIndexOf(const CFunctionsScopePtr &c, void *userdata) {
string str = this2string(c);
string search = c->getArgument("search")->toString();
CNumber pos_n = c->getArgument("pos")->toNumber();
string::size_type pos;
pos = (userdata) ? string::npos : 0;
if(pos_n.sign()<0) pos = 0;
else if(pos_n.isInfinity()) pos = string::npos;
else if(pos_n.isFinite()) pos = pos_n.toInt32();
string::size_type p = (userdata==0) ? str.find(search, pos) : str.rfind(search, pos);
if(p==string::npos)
c->setReturnVar(c->newScriptVar(-1));
else
c->setReturnVar(c->newScriptVar(p));
}
static void scStringLocaleCompare(const CFunctionsScopePtr &c, void *userdata) {
string str = this2string(c);
string compareString = c->getArgument("compareString")->toString();
int32_t val = 0;
if(str<compareString) val = -1;
else if(str>compareString) val = 1;
c->setReturnVar(c->newScriptVar(val));
}
static void scStringQuote(const CFunctionsScopePtr &c, void *userdata) {
string str = this2string(c);
c->setReturnVar(c->newScriptVar(getJSString(str)));
}
#ifndef NO_REGEXP
// helper-function for replace search
static bool regex_search(const string &str, const string::const_iterator &search_begin, const string &substr, bool ignoreCase, bool sticky, string::const_iterator &match_begin, string::const_iterator &match_end, smatch &match) {
regex::flag_type flags = regex_constants::ECMAScript;
if(ignoreCase) flags |= regex_constants::icase;
regex_constants::match_flag_type mflag = sticky?regex_constants::match_continuous:regex_constants::format_default;
if(str.begin() != search_begin) mflag |= regex_constants::match_prev_avail;
if(regex_search(search_begin, str.end(), match, regex(substr, flags), mflag)) {
match_begin = match[0].first;
match_end = match[0].second;
return true;
}
return false;
}
static bool regex_search(const string &str, const string::const_iterator &search_begin, const string &substr, bool ignoreCase, bool sticky, string::const_iterator &match_begin, string::const_iterator &match_end) {
smatch match;
return regex_search(str, search_begin, substr, ignoreCase, sticky, match_begin, match_end, match);
}
#endif /* NO_REGEXP */
static bool charcmp (char i, char j) { return (i==j); }
static bool charicmp (char i, char j) { return (toupper(i)==toupper(j)); }
// helper-function for replace search
static bool string_search(const string &str, const string::const_iterator &search_begin, const string &substr, bool ignoreCase, bool sticky, string::const_iterator &match_begin, string::const_iterator &match_end) {
bool (*cmp)(char,char) = ignoreCase ? charicmp : charcmp;
if(sticky) {
match_begin = match_end = search_begin;
string::const_iterator s1e=str.end();
string::const_iterator s2=substr.begin(), s2e=substr.end();
while(match_end!=s1e && s2!=s2e && cmp(*match_end++, *s2++));
return s2==s2e;
}
match_begin = search(search_begin, str.end(), substr.begin(), substr.end(), cmp);
if(match_begin==str.end()) return false;
match_end = match_begin + substr.length();
return true;
}
//************************************
// Method: getRegExpData
// FullName: getRegExpData
// Access: public static
// Returns: bool true if regexp-param=RegExp-Object / other false
// Qualifier:
// Parameter: const CFunctionsScopePtr & c
// Parameter: const string & regexp - parameter name of the regexp
// Parameter: bool noUndefined - true an undefined regexp aims in "" else in "undefined"
// Parameter: const string & flags - parameter name of the flags
// Parameter: string & substr - rgexp.source
// Parameter: bool & global
// Parameter: bool & ignoreCase
// Parameter: bool & sticky
//************************************
static CScriptVarPtr getRegExpData(const CFunctionsScopePtr &c, const string ®exp, bool noUndefined, const char *flags_argument, string &substr, bool &global, bool &ignoreCase, bool &sticky) {
CScriptVarPtr regexpVar = c->getArgument(regexp);
if(regexpVar->isRegExp()) {
#ifndef NO_REGEXP
CScriptVarRegExpPtr RegExp(regexpVar);
substr = RegExp->Regexp();
ignoreCase = RegExp->IgnoreCase();
global = RegExp->Global();
sticky = RegExp->Sticky();
return RegExp;
#endif /* NO_REGEXP */
} else {
substr.clear();
if(!noUndefined || !regexpVar->isUndefined()) substr = regexpVar->toString();
CScriptVarPtr flagVar;
if(flags_argument && (flagVar = c->getArgument(flags_argument)) && !flagVar->isUndefined()) {
string flags = flagVar->toString();
string::size_type pos = flags.find_first_not_of("gimy");
if(pos != string::npos) {
c->throwError(SyntaxError, string("invalid regular expression flag ")+flags[pos]);
}
global = flags.find_first_of('g')!=string::npos;
ignoreCase = flags.find_first_of('i')!=string::npos;
sticky = flags.find_first_of('y')!=string::npos;
} else
global = ignoreCase = sticky = false;
}
return CScriptVarPtr();
}
static void scStringReplace(const CFunctionsScopePtr &c, void *) {
const string str = this2string(c);
CScriptVarPtr newsubstrVar = c->getArgument("newsubstr");
string substr, ret_str;
bool global, ignoreCase, sticky;
bool isRegExp = getRegExpData(c, "substr", false, "flags", substr, global, ignoreCase, sticky);
if(isRegExp && !newsubstrVar->isFunction()) {
#ifndef NO_REGEXP
regex::flag_type flags = regex_constants::ECMAScript;
if(ignoreCase) flags |= regex_constants::icase;
regex_constants::match_flag_type mflags = regex_constants::match_default;
if(!global) mflags |= regex_constants::format_first_only;
if(sticky) mflags |= regex_constants::match_continuous;
ret_str = regex_replace(str, regex(substr, flags), newsubstrVar->toString(), mflags);
#endif /* NO_REGEXP */
} else {
bool (*search)(const string &, const string::const_iterator &, const string &, bool, bool, string::const_iterator &, string::const_iterator &);
#ifndef NO_REGEXP
if(isRegExp)
search = regex_search;
else
#endif /* NO_REGEXP */
search = string_search;
string newsubstr;
vector<CScriptVarPtr> arguments;
if(!newsubstrVar->isFunction())
newsubstr = newsubstrVar->toString();
global = global && substr.length();
string::const_iterator search_begin=str.begin(), match_begin, match_end;
if(search(str, search_begin, substr, ignoreCase, sticky, match_begin, match_end)) {
do {
ret_str.append(search_begin, match_begin);
if(newsubstrVar->isFunction()) {
arguments.push_back(c->newScriptVar(string(match_begin, match_end)));
newsubstr = c->getContext()->callFunction(newsubstrVar, arguments)->toString();
arguments.pop_back();
}
ret_str.append(newsubstr);
#if 1 /* Fix from "vcmpeq" (see Issue 14) currently untested */
if (match_begin == match_end) {
if (search_begin != str.end())
++search_begin;
else
break;
} else {
search_begin = match_end;
}
#else
search_begin = match_end;
#endif
} while(global && search(str, search_begin, substr, ignoreCase, sticky, match_begin, match_end));
}
ret_str.append(search_begin, str.end());
}
c->setReturnVar(c->newScriptVar(ret_str));
}
#ifndef NO_REGEXP
static void scStringMatch(const CFunctionsScopePtr &c, void *) {
string str = this2string(c);
string flags="flags", substr, newsubstr, match;
bool global, ignoreCase, sticky;
CScriptVarRegExpPtr RegExp = getRegExpData(c, "regexp", true, "flags", substr, global, ignoreCase, sticky);
if(!global) {
if(!RegExp)
RegExp = ::newScriptVar(c->getContext(), substr, flags);
if(RegExp) {
try {
c->setReturnVar(RegExp->exec(str));
} catch(regex_error e) {
c->throwError(SyntaxError, string(e.what())+" - "+CScriptVarRegExp::ErrorStr(e.code()));
}
}
} else {
try {
CScriptVarArrayPtr retVar = c->newScriptVar(Array);
int idx=0;
string::size_type offset=0;
global = global && substr.length();
string::const_iterator search_begin=str.begin(), match_begin, match_end;
if(regex_search(str, search_begin, substr, ignoreCase, sticky, match_begin, match_end)) {
do {
offset = match_begin-str.begin();
retVar->addChild(int2string(idx++), c->newScriptVar(string(match_begin, match_end)));
#if 1 /* Fix from "vcmpeq" (see Issue 14) currently untested */
if (match_begin == match_end) {
if (search_begin != str.end())
++search_begin;
else
break;
} else {
search_begin = match_end;
}
#else
search_begin = match_end;
#endif
} while(global && regex_search(str, search_begin, substr, ignoreCase, sticky, match_begin, match_end));
}
if(idx) {
retVar->addChild("input", c->newScriptVar(str));
retVar->addChild("index", c->newScriptVar((int)offset));
c->setReturnVar(retVar);
} else
c->setReturnVar(c->constScriptVar(Null));
} catch(regex_error e) {
c->throwError(SyntaxError, string(e.what())+" - "+CScriptVarRegExp::ErrorStr(e.code()));
}
}
}
#endif /* NO_REGEXP */
static void scStringSearch(const CFunctionsScopePtr &c, void *userdata) {
string str = this2string(c);
string substr;
bool global, ignoreCase, sticky;
getRegExpData(c, "regexp", true, "flags", substr, global, ignoreCase, sticky);
string::const_iterator search_begin=str.begin(), match_begin, match_end;
#ifndef NO_REGEXP
try {
c->setReturnVar(c->newScriptVar(regex_search(str, search_begin, substr, ignoreCase, sticky, match_begin, match_end)?match_begin-search_begin:-1));
} catch(regex_error e) {
c->throwError(SyntaxError, string(e.what())+" - "+CScriptVarRegExp::ErrorStr(e.code()));
}
#else /* NO_REGEXP */
c->setReturnVar(c->newScriptVar(string_search(str, search_begin, substr, ignoreCase, sticky, match_begin, match_end)?match_begin-search_begin:-1));
#endif /* NO_REGEXP */
}
static void scStringSlice(const CFunctionsScopePtr &c, void *userdata) {
string str = this2string(c);
int32_t length = c->getArgumentsLength()-(ptr2int32(userdata) & 1);
bool slice = (ptr2int32(userdata) & 2) == 0;
int32_t start = c->getArgument("start")->toNumber().toInt32();
int32_t end = (int32_t)str.size();
if(slice && start<0) start = (int32_t)(str.size())+start;
if(length>1) {
end = c->getArgument("end")->toNumber().toInt32();
if(slice && end<0) end = (int32_t)(str.size())+end;
}
if(!slice && end < start) { end^=start; start^=end; end^=start; }
if(start<0) start = 0;
if(start>=(int)str.size())
c->setReturnVar(c->newScriptVar(""));
else if(end <= start)
c->setReturnVar(c->newScriptVar(""));
else
c->setReturnVar(c->newScriptVar(str.substr(start, end-start)));
}
static void scStringSplit(const CFunctionsScopePtr &c, void *) {
const string str = this2string(c);
string seperator;
bool global, ignoreCase, sticky;
#ifndef NO_REGEXP
CScriptVarRegExpPtr RegExp = getRegExpData(c, "separator", true, 0, seperator, global, ignoreCase, sticky);
#else
getRegExpData(c, "separator", true, 0, seperator, global, ignoreCase, sticky);
#endif
CScriptVarPtr sep_var = c->getArgument("separator");
CScriptVarPtr limit_var = c->getArgument("limit");
int limit = limit_var->isUndefined() ? 0x7fffffff : limit_var->toNumber().toInt32();
CScriptVarPtr result(c->newScriptVar(Array));
c->setReturnVar(result);
if(limit == 0)
return;
else if(!str.size() || sep_var->isUndefined()) {
result->addChild("0", c->newScriptVar(str));
return;
}
if(seperator.size() == 0) {
for(int i=0; i<min((int)str.size(), limit); ++i)
result->addChild(i, c->newScriptVar(str.substr(i,1)));
return;
}
int length = 0;
string::const_iterator search_begin=str.begin(), match_begin, match_end;
#ifndef NO_REGEXP
smatch match;
#endif
bool found=true;
while(found) {
#ifndef NO_REGEXP
if(RegExp) {
try {
found = regex_search(str, search_begin, seperator, ignoreCase, sticky, match_begin, match_end, match);
} catch(regex_error e) {
c->throwError(SyntaxError, string(e.what())+" - "+CScriptVarRegExp::ErrorStr(e.code()));
}
} else /* NO_REGEXP */
#endif
found = string_search(str, search_begin, seperator, ignoreCase, sticky, match_begin, match_end);
string f;
if(found) {
result->addChild(length++, c->newScriptVar(string(search_begin, match_begin)));
if(length>=limit) break;
#ifndef NO_REGEXP
for(uint32_t i=1; i<match.size(); i++) {
if(match[i].matched)
result->addChild(length++, c->newScriptVar(string(match[i].first, match[i].second)));
else
result->addChild(length++, c->constScriptVar(Undefined));
if(length>=limit) break;
}
if(length>=limit) break;
#endif
search_begin = match_end;
} else {
result->addChild(length++, c->newScriptVar(string(search_begin,str.end())));
if(length>=limit) break;
}
}
}
static void scStringSubstr(const CFunctionsScopePtr &c, void *userdata) {
string str = this2string(c);
int32_t length = c->getArgumentsLength()-ptr2int32(userdata);
int32_t start = c->getArgument("start")->toNumber().toInt32();
if(start<0 || start>=(int)str.size())
c->setReturnVar(c->newScriptVar(""));
else if(length>1) {
int length = c->getArgument("length")->toNumber().toInt32();
c->setReturnVar(c->newScriptVar(str.substr(start, length)));
} else
c->setReturnVar(c->newScriptVar(str.substr(start)));
}
static void scStringToLowerCase(const CFunctionsScopePtr &c, void *) {
string str = this2string(c);
transform(str.begin(), str.end(), str.begin(), ::tolower);
c->setReturnVar(c->newScriptVar(str));
}
static void scStringToUpperCase(const CFunctionsScopePtr &c, void *) {
string str = this2string(c);
transform(str.begin(), str.end(), str.begin(), ::toupper);
c->setReturnVar(c->newScriptVar(str));
}
static void scStringTrim(const CFunctionsScopePtr &c, void *userdata) {
string str = this2string(c);
string::size_type start = 0;
string::size_type end = string::npos;
if(((ptr2int32(userdata)) & 2) == 0) {
start = str.find_first_not_of(" \t\r\n");
if(start == string::npos) start = 0;
}
if(((ptr2int32(userdata)) & 1) == 0) {
end = str.find_last_not_of(" \t\r\n");
if(end != string::npos) end = 1+end-start;
}
c->setReturnVar(c->newScriptVar(str.substr(start, end)));
}
static void scCharToInt(const CFunctionsScopePtr &c, void *) {
string str = c->getArgument("ch")->toString();;
int val = 0;
if (str.length()>0)
val = (int)str.c_str()[0];
c->setReturnVar(c->newScriptVar(val));
}
static void scStringFromCharCode(const CFunctionsScopePtr &c, void *) {
char str[2];
str[0] = c->getArgument("char")->toNumber().toInt32();
str[1] = 0;
c->setReturnVar(c->newScriptVar(str));
}
//////////////////////////////////////////////////////////////////////////
// RegExp-Stuff
//////////////////////////////////////////////////////////////////////////
#ifndef NO_REGEXP
static void scRegExpTest(const CFunctionsScopePtr &c, void *) {
CScriptVarRegExpPtr This = c->getArgument("this");
if(This)
c->setReturnVar(This->exec(c->getArgument("str")->toString(), true));
else
c->throwError(TypeError, "Object is not a RegExp-Object in test(str)");
}
static void scRegExpExec(const CFunctionsScopePtr &c, void *) {
CScriptVarRegExpPtr This = c->getArgument("this");
if(This)
c->setReturnVar(This->exec(c->getArgument("str")->toString()));
else
c->throwError(TypeError, "Object is not a RegExp-Object in exec(str)");
}
#endif /* NO_REGEXP */
// ----------------------------------------------- Register Functions
void registerStringFunctions(CTinyJS *tinyJS) {}
extern "C" void _registerStringFunctions(CTinyJS *tinyJS) {
CScriptVarPtr fnc;
// charAt
tinyJS->addNative("function String.prototype.charAt(pos)", scStringCharAt, 0, SCRIPTVARLINK_BUILDINDEFAULT);
tinyJS->addNative("function String.charAt(this,pos)", scStringCharAt, 0, SCRIPTVARLINK_BUILDINDEFAULT);
// charCodeAt
tinyJS->addNative("function String.prototype.charCodeAt(pos)", scStringCharCodeAt, 0, SCRIPTVARLINK_BUILDINDEFAULT);
tinyJS->addNative("function String.charCodeAt(this,pos)", scStringCharCodeAt, 0, SCRIPTVARLINK_BUILDINDEFAULT);
// concat
tinyJS->addNative("function String.prototype.concat()", scStringConcat, 0, SCRIPTVARLINK_BUILDINDEFAULT);
tinyJS->addNative("function String.concat(this)", scStringConcat, (void*)1, SCRIPTVARLINK_BUILDINDEFAULT);
// indexOf
tinyJS->addNative("function String.prototype.indexOf(search,pos)", scStringIndexOf, 0, SCRIPTVARLINK_BUILDINDEFAULT); // find the position of a string in a string, -1 if not
tinyJS->addNative("function String.indexOf(this,search,pos)", scStringIndexOf, 0, SCRIPTVARLINK_BUILDINDEFAULT); // find the position of a string in a string, -1 if not
// lastIndexOf
tinyJS->addNative("function String.prototype.lastIndexOf(search,pos)", scStringIndexOf, (void*)-1, SCRIPTVARLINK_BUILDINDEFAULT); // find the last position of a string in a string, -1 if not
tinyJS->addNative("function String.lastIndexOf(this,search,pos)", scStringIndexOf, (void*)-1, SCRIPTVARLINK_BUILDINDEFAULT); // find the last position of a string in a string, -1 if not
// localeCompare
tinyJS->addNative("function String.prototype.localeCompare(compareString)", scStringLocaleCompare, 0, SCRIPTVARLINK_BUILDINDEFAULT);
tinyJS->addNative("function String.localeCompare(this,compareString)", scStringLocaleCompare, 0, SCRIPTVARLINK_BUILDINDEFAULT);
// quote
tinyJS->addNative("function String.prototype.quote()", scStringQuote, 0, SCRIPTVARLINK_BUILDINDEFAULT);
tinyJS->addNative("function String.quote(this)", scStringQuote, 0, SCRIPTVARLINK_BUILDINDEFAULT);
#ifndef NO_REGEXP
// match
tinyJS->addNative("function String.prototype.match(regexp, flags)", scStringMatch, 0, SCRIPTVARLINK_BUILDINDEFAULT);
tinyJS->addNative("function String.match(this, regexp, flags)", scStringMatch, 0, SCRIPTVARLINK_BUILDINDEFAULT);
#endif /* !REGEXP */
// replace
tinyJS->addNative("function String.prototype.replace(substr, newsubstr, flags)", scStringReplace, 0, SCRIPTVARLINK_BUILDINDEFAULT);
tinyJS->addNative("function String.replace(this, substr, newsubstr, flags)", scStringReplace, 0, SCRIPTVARLINK_BUILDINDEFAULT);
// search
tinyJS->addNative("function String.prototype.search(regexp, flags)", scStringSearch, 0, SCRIPTVARLINK_BUILDINDEFAULT);
tinyJS->addNative("function String.search(this, regexp, flags)", scStringSearch, 0, SCRIPTVARLINK_BUILDINDEFAULT);
// slice
tinyJS->addNative("function String.prototype.slice(start,end)", scStringSlice, 0, SCRIPTVARLINK_BUILDINDEFAULT); // find the last position of a string in a string, -1 if not
tinyJS->addNative("function String.slice(this,start,end)", scStringSlice, (void*)1, SCRIPTVARLINK_BUILDINDEFAULT); // find the last position of a string in a string, -1 if not
// split
tinyJS->addNative("function String.prototype.split(separator,limit)", scStringSplit, 0, SCRIPTVARLINK_BUILDINDEFAULT);
tinyJS->addNative("function String.split(this,separator,limit)", scStringSplit, 0, SCRIPTVARLINK_BUILDINDEFAULT);
// substr
tinyJS->addNative("function String.prototype.substr(start,length)", scStringSubstr, 0, SCRIPTVARLINK_BUILDINDEFAULT);
tinyJS->addNative("function String.substr(this,start,length)", scStringSubstr, (void*)1, SCRIPTVARLINK_BUILDINDEFAULT);
// substring
tinyJS->addNative("function String.prototype.substring(start,end)", scStringSlice, (void*)2, SCRIPTVARLINK_BUILDINDEFAULT);
tinyJS->addNative("function String.substring(this,start,end)", scStringSlice, (void*)3, SCRIPTVARLINK_BUILDINDEFAULT);
// toLowerCase toLocaleLowerCase currently the same function
tinyJS->addNative("function String.prototype.toLowerCase()", scStringToLowerCase, 0, SCRIPTVARLINK_BUILDINDEFAULT);
tinyJS->addNative("function String.toLowerCase(this)", scStringToLowerCase, 0, SCRIPTVARLINK_BUILDINDEFAULT);
tinyJS->addNative("function String.prototype.toLocaleLowerCase()", scStringToLowerCase, 0, SCRIPTVARLINK_BUILDINDEFAULT);
tinyJS->addNative("function String.toLocaleLowerCase(this)", scStringToLowerCase, 0, SCRIPTVARLINK_BUILDINDEFAULT);
// toUpperCase toLocaleUpperCase currently the same function
tinyJS->addNative("function String.prototype.toUpperCase()", scStringToUpperCase, 0, SCRIPTVARLINK_BUILDINDEFAULT);
tinyJS->addNative("function String.toUpperCase(this)", scStringToUpperCase, 0, SCRIPTVARLINK_BUILDINDEFAULT);
tinyJS->addNative("function String.prototype.toLocaleUpperCase()", scStringToUpperCase, 0, SCRIPTVARLINK_BUILDINDEFAULT);
tinyJS->addNative("function String.toLocaleUpperCase(this)", scStringToUpperCase, 0, SCRIPTVARLINK_BUILDINDEFAULT);
// trim
tinyJS->addNative("function String.prototype.trim()", scStringTrim, 0, SCRIPTVARLINK_BUILDINDEFAULT);
tinyJS->addNative("function String.trim(this)", scStringTrim, 0, SCRIPTVARLINK_BUILDINDEFAULT);
// trimLeft
tinyJS->addNative("function String.prototype.trimLeft()", scStringTrim, (void*)1, SCRIPTVARLINK_BUILDINDEFAULT);
tinyJS->addNative("function String.trimLeft(this)", scStringTrim, (void*)1, SCRIPTVARLINK_BUILDINDEFAULT);
// trimRight
tinyJS->addNative("function String.prototype.trimRight()", scStringTrim, (void*)2, SCRIPTVARLINK_BUILDINDEFAULT);
tinyJS->addNative("function String.trimRight(this)", scStringTrim, (void*)2, SCRIPTVARLINK_BUILDINDEFAULT);
tinyJS->addNative("function charToInt(ch)", scCharToInt, 0, SCRIPTVARLINK_BUILDINDEFAULT); // convert a character to an int - get its value
tinyJS->addNative("function String.prototype.fromCharCode(char)", scStringFromCharCode, 0, SCRIPTVARLINK_BUILDINDEFAULT);
#ifndef NO_REGEXP
tinyJS->addNative("function RegExp.prototype.test(str)", scRegExpTest, 0, SCRIPTVARLINK_BUILDINDEFAULT);
tinyJS->addNative("function RegExp.prototype.exec(str)", scRegExpExec, 0, SCRIPTVARLINK_BUILDINDEFAULT);
#endif /* NO_REGEXP */
}