MinitScript  0.9.31 PRE-BETA
StringMethods.cpp
Go to the documentation of this file.
1 #include <regex>
2 #include <span>
3 
15 
16 using std::smatch;
17 using std::span;
18 
20 
22 
30 
31 void StringMethods::registerConstants(MinitScript* minitScript) {
32 }
33 
34 void StringMethods::registerMethods(MinitScript* minitScript) {
35  // string functions
36  {
37  //
38  class MethodString: public MinitScript::Method {
39  private:
40  MinitScript* minitScript { nullptr };
41  public:
42  MethodString(MinitScript* minitScript):
44  {
45  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }
46  },
47  MinitScript::TYPE_STRING
48  ),
49  minitScript(minitScript) {}
50  const string getMethodName() override {
51  return "String";
52  }
53  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
54  string stringValue;
55  if (arguments.size() == 1 &&
56  MinitScript::getStringValue(arguments, 0, stringValue) == true) {
57  returnValue.setValue(stringValue);
58  } else {
59  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
60  }
61  }
62  };
63  minitScript->registerMethod(new MethodString(minitScript));
64  }
65  {
66  //
67  class MethodStringGetSize: public MinitScript::Method {
68  private:
69  MinitScript* minitScript { nullptr };
70  public:
71  MethodStringGetSize(MinitScript* minitScript):
73  {
74  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }
75  },
76  MinitScript::TYPE_INTEGER
77  ),
78  minitScript(minitScript) {}
79  const string getMethodName() override {
80  return "String::getSize";
81  }
82  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
83  string stringValue;
84  if (arguments.size() == 1 &&
85  MinitScript::getStringValue(arguments, 0, stringValue) == true) {
86  returnValue.setValue(static_cast<int64_t>(_UTF8StringTools::getLength(stringValue, arguments[0].getStringValueCache())));
87  } else {
88  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
89  }
90  }
91  };
92  minitScript->registerMethod(new MethodStringGetSize(minitScript));
93  }
94  {
95  //
96  class MethodStringCharAt: public MinitScript::Method {
97  private:
98  MinitScript* minitScript { nullptr };
99  public:
100  MethodStringCharAt(MinitScript* minitScript):
102  {
103  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false },
104  { .type = MinitScript::TYPE_INTEGER, .name = "index", .optional = false, .reference = false, .nullable = false }
105  },
106  MinitScript::TYPE_STRING
107  ),
108  minitScript(minitScript) {}
109  const string getMethodName() override {
110  return "String::charAt";
111  }
112  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
113  string stringValue;
114  int64_t index;
115  if (arguments.size() == 2 &&
116  MinitScript::getStringValue(arguments, 0, stringValue) == true &&
117  MinitScript::getIntegerValue(arguments, 1, index) == true) {
118  returnValue.setValue(_UTF8StringTools::getCharAt(stringValue, index, arguments[0].getStringValueCache()));
119  } else {
120  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
121  }
122  }
123  };
124  minitScript->registerMethod(new MethodStringCharAt(minitScript));
125  }
126  {
127  //
128  class MethodStringCodePointAt: public MinitScript::Method {
129  private:
130  MinitScript* minitScript { nullptr };
131  public:
132  MethodStringCodePointAt(MinitScript* minitScript):
134  {
135  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false },
136  { .type = MinitScript::TYPE_INTEGER, .name = "index", .optional = false, .reference = false, .nullable = false }
137  },
138  MinitScript::TYPE_INTEGER
139  ),
140  minitScript(minitScript) {}
141  const string getMethodName() override {
142  return "String::codePointAt";
143  }
144  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
145  string stringValue;
146  int64_t index;
147  if (arguments.size() == 2 &&
148  MinitScript::getStringValue(arguments, 0, stringValue) == true &&
149  MinitScript::getIntegerValue(arguments, 1, index) == true) {
150  returnValue.setValue(static_cast<int64_t>(_UTF8StringTools::getCodePointAt(stringValue, index, arguments[0].getStringValueCache())));
151  } else {
152  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
153  }
154  }
155  };
156  minitScript->registerMethod(new MethodStringCodePointAt(minitScript));
157  }
158  {
159  //
160  class MethodStringStartsWith: public MinitScript::Method {
161  private:
162  MinitScript* minitScript { nullptr };
163  public:
164  MethodStringStartsWith(MinitScript* minitScript):
166  {
167  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false },
168  { .type = MinitScript::TYPE_STRING, .name = "prefix", .optional = false, .reference = false, .nullable = false }
169  },
170  MinitScript::TYPE_BOOLEAN
171  ),
172  minitScript(minitScript) {}
173  const string getMethodName() override {
174  return "String::startsWith";
175  }
176  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
177  string stringValue;
178  string prefix;
179  if (arguments.size() == 2 &&
180  MinitScript::getStringValue(arguments, 0, stringValue) == true &&
181  MinitScript::getStringValue(arguments, 1, prefix) == true) {
182  returnValue.setValue(_UTF8StringTools::startsWith(stringValue, prefix));
183  } else {
184  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
185  }
186  }
187  };
188  minitScript->registerMethod(new MethodStringStartsWith(minitScript));
189  }
190  {
191  //
192  class MethodStringEndsWith: public MinitScript::Method {
193  private:
194  MinitScript* minitScript { nullptr };
195  public:
196  MethodStringEndsWith(MinitScript* minitScript):
198  {
199  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false },
200  { .type = MinitScript::TYPE_STRING, .name = "suffix", .optional = false, .reference = false, .nullable = false }
201  },
202  MinitScript::TYPE_BOOLEAN
203  ),
204  minitScript(minitScript) {}
205  const string getMethodName() override {
206  return "String::endsWith";
207  }
208  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
209  string stringValue;
210  string suffix;
211  if (arguments.size() == 2 &&
212  MinitScript::getStringValue(arguments, 0, stringValue) == true &&
213  MinitScript::getStringValue(arguments, 1, suffix) == true) {
214  returnValue.setValue(_UTF8StringTools::endsWith(stringValue, suffix));
215  } else {
216  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
217  }
218  }
219  };
220  minitScript->registerMethod(new MethodStringEndsWith(minitScript));
221  }
222  {
223  //
224  class MethodStringReplace: public MinitScript::Method {
225  private:
226  MinitScript* minitScript { nullptr };
227  public:
228  MethodStringReplace(MinitScript* minitScript):
230  {
231  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false },
232  { .type = MinitScript::TYPE_STRING, .name = "what", .optional = false, .reference = false, .nullable = false },
233  { .type = MinitScript::TYPE_STRING, .name = "by", .optional = false, .reference = false, .nullable = false },
234  { .type = MinitScript::TYPE_INTEGER, .name = "beginIndex", .optional = true, .reference = false, .nullable = false }
235  },
236  MinitScript::TYPE_STRING
237  ),
238  minitScript(minitScript) {}
239  const string getMethodName() override {
240  return "String::replace";
241  }
242  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
243  string stringValue;
244  string what;
245  string by;
246  int64_t beginIndex = 0;
247  if ((arguments.size() == 3 || arguments.size() == 4) &&
248  MinitScript::getStringValue(arguments, 0, stringValue) == true &&
249  MinitScript::getStringValue(arguments, 1, what) == true &&
250  MinitScript::getStringValue(arguments, 2, by) == true &&
251  MinitScript::getIntegerValue(arguments, 3, beginIndex, true) == true) {
252  returnValue.setValue(_UTF8StringTools::replace(stringValue, what, by, beginIndex, arguments[0].getStringValueCache()));
253  } else {
254  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
255  }
256  }
257  };
258  minitScript->registerMethod(new MethodStringReplace(minitScript));
259  }
260  {
261  //
262  class MethodStringIndexOf: public MinitScript::Method {
263  private:
264  MinitScript* minitScript { nullptr };
265  public:
266  MethodStringIndexOf(MinitScript* minitScript):
268  {
269  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false },
270  { .type = MinitScript::TYPE_STRING, .name = "what", .optional = false, .reference = false, .nullable = false },
271  { .type = MinitScript::TYPE_INTEGER, .name = "beginIndex", .optional = true, .reference = false, .nullable = false }
272  },
273  MinitScript::TYPE_INTEGER
274  ),
275  minitScript(minitScript) {}
276  const string getMethodName() override {
277  return "String::indexOf";
278  }
279  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
280  string stringValue;
281  string what;
282  int64_t beginIndex = 0;
283  if ((arguments.size() == 2 || arguments.size() == 3) &&
284  MinitScript::getStringValue(arguments, 0, stringValue) == true &&
285  MinitScript::getStringValue(arguments, 1, what) == true &&
286  MinitScript::getIntegerValue(arguments, 2, beginIndex, true) == true) {
287  returnValue.setValue(_UTF8StringTools::indexOf(stringValue, what, beginIndex, arguments[0].getStringValueCache()));
288  } else {
289  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
290  }
291  }
292  };
293  minitScript->registerMethod(new MethodStringIndexOf(minitScript));
294  }
295  {
296  //
297  class MethodStringFirstIndexOf: public MinitScript::Method {
298  private:
299  MinitScript* minitScript { nullptr };
300  public:
301  MethodStringFirstIndexOf(MinitScript* minitScript):
303  {
304  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false },
305  { .type = MinitScript::TYPE_STRING, .name = "what", .optional = false, .reference = false, .nullable = false },
306  { .type = MinitScript::TYPE_INTEGER, .name = "beginIndex", .optional = true, .reference = false, .nullable = false }
307  },
308  MinitScript::TYPE_INTEGER
309  ),
310  minitScript(minitScript) {}
311  const string getMethodName() override {
312  return "String::firstIndexOf";
313  }
314  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
315  string stringValue;
316  string what;
317  int64_t beginIndex = 0;
318  if ((arguments.size() == 2 || arguments.size() == 3) &&
319  MinitScript::getStringValue(arguments, 0, stringValue) == true &&
320  MinitScript::getStringValue(arguments, 1, what) == true &&
321  MinitScript::getIntegerValue(arguments, 2, beginIndex, true) == true) {
322  returnValue.setValue(_UTF8StringTools::firstIndexOf(stringValue, what, beginIndex, arguments[0].getStringValueCache()));
323  } else {
324  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
325  }
326  }
327  };
328  minitScript->registerMethod(new MethodStringFirstIndexOf(minitScript));
329  }
330  {
331  //
332  class MethodStringLastIndexOf: public MinitScript::Method {
333  private:
334  MinitScript* minitScript { nullptr };
335  public:
336  MethodStringLastIndexOf(MinitScript* minitScript):
338  {
339  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false },
340  { .type = MinitScript::TYPE_STRING, .name = "what", .optional = false, .reference = false, .nullable = false },
341  { .type = MinitScript::TYPE_INTEGER, .name = "beginIndex", .optional = true, .reference = false, .nullable = false }
342  },
343  MinitScript::TYPE_INTEGER
344  ),
345  minitScript(minitScript) {}
346  const string getMethodName() override {
347  return "String::lastIndexOf";
348  }
349  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
350  string stringValue;
351  string what;
352  int64_t beginIndex = 0;
353  if ((arguments.size() == 2 || arguments.size() == 3) &&
354  MinitScript::getStringValue(arguments, 0, stringValue) == true &&
355  MinitScript::getStringValue(arguments, 1, what) == true &&
356  MinitScript::getIntegerValue(arguments, 2, beginIndex, true) == true) {
357  returnValue.setValue(_UTF8StringTools::lastIndexOf(stringValue, what, beginIndex, arguments[0].getStringValueCache()));
358  } else {
359  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
360  }
361  }
362  };
363  minitScript->registerMethod(new MethodStringLastIndexOf(minitScript));
364  }
365  {
366  //
367  class MethodStringFirstIndexOfChars: public MinitScript::Method {
368  private:
369  MinitScript* minitScript { nullptr };
370  public:
371  MethodStringFirstIndexOfChars(MinitScript* minitScript):
373  {
374  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false },
375  { .type = MinitScript::TYPE_STRING, .name = "what", .optional = false, .reference = false, .nullable = false },
376  { .type = MinitScript::TYPE_INTEGER, .name = "beginIndex", .optional = true, .reference = false, .nullable = false }
377  },
378  MinitScript::TYPE_INTEGER
379  ),
380  minitScript(minitScript) {}
381  const string getMethodName() override {
382  return "String::firstIndexOfChars";
383  }
384  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
385  string stringValue;
386  string what;
387  int64_t beginIndex = 0;
388  if ((arguments.size() == 2 || arguments.size() == 3) &&
389  MinitScript::getStringValue(arguments, 0, stringValue) == true &&
390  MinitScript::getStringValue(arguments, 1, what) == true &&
391  MinitScript::getIntegerValue(arguments, 2, beginIndex, true) == true) {
392  returnValue.setValue(
393  static_cast<int64_t>(
395  stringValue,
396  what,
397  beginIndex,
398  arguments[0].getStringValueCache(),
399  arguments[1].getStringValueCache()
400  )
401  )
402  );
403  } else {
404  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
405  }
406  }
407  };
408  minitScript->registerMethod(new MethodStringFirstIndexOfChars(minitScript));
409  }
410  {
411  //
412  class MethodStringLastIndexOfChars: public MinitScript::Method {
413  private:
414  MinitScript* minitScript { nullptr };
415  public:
416  MethodStringLastIndexOfChars(MinitScript* minitScript):
418  {
419  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false },
420  { .type = MinitScript::TYPE_STRING, .name = "what", .optional = false, .reference = false, .nullable = false },
421  { .type = MinitScript::TYPE_INTEGER, .name = "endIndex", .optional = true, .reference = false, .nullable = false }
422  },
423  MinitScript::TYPE_INTEGER
424  ),
425  minitScript(minitScript) {}
426  const string getMethodName() override {
427  return "String::lastIndexOfChars";
428  }
429  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
430  string stringValue;
431  string what;
432  int64_t endIndex = string::npos;
433  if ((arguments.size() == 2 || arguments.size() == 3) &&
434  MinitScript::getStringValue(arguments, 0, stringValue) == true &&
435  MinitScript::getStringValue(arguments, 1, what) == true &&
436  MinitScript::getIntegerValue(arguments, 2, endIndex, true) == true) {
437  returnValue.setValue(
438  static_cast<int64_t>(
440  stringValue,
441  what,
442  endIndex,
443  arguments[0].getStringValueCache(),
444  arguments[1].getStringValueCache()
445  )
446  )
447  );
448  } else {
449  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
450  }
451  }
452  };
453  minitScript->registerMethod(new MethodStringLastIndexOfChars(minitScript));
454  }
455  {
456  //
457  class MethodStringSubString: public MinitScript::Method {
458  private:
459  MinitScript* minitScript { nullptr };
460  public:
461  MethodStringSubString(MinitScript* minitScript):
463  {
464  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false },
465  { .type = MinitScript::TYPE_INTEGER, .name = "beginIndex", .optional = false, .reference = false, .nullable = false },
466  { .type = MinitScript::TYPE_INTEGER, .name = "endIndex", .optional = true, .reference = false, .nullable = false },
467  },
468  MinitScript::TYPE_STRING
469  ),
470  minitScript(minitScript) {}
471  const string getMethodName() override {
472  return "String::substring";
473  }
474  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
475  string stringValue;
476  int64_t beginIndex;
477  int64_t endIndex = string::npos;
478  if ((arguments.size() == 2 || arguments.size() == 3) &&
479  MinitScript::getStringValue(arguments, 0, stringValue) == true &&
480  MinitScript::getIntegerValue(arguments, 1, beginIndex) == true &&
481  MinitScript::getIntegerValue(arguments, 2, endIndex, true) == true) {
482  // utf8 character iterator
483  returnValue.setValue(_UTF8StringTools::substring(stringValue, beginIndex, endIndex));
484  } else {
485  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
486  }
487  }
488  };
489  minitScript->registerMethod(new MethodStringSubString(minitScript));
490  }
491  {
492  //
493  class MethodStringEqualsIgnoreCase: public MinitScript::Method {
494  private:
495  MinitScript* minitScript { nullptr };
496  public:
497  MethodStringEqualsIgnoreCase(MinitScript* minitScript):
499  {
500  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false },
501  { .type = MinitScript::TYPE_STRING, .name = "other", .optional = false, .reference = false, .nullable = false },
502  },
503  MinitScript::TYPE_BOOLEAN
504  ),
505  minitScript(minitScript) {}
506  const string getMethodName() override {
507  return "String::equalsIgnoreCase";
508  }
509  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
510  string stringValue;
511  string other;
512  if (arguments.size() == 2 &&
513  MinitScript::getStringValue(arguments, 0, stringValue) == true &&
514  MinitScript::getStringValue(arguments, 1, other) == true) {
515  returnValue.setValue(_UTF8StringTools::equalsIgnoreCase(stringValue, other, arguments[0].getStringValueCache(), arguments[1].getStringValueCache()));
516  } else {
517  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
518  }
519  }
520  };
521  minitScript->registerMethod(new MethodStringEqualsIgnoreCase(minitScript));
522  }
523  {
524  //
525  class MethodStringTrim: public MinitScript::Method {
526  private:
527  MinitScript* minitScript { nullptr };
528  public:
529  MethodStringTrim(MinitScript* minitScript):
531  {
532  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false },
533  },
534  MinitScript::TYPE_STRING
535  ),
536  minitScript(minitScript) {}
537  const string getMethodName() override {
538  return "String::trim";
539  }
540  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
541  string stringValue;
542  if (arguments.size() == 1 &&
543  MinitScript::getStringValue(arguments, 0, stringValue) == true) {
544  returnValue.setValue(_UTF8StringTools::trim(stringValue, arguments[0].getStringValueCache()));
545  } else {
546  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
547  }
548  }
549  };
550  minitScript->registerMethod(new MethodStringTrim(minitScript));
551  }
552  {
553  //
554  class MethodStringRegexMatch: public MinitScript::Method {
555  private:
556  MinitScript* minitScript { nullptr };
557  public:
558  MethodStringRegexMatch(MinitScript* minitScript):
560  {
561  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false },
562  { .type = MinitScript::TYPE_STRING, .name = "pattern", .optional = false, .reference = false, .nullable = false },
563  { .type = MinitScript::TYPE_ARRAY, .name = "matches", .optional = true, .reference = true, .nullable = true },
564  },
565  MinitScript::TYPE_BOOLEAN
566  ),
567  minitScript(minitScript) {}
568  const string getMethodName() override {
569  return "String::regexMatch";
570  }
571  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
572  string stringValue;
573  string pattern;
574  if ((arguments.size() == 2 || arguments.size() == 3) &&
575  MinitScript::getStringValue(arguments, 0, stringValue) == true &&
576  MinitScript::getStringValue(arguments, 1, pattern) == true) {
577  if (arguments.size() == 3) {
578  smatch matches;
579  returnValue.setValue(_UTF8StringTools::regexMatch(stringValue, pattern, &matches));
580  arguments[2].setType(MinitScript::TYPE_ARRAY);
581  arguments[2].clearArray();
582  for (const auto& match: matches) {
583  arguments[2].pushArrayEntry(MinitScript::Variable(string(match.str())));
584  }
585  } else {
586  returnValue.setValue(_UTF8StringTools::regexMatch(stringValue, pattern));
587  }
588  } else {
589  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
590  }
591  }
592  };
593  minitScript->registerMethod(new MethodStringRegexMatch(minitScript));
594  }
595  {
596  //
597  class MethodStringRegexSearch: public MinitScript::Method {
598  private:
599  MinitScript* minitScript { nullptr };
600  public:
601  MethodStringRegexSearch(MinitScript* minitScript):
603  {
604  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false },
605  { .type = MinitScript::TYPE_STRING, .name = "pattern", .optional = false, .reference = false, .nullable = false },
606  { .type = MinitScript::TYPE_ARRAY, .name = "matches", .optional = true, .reference = true, .nullable = true },
607  },
608  MinitScript::TYPE_BOOLEAN
609  ),
610  minitScript(minitScript) {}
611  const string getMethodName() override {
612  return "String::regexSearch";
613  }
614  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
615  string stringValue;
616  string pattern;
617  if ((arguments.size() == 2 || arguments.size() == 3) &&
618  MinitScript::getStringValue(arguments, 0, stringValue) == true &&
619  MinitScript::getStringValue(arguments, 1, pattern) == true) {
620  if (arguments.size() == 3) {
621  smatch matches;
622  returnValue.setValue(_UTF8StringTools::regexSearch(stringValue, pattern, &matches));
623  arguments[2].setType(MinitScript::TYPE_ARRAY);
624  arguments[2].clearArray();
625  for (const auto& match: matches) {
626  arguments[2].pushArrayEntry(MinitScript::Variable(string(match.str())));
627  }
628  } else {
629  returnValue.setValue(_UTF8StringTools::regexSearch(stringValue, pattern));
630  }
631  } else {
632  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
633  }
634  }
635  };
636  minitScript->registerMethod(new MethodStringRegexSearch(minitScript));
637  }
638  {
639  //
640  class MethodStringRegexReplace: public MinitScript::Method {
641  private:
642  MinitScript* minitScript { nullptr };
643  public:
644  MethodStringRegexReplace(MinitScript* minitScript):
646  {
647  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false },
648  { .type = MinitScript::TYPE_STRING, .name = "pattern", .optional = false, .reference = false, .nullable = false },
649  { .type = MinitScript::TYPE_STRING, .name = "by", .optional = false, .reference = false, .nullable = false },
650  },
651  MinitScript::TYPE_STRING
652  ),
653  minitScript(minitScript) {}
654  const string getMethodName() override {
655  return "String::regexReplace";
656  }
657  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
658  string stringValue;
659  string pattern;
660  string by;
661  if (arguments.size() == 3 &&
662  MinitScript::getStringValue(arguments, 0, stringValue) == true &&
663  MinitScript::getStringValue(arguments, 1, pattern) == true &&
664  MinitScript::getStringValue(arguments, 2, by) == true) {
665  returnValue.setValue(_UTF8StringTools::regexReplace(stringValue, pattern, by));
666  } else {
667  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
668  }
669  }
670  };
671  minitScript->registerMethod(new MethodStringRegexReplace(minitScript));
672  }
673  {
674  //
675  class MethodStringTokenize: public MinitScript::Method {
676  private:
677  MinitScript* minitScript { nullptr };
678  public:
679  MethodStringTokenize(MinitScript* minitScript):
681  {
682  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false },
683  { .type = MinitScript::TYPE_STRING, .name = "delimiters", .optional = false, .reference = false, .nullable = false },
684  },
685  MinitScript::TYPE_ARRAY
686  ),
687  minitScript(minitScript) {}
688  const string getMethodName() override {
689  return "String::tokenize";
690  }
691  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
692  string stringValue;
693  string delimiters;
694  if (arguments.size() == 2 &&
695  MinitScript::getStringValue(arguments, 0, stringValue) == true &&
696  MinitScript::getStringValue(arguments, 1, delimiters) == true) {
697  auto tokenizedStringVector = _UTF8StringTools::tokenize(stringValue, delimiters);
698  returnValue.setType(MinitScript::TYPE_ARRAY);
699  for (const auto& tokenizedString: tokenizedStringVector) {
700  returnValue.pushArrayEntry(tokenizedString);
701  }
702  } else {
703  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
704  }
705  }
706  };
707  minitScript->registerMethod(new MethodStringTokenize(minitScript));
708  }
709  {
710  //
711  class MethodStringGenerate: public MinitScript::Method {
712  private:
713  MinitScript *minitScript { nullptr };
714  public:
715  MethodStringGenerate(MinitScript *minitScript) :
717  {
718  { .type = MinitScript::TYPE_STRING, .name = "what", .optional = false, .reference = false, .nullable = false },
719  { .type = MinitScript::TYPE_INTEGER, .name = "count", .optional = true, .reference = false, .nullable = false }
720  },
721  MinitScript::TYPE_STRING
722  ),
723  minitScript(minitScript) {
724  //
725  }
726  const string getMethodName() override {
727  return "String::generate";
728  }
729  void executeMethod(span<MinitScript::Variable> &arguments, MinitScript::Variable &returnValue, const MinitScript::SubStatement& subStatement) override {
730  string what;
731  int64_t count = 1;
732  if ((arguments.size() == 1 || arguments.size() == 2) &&
733  MinitScript::getStringValue(arguments, 0, what) == true &&
734  MinitScript::getIntegerValue(arguments, 1, count, true) == true) {
735  returnValue.setValue(_UTF8StringTools::generate(what, count));
736  } else {
737  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
738  }
739  }
740  };
741  minitScript->registerMethod(new MethodStringGenerate(minitScript));
742  }
743  {
744  //
745  class MethodStringIndent: public MinitScript::Method {
746  private:
747  MinitScript *minitScript { nullptr };
748  public:
749  MethodStringIndent(MinitScript *minitScript) :
751  {
752  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false },
753  { .type = MinitScript::TYPE_STRING, .name = "with", .optional = false, .reference = false, .nullable = false },
754  { .type = MinitScript::TYPE_INTEGER, .name = "count", .optional = false, .reference = false, .nullable = false }
755  },
756  MinitScript::TYPE_STRING
757  ),
758  minitScript(minitScript) {
759  //
760  }
761  const string getMethodName() override {
762  return "String::indent";
763  }
764  void executeMethod(span<MinitScript::Variable> &arguments, MinitScript::Variable &returnValue, const MinitScript::SubStatement& subStatement) override {
765  string src;
766  string with;
767  int64_t count = 1;
768  if ((arguments.size() == 2 || arguments.size() == 3) &&
769  MinitScript::getStringValue(arguments, 0, src) == true &&
770  MinitScript::getStringValue(arguments, 1, with) == true &&
771  MinitScript::getIntegerValue(arguments, 2, count, true) == true) {
772  returnValue.setValue(_UTF8StringTools::indent(src, with, count));
773  } else {
774  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
775  }
776  }
777  };
778  minitScript->registerMethod(new MethodStringIndent(minitScript));
779  }
780  {
781  //
782  class MethodStringConcatenate: public MinitScript::Method {
783  private:
784  MinitScript* minitScript { nullptr };
785  public:
786  MethodStringConcatenate(MinitScript* minitScript): MinitScript::Method({}, MinitScript::TYPE_STRING), minitScript(minitScript) {}
787  const string getMethodName() override {
788  return "String::concatenate";
789  }
790  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
791  string result;
792  for (const auto& argument: arguments) {
793  result+= argument.getValueAsString();
794  }
795  returnValue.setValue(result);
796  }
797  bool isVariadic() const override {
798  return true;
799  }
800  };
801  minitScript->registerMethod(new MethodStringConcatenate(minitScript));
802  }
803  {
804  //
805  class MethodToStringUpperCase: public MinitScript::Method {
806  private:
807  MinitScript* minitScript { nullptr };
808  public:
809  MethodToStringUpperCase(MinitScript* minitScript):
811  {
812  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }
813  },
814  MinitScript::TYPE_STRING
815  ),
816  minitScript(minitScript) {}
817  const string getMethodName() override {
818  return "String::toUpperCase";
819  }
820  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
821  string stringValue;
822  if (arguments.size() == 1 &&
823  MinitScript::getStringValue(arguments, 0, stringValue) == true) {
824  returnValue.setValue(_UTF8StringTools::toUpperCase(stringValue, arguments[0].getStringValueCache()));
825  } else {
826  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
827  }
828  }
829  };
830  minitScript->registerMethod(new MethodToStringUpperCase(minitScript));
831  }
832  {
833  //
834  class MethodToStringLowerCase: public MinitScript::Method {
835  private:
836  MinitScript* minitScript { nullptr };
837  public:
838  MethodToStringLowerCase(MinitScript* minitScript):
840  {
841  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }
842  },
843  MinitScript::TYPE_STRING
844  ),
845  minitScript(minitScript) {}
846  const string getMethodName() override {
847  return "String::toLowerCase";
848  }
849  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
850  string stringValue;
851  if (arguments.size() == 1 &&
852  MinitScript::getStringValue(arguments, 0, stringValue) == true) {
853  returnValue.setValue(_UTF8StringTools::toLowerCase(stringValue, arguments[0].getStringValueCache()));
854  } else {
855  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
856  }
857  }
858  };
859  minitScript->registerMethod(new MethodToStringLowerCase(minitScript));
860  }
861  {
862  //
863  class MethodStringIsEmpty: public MinitScript::Method {
864  private:
865  MinitScript* minitScript { nullptr };
866  public:
867  MethodStringIsEmpty(MinitScript* minitScript):
869  {
870  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }
871  },
872  MinitScript::TYPE_BOOLEAN
873  ),
874  minitScript(minitScript) {}
875  const string getMethodName() override {
876  return "String::isEmpty";
877  }
878  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
879  string stringValue;
880  if (arguments.size() == 1 &&
881  MinitScript::getStringValue(arguments, 0, stringValue) == true) {
882  returnValue.setValue(stringValue.empty());
883  } else {
884  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
885  }
886  }
887  };
888  minitScript->registerMethod(new MethodStringIsEmpty(minitScript));
889  }
890  {
891  //
892  class MethodStringIsFloat: public MinitScript::Method {
893  private:
894  MinitScript* minitScript { nullptr };
895  public:
896  MethodStringIsFloat(MinitScript* minitScript):
898  {
899  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }
900  },
901  MinitScript::TYPE_BOOLEAN
902  ),
903  minitScript(minitScript) {}
904  const string getMethodName() override {
905  return "String::isFloat";
906  }
907  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
908  string stringValue;
909  if (arguments.size() == 1 &&
910  MinitScript::getStringValue(arguments, 0, stringValue) == true) {
911  returnValue.setValue(_Float::is(stringValue));
912  } else {
913  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
914  }
915  }
916  };
917  minitScript->registerMethod(new MethodStringIsFloat(minitScript));
918  }
919  {
920  //
921  class MethodStringIsInteger: public MinitScript::Method {
922  private:
923  MinitScript* minitScript { nullptr };
924  public:
925  MethodStringIsInteger(MinitScript* minitScript):
927  {
928  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }
929  },
930  MinitScript::TYPE_BOOLEAN
931  ),
932  minitScript(minitScript) {}
933  const string getMethodName() override {
934  return "String::isInteger";
935  }
936  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
937  string stringValue;
938  if (arguments.size() == 1 &&
939  MinitScript::getStringValue(arguments, 0, stringValue) == true) {
940  returnValue.setValue(_Integer::is(stringValue));
941  } else {
942  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
943  }
944  }
945  };
946  minitScript->registerMethod(new MethodStringIsInteger(minitScript));
947  }
948  {
949  //
950  class MethodStringPadLeft: public MinitScript::Method {
951  private:
952  MinitScript* minitScript { nullptr };
953  public:
954  MethodStringPadLeft(MinitScript* minitScript):
956  {
957  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false },
958  { .type = MinitScript::TYPE_STRING, .name = "by", .optional = false, .reference = false, .nullable = false },
959  { .type = MinitScript::TYPE_INTEGER, .name = "toLength", .optional = false, .reference = false, .nullable = false }
960  },
961  MinitScript::TYPE_STRING
962  ),
963  minitScript(minitScript) {}
964  const string getMethodName() override {
965  return "String::padLeft";
966  }
967  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
968  string stringValue;
969  string by;
970  int64_t toLength;
971  if (arguments.size() == 3 &&
972  MinitScript::getStringValue(arguments, 0, stringValue) == true &&
973  MinitScript::getStringValue(arguments, 1, by) == true &&
974  MinitScript::getIntegerValue(arguments, 2, toLength) == true) {
975  returnValue.setValue(_UTF8StringTools::padLeft(stringValue, by, toLength, arguments[0].getStringValueCache()));
976  } else {
977  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
978  }
979  }
980  };
981  minitScript->registerMethod(new MethodStringPadLeft(minitScript));
982  }
983  {
984  //
985  class MethodStringPadRight: public MinitScript::Method {
986  private:
987  MinitScript* minitScript { nullptr };
988  public:
989  MethodStringPadRight(MinitScript* minitScript):
991  {
992  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false },
993  { .type = MinitScript::TYPE_STRING, .name = "by", .optional = false, .reference = false, .nullable = false },
994  { .type = MinitScript::TYPE_INTEGER, .name = "toLength", .optional = false, .reference = false, .nullable = false }
995  },
996  MinitScript::TYPE_STRING
997  ),
998  minitScript(minitScript) {}
999  const string getMethodName() override {
1000  return "String::padRight";
1001  }
1002  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
1003  string stringValue;
1004  string by;
1005  int64_t toLength;
1006  if (arguments.size() == 3 &&
1007  MinitScript::getStringValue(arguments, 0, stringValue) == true &&
1008  MinitScript::getStringValue(arguments, 1, by) == true &&
1009  MinitScript::getIntegerValue(arguments, 2, toLength) == true) {
1010  returnValue.setValue(_UTF8StringTools::padRight(stringValue, by, toLength, arguments[0].getStringValueCache()));
1011  } else {
1012  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
1013  }
1014  }
1015  };
1016  minitScript->registerMethod(new MethodStringPadRight(minitScript));
1017  }
1018  {
1019  //
1020  class MethodStringToByteArray: public MinitScript::Method {
1021  private:
1022  MinitScript* minitScript { nullptr };
1023  public:
1024  MethodStringToByteArray(MinitScript* minitScript):
1026  {
1027  { .type = MinitScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false },
1028  },
1029  MinitScript::TYPE_BYTEARRAY
1030  ),
1031  minitScript(minitScript) {}
1032  const string getMethodName() override {
1033  return "String::toByteArray";
1034  }
1035  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
1036  string stringValue;
1037  if (arguments.size() == 1 &&
1038  MinitScript::getStringValue(arguments, 0, stringValue) == true) {
1039  returnValue.setType(MinitScript::TYPE_BYTEARRAY);
1040  for (auto i = 0; i < stringValue.size(); i++) returnValue.pushByteArrayEntry(stringValue[i]);
1041  } else {
1042  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
1043  }
1044  }
1045  };
1046  minitScript->registerMethod(new MethodStringToByteArray(minitScript));
1047  }
1048  {
1049  //
1050  class MethodStringFromByteArray: public MinitScript::Method {
1051  private:
1052  MinitScript* minitScript { nullptr };
1053  public:
1054  MethodStringFromByteArray(MinitScript* minitScript):
1056  {
1057  { .type = MinitScript::TYPE_BYTEARRAY, .name = "byteArray", .optional = false, .reference = false, .nullable = false },
1058  },
1059  MinitScript::TYPE_STRING
1060  ),
1061  minitScript(minitScript) {}
1062  const string getMethodName() override {
1063  return "String::fromByteArray";
1064  }
1065  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
1066  string stringValue;
1067  if (arguments.size() == 1 &&
1068  arguments[0].getType() == MinitScript::TYPE_BYTEARRAY) {
1069  auto byteArrayPointer = arguments[0].getByteArrayPointer();
1070  if (byteArrayPointer != nullptr) {
1071  returnValue.setValue(string((const char*)(byteArrayPointer->data()), byteArrayPointer->size()));
1072  }
1073  } else {
1074  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
1075  }
1076  }
1077  };
1078  minitScript->registerMethod(new MethodStringFromByteArray(minitScript));
1079  }
1080  {
1081  //
1082  class MethodStringFromCodePoint: public MinitScript::Method {
1083  private:
1084  MinitScript* minitScript { nullptr };
1085  public:
1086  MethodStringFromCodePoint(MinitScript* minitScript):
1088  {
1089  { .type = MinitScript::TYPE_INTEGER, .name = "codePoint", .optional = false, .reference = false, .nullable = false },
1090  },
1091  MinitScript::TYPE_STRING
1092  ),
1093  minitScript(minitScript) {}
1094  const string getMethodName() override {
1095  return "String::fromCodePoint";
1096  }
1097  void executeMethod(span<MinitScript::Variable>& arguments, MinitScript::Variable& returnValue, const MinitScript::SubStatement& subStatement) override {
1098  int64_t codePoint;
1099  if (arguments.size() == 1 &&
1100  MinitScript::getIntegerValue(arguments, 0, codePoint) == true) {
1101  returnValue.setValue(_Character::toString(codePoint));
1102  } else {
1103  MINITSCRIPT_METHODUSAGE_COMPLAIN(getMethodName());
1104  }
1105  }
1106  };
1107  minitScript->registerMethod(new MethodStringFromCodePoint(minitScript));
1108  }
1109 }
#define MINITSCRIPT_METHODUSAGE_COMPLAIN(methodName)
Definition: MinitScript.h:59
Standard math functions.
Definition: Math.h:19
void pushByteArrayEntry(uint8_t value)
Push entry to byte array.
Definition: MinitScript.h:1809
void pushArrayEntry(const Variable &value)
Push entry to array.
Definition: MinitScript.h:1892
void setType(VariableType newType)
Set type.
Definition: MinitScript.h:1253
void setValue(const Variable &variable)
Set value from given variable into variable.
Definition: MinitScript.h:1618
void registerMethod(Method *method)
Register method.
MinitScript script string methods.
Definition: StringMethods.h:12
static const string toString(uint32_t character)
Generates a string from given character / code point.
Definition: Character.h:59
static bool is(const string &str)
Check if given string is a float string.
Definition: Float.cpp:26
static bool is(const string &str)
Check if given string is a integer string.
Definition: Integer.cpp:26
static const bool startsWith(const string &str, const string &prefix)
Checks if string starts with prefix.
static int64_t firstIndexOf(const string &str, const string &what, int64_t beginIndex=0, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
Finds first index of given string.
static const string toUpperCase(const string &str, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
Transform string to upper case.
static bool equalsIgnoreCase(const string &string1, const string &string2, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *string1Cache=nullptr, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *string2Cache=nullptr)
Checks if strings equal ignoring case.
static const string getCharAt(const string &str, int64_t index, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
Get UTF8 character at given index.
static uint32_t getCodePointAt(const string &str, int64_t index, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
Get UTF8 code point at given index.
static const string indent(const string &str, const string &with, int64_t count)
Indent a string.
static int64_t getLength(const string &str, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
Get UTF8 string length.
static const string padLeft(const string &str, const string &by, int64_t toLength, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
Pad a string left.
static const string toLowerCase(const string &str, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
Transform string to lower case.
static const bool endsWith(const string &str, const string &suffix)
Checks if string ends with suffix.
static int64_t indexOf(const string &str, const string &what, int64_t beginIndex=0, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
Finds first index of given string.
static const string trim(const string &str, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
Trim string.
static int64_t lastIndexOfChars(const string &str, const string &what, int64_t endIndex=string::npos, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *srcCache=nullptr, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *whatCache=nullptr)
Finds last index of characters provided within given string.
static const string replace(const string &str, const string &what, const string &by, int64_t beginIndex=0, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
Replace string with another string.
static const string regexReplace(const string &str, const string &pattern, const string &by)
Replace regex pattern with given string.
static bool regexSearch(const string &str, const string &pattern, smatch *matches=nullptr)
Do regex pattern search.
static const string substring(const string &str, int64_t beginIndex, int64_t endIndex=string::npos, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *srcCache=nullptr, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
Returns substring of given string from begin index to end index.
static int64_t lastIndexOf(const string &str, const string &what, int64_t endIndex=string::npos, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
Finds last index of given string.
static const string generate(const string &what, int64_t count=1)
Generate a string.
static bool regexMatch(const string &str, const string &pattern, smatch *matches=nullptr)
Check if pattern matches whole string.
static const string padRight(const string &str, const string &by, int64_t toLength, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *cache=nullptr)
Pad a string right.
static const vector< string > tokenize(const string &str, const string &delimiters, bool emptyTokens=false)
Tokenize.
static int64_t firstIndexOfChars(const string &str, const string &what, int64_t beginIndex=0, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *srcCache=nullptr, ::minitscript::utilities::UTF8CharacterIterator::UTF8PositionCache *whatCache=nullptr)
Finds first index of characters provided within given string.