@ugo-studio/jspp 0.2.9 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/LICENSE +25 -25
  2. package/README.md +20 -12
  3. package/dist/analysis/scope.js +5 -3
  4. package/dist/analysis/typeAnalyzer.js +21 -25
  5. package/dist/cli/index.js +14 -4
  6. package/dist/cli/utils.js +61 -0
  7. package/dist/core/codegen/class-handlers.js +6 -6
  8. package/dist/core/codegen/control-flow-handlers.js +10 -9
  9. package/dist/core/codegen/declaration-handlers.js +10 -3
  10. package/dist/core/codegen/destructuring-handlers.js +9 -4
  11. package/dist/core/codegen/expression-handlers.js +40 -29
  12. package/dist/core/codegen/function-handlers.js +78 -12
  13. package/dist/core/codegen/helpers.js +91 -14
  14. package/dist/core/codegen/index.js +4 -2
  15. package/dist/core/codegen/statement-handlers.js +9 -7
  16. package/package.json +2 -2
  17. package/scripts/precompile-headers.ts +249 -50
  18. package/scripts/setup-compiler.ts +63 -63
  19. package/src/prelude/any_value.cpp +636 -0
  20. package/src/prelude/any_value.hpp +369 -362
  21. package/src/prelude/{exception_helpers.hpp → exception.cpp} +53 -53
  22. package/src/prelude/exception.hpp +27 -27
  23. package/src/prelude/iterator_instantiations.hpp +10 -0
  24. package/src/prelude/{index.hpp → jspp.hpp} +10 -16
  25. package/src/prelude/library/array.cpp +191 -0
  26. package/src/prelude/library/array.hpp +13 -186
  27. package/src/prelude/library/console.cpp +125 -0
  28. package/src/prelude/library/console.hpp +24 -112
  29. package/src/prelude/library/error.cpp +100 -0
  30. package/src/prelude/library/error.hpp +13 -113
  31. package/src/prelude/library/function.cpp +69 -0
  32. package/src/prelude/library/function.hpp +11 -10
  33. package/src/prelude/library/global.cpp +96 -0
  34. package/src/prelude/library/global.hpp +12 -28
  35. package/src/prelude/library/global_usings.hpp +15 -0
  36. package/src/prelude/library/math.cpp +258 -0
  37. package/src/prelude/library/math.hpp +26 -308
  38. package/src/prelude/library/object.cpp +379 -0
  39. package/src/prelude/library/object.hpp +14 -276
  40. package/src/prelude/library/performance.cpp +21 -0
  41. package/src/prelude/library/performance.hpp +5 -20
  42. package/src/prelude/library/process.cpp +38 -0
  43. package/src/prelude/library/process.hpp +11 -39
  44. package/src/prelude/library/promise.cpp +131 -0
  45. package/src/prelude/library/promise.hpp +12 -123
  46. package/src/prelude/library/symbol.cpp +56 -0
  47. package/src/prelude/library/symbol.hpp +11 -52
  48. package/src/prelude/library/timer.cpp +88 -0
  49. package/src/prelude/library/timer.hpp +16 -92
  50. package/src/prelude/runtime.cpp +19 -0
  51. package/src/prelude/types.hpp +184 -179
  52. package/src/prelude/utils/access.hpp +502 -411
  53. package/src/prelude/utils/assignment_operators.hpp +99 -99
  54. package/src/prelude/utils/log_any_value/array.hpp +61 -40
  55. package/src/prelude/utils/log_any_value/function.hpp +39 -39
  56. package/src/prelude/utils/log_any_value/object.hpp +60 -3
  57. package/src/prelude/utils/operators.hpp +351 -336
  58. package/src/prelude/utils/operators_primitive.hpp +336 -336
  59. package/src/prelude/utils/well_known_symbols.hpp +24 -24
  60. package/src/prelude/values/array.cpp +1399 -0
  61. package/src/prelude/values/array.hpp +4 -1
  62. package/src/prelude/values/async_iterator.cpp +251 -0
  63. package/src/prelude/values/async_iterator.hpp +111 -83
  64. package/src/prelude/values/function.cpp +262 -0
  65. package/src/prelude/values/function.hpp +62 -82
  66. package/src/prelude/values/iterator.cpp +309 -0
  67. package/src/prelude/values/iterator.hpp +33 -64
  68. package/src/prelude/values/number.cpp +176 -0
  69. package/src/prelude/values/object.cpp +159 -0
  70. package/src/prelude/values/object.hpp +4 -0
  71. package/src/prelude/values/promise.cpp +479 -0
  72. package/src/prelude/values/promise.hpp +79 -72
  73. package/src/prelude/values/prototypes/array.hpp +46 -1336
  74. package/src/prelude/values/prototypes/async_iterator.hpp +19 -61
  75. package/src/prelude/values/prototypes/function.hpp +7 -46
  76. package/src/prelude/values/prototypes/iterator.hpp +25 -201
  77. package/src/prelude/values/prototypes/number.hpp +23 -210
  78. package/src/prelude/values/prototypes/object.hpp +7 -23
  79. package/src/prelude/values/prototypes/promise.hpp +18 -196
  80. package/src/prelude/values/prototypes/string.hpp +39 -542
  81. package/src/prelude/values/prototypes/symbol.hpp +9 -70
  82. package/src/prelude/values/shape.hpp +52 -52
  83. package/src/prelude/values/string.cpp +485 -0
  84. package/src/prelude/values/string.hpp +25 -26
  85. package/src/prelude/values/symbol.cpp +89 -0
  86. package/src/prelude/values/symbol.hpp +101 -101
  87. package/src/prelude/any_value_access.hpp +0 -170
  88. package/src/prelude/any_value_defines.hpp +0 -190
  89. package/src/prelude/any_value_helpers.hpp +0 -374
  90. package/src/prelude/values/helpers/array.hpp +0 -209
  91. package/src/prelude/values/helpers/async_iterator.hpp +0 -275
  92. package/src/prelude/values/helpers/function.hpp +0 -109
  93. package/src/prelude/values/helpers/iterator.hpp +0 -145
  94. package/src/prelude/values/helpers/object.hpp +0 -104
  95. package/src/prelude/values/helpers/promise.hpp +0 -254
  96. package/src/prelude/values/helpers/string.hpp +0 -61
  97. package/src/prelude/values/helpers/symbol.hpp +0 -21
@@ -1,542 +1,39 @@
1
- #pragma once
2
-
3
- #include "types.hpp"
4
- #include "values/string.hpp" // Make sure this is included
5
- #include "any_value.hpp"
6
- #include "utils/operators.hpp"
7
- #include <optional>
8
- #include <string>
9
- #include <vector>
10
- #include <algorithm>
11
- #include <cctype>
12
-
13
- namespace jspp
14
- {
15
- namespace StringPrototypes
16
- {
17
- inline AnyValue &get_toString_fn()
18
- {
19
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
20
- { return AnyValue::make_string(thisVal.as_string()->value); },
21
- "toString");
22
- return fn;
23
- }
24
-
25
- inline AnyValue &get_iterator_fn()
26
- {
27
- static AnyValue fn = AnyValue::make_generator([](const AnyValue &thisVal, std::span<const AnyValue> _) -> AnyValue
28
- { return AnyValue::from_iterator(thisVal.as_string()->get_iterator()); },
29
- "Symbol.iterator");
30
- return fn;
31
- }
32
-
33
- inline AnyValue &get_length_desc()
34
- {
35
- static auto getter = [](const AnyValue &thisVal, std::span<const AnyValue>) -> AnyValue
36
- { return AnyValue::make_number(thisVal.as_string()->value.length()); };
37
- static auto setter = [](const AnyValue &thisVal, std::span<const AnyValue>) -> AnyValue
38
- { return Constants::UNDEFINED; };
39
- static AnyValue desc = AnyValue::make_accessor_descriptor(getter, setter, false, false);
40
- return desc;
41
- }
42
-
43
- inline AnyValue &get_charAt_fn()
44
- {
45
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
46
- {
47
- auto self = thisVal.as_string();
48
- double pos = args.empty() ? 0 : Operators_Private::ToNumber(args[0]);
49
- int index = static_cast<int>(pos);
50
- if (index < 0 || index >= self->value.length())
51
- {
52
- return AnyValue::make_string("");
53
- }
54
- return AnyValue::make_string(std::string(1, self->value[index])); },
55
- "charAt");
56
- return fn;
57
- }
58
-
59
- inline AnyValue &get_concat_fn()
60
- {
61
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
62
- {
63
- std::string result = thisVal.as_string()->value;
64
- for (const auto &arg : args)
65
- {
66
- result += arg.to_std_string();
67
- }
68
- return AnyValue::make_string(result); },
69
- "concat");
70
- return fn;
71
- }
72
-
73
- inline AnyValue &get_endsWith_fn()
74
- {
75
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
76
- {
77
- auto self = thisVal.as_string();
78
- if (args.empty())
79
- return Constants::FALSE;
80
- std::string search = args[0].to_std_string();
81
- size_t end_pos = (args.size() > 1 && !args[1].is_undefined()) ? static_cast<size_t>(Operators_Private::ToNumber(args[1])) : self->value.length();
82
-
83
- if (end_pos > self->value.length())
84
- end_pos = self->value.length();
85
- if (search.length() > end_pos)
86
- return Constants::FALSE;
87
-
88
- return AnyValue::make_boolean(self->value.substr(end_pos - search.length(), search.length()) == search); },
89
- "endsWith");
90
- return fn;
91
- }
92
-
93
- inline AnyValue &get_includes_fn()
94
- {
95
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
96
- {
97
- auto self = thisVal.as_string();
98
- if (args.empty())
99
- return Constants::FALSE;
100
- std::string search = args[0].to_std_string();
101
- size_t pos = (args.size() > 1) ? static_cast<size_t>(Operators_Private::ToNumber(args[1])) : 0;
102
-
103
- return AnyValue::make_boolean(self->value.find(search, pos) != std::string::npos); },
104
- "includes");
105
- return fn;
106
- }
107
-
108
- inline AnyValue &get_indexOf_fn()
109
- {
110
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
111
- {
112
- auto self = thisVal.as_string();
113
- if (args.empty())
114
- return AnyValue::make_number(-1);
115
- std::string search = args[0].to_std_string();
116
- size_t pos = (args.size() > 1) ? static_cast<size_t>(Operators_Private::ToNumber(args[1])) : 0;
117
- size_t result = self->value.find(search, pos);
118
- return result == std::string::npos ? AnyValue::make_number(-1) : AnyValue::make_number(result); },
119
- "indexOf");
120
- return fn;
121
- }
122
-
123
- inline AnyValue &get_lastIndexOf_fn()
124
- {
125
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
126
- {
127
- auto self = thisVal.as_string();
128
- if (args.empty())
129
- return AnyValue::make_number(-1);
130
- std::string search = args[0].to_std_string();
131
- size_t pos = (args.size() > 1 && !args[1].is_undefined()) ? static_cast<size_t>(Operators_Private::ToNumber(args[1])) : std::string::npos;
132
- size_t result = self->value.rfind(search, pos);
133
- return result == std::string::npos ? AnyValue::make_number(-1) : AnyValue::make_number(result); },
134
- "lastIndexOf");
135
- return fn;
136
- }
137
-
138
- inline AnyValue &get_padEnd_fn()
139
- {
140
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
141
- {
142
- auto self = thisVal.as_string();
143
- size_t target_length = args.empty() ? 0 : static_cast<size_t>(Operators_Private::ToNumber(args[0]));
144
- if (self->value.length() >= target_length)
145
- return AnyValue::make_string(self->value);
146
- std::string pad_string = (args.size() > 1 && !args[1].is_undefined() && !args[1].to_std_string().empty()) ? args[1].to_std_string() : " ";
147
- std::string result = self->value;
148
- while (result.length() < target_length)
149
- {
150
- result += pad_string;
151
- }
152
- return AnyValue::make_string(result.substr(0, target_length)); },
153
- "padEnd");
154
- return fn;
155
- }
156
-
157
- inline AnyValue &get_padStart_fn()
158
- {
159
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
160
- {
161
- auto self = thisVal.as_string();
162
- size_t target_length = args.empty() ? 0 : static_cast<size_t>(Operators_Private::ToNumber(args[0]));
163
- if (self->value.length() >= target_length)
164
- return AnyValue::make_string(self->value);
165
- std::string pad_string = (args.size() > 1 && !args[1].is_undefined() && !args[1].to_std_string().empty()) ? args[1].to_std_string() : " ";
166
- std::string padding;
167
- while (padding.length() < target_length - self->value.length())
168
- {
169
- padding += pad_string;
170
- }
171
- return AnyValue::make_string(padding.substr(0, target_length - self->value.length()) + self->value); },
172
- "padStart");
173
- return fn;
174
- }
175
-
176
- inline AnyValue &get_repeat_fn()
177
- {
178
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
179
- {
180
- auto self = thisVal.as_string();
181
- double count = args.empty() ? 0 : Operators_Private::ToNumber(args[0]);
182
- if (count < 0)
183
- {
184
- // In a real implementation, this should throw a RangeError.
185
- return AnyValue::make_string("");
186
- }
187
- std::string result = "";
188
- for (int i = 0; i < count; ++i)
189
- {
190
- result += self->value;
191
- }
192
- return AnyValue::make_string(result); },
193
- "repeat");
194
- return fn;
195
- }
196
-
197
- inline AnyValue &get_replace_fn()
198
- {
199
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
200
- {
201
- auto self = thisVal.as_string();
202
- if (args.size() < 2)
203
- return AnyValue::make_string(self->value);
204
- std::string search = args[0].to_std_string();
205
- std::string replacement = args[1].to_std_string();
206
- std::string result = self->value;
207
- size_t pos = result.find(search);
208
- if (pos != std::string::npos)
209
- {
210
- result.replace(pos, search.length(), replacement);
211
- }
212
- return AnyValue::make_string(result); },
213
- "replace");
214
- return fn;
215
- }
216
-
217
- inline AnyValue &get_replaceAll_fn()
218
- {
219
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
220
- {
221
- auto self = thisVal.as_string();
222
- if (args.size() < 2)
223
- return AnyValue::make_string(self->value);
224
- std::string search = args[0].to_std_string();
225
- if (search.empty())
226
- return AnyValue::make_string(self->value);
227
- std::string replacement = args[1].to_std_string();
228
- std::string result = self->value;
229
- size_t pos = result.find(search);
230
- while (pos != std::string::npos)
231
- {
232
- result.replace(pos, search.length(), replacement);
233
- pos = result.find(search, pos + replacement.length());
234
- }
235
- return AnyValue::make_string(result); },
236
- "replaceAll");
237
- return fn;
238
- }
239
-
240
- inline AnyValue &get_slice_fn()
241
- {
242
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
243
- {
244
- auto self = thisVal.as_string();
245
- int len = self->value.length();
246
- int start = args.empty() ? 0 : Operators_Private::ToInt32(args[0]);
247
- int end = (args.size() < 2 || args[1].is_undefined()) ? len : Operators_Private::ToInt32(args[1]);
248
-
249
- if (start < 0)
250
- start += len;
251
- if (end < 0)
252
- end += len;
253
-
254
- start = std::max(0, std::min(len, start));
255
- end = std::max(0, std::min(len, end));
256
-
257
- if (start >= end)
258
- return AnyValue::make_string("");
259
- return AnyValue::make_string(self->value.substr(start, end - start)); },
260
- "slice");
261
- return fn;
262
- }
263
-
264
- inline AnyValue &get_split_fn()
265
- {
266
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
267
- {
268
- auto self = thisVal.as_string();
269
- std::string separator = (args.empty() || args[0].is_undefined()) ? "" : args[0].to_std_string();
270
- std::vector<jspp::AnyValue> result_vec;
271
-
272
- if (separator.empty())
273
- {
274
- for (char c : (self->value))
275
- {
276
- result_vec.push_back(AnyValue::make_string(std::string(1, c)));
277
- }
278
- }
279
- else
280
- {
281
- std::string temp = (self->value);
282
- size_t pos = 0;
283
- while ((pos = temp.find(separator)) != std::string::npos)
284
- {
285
- result_vec.push_back(AnyValue::make_string(temp.substr(0, pos)));
286
- temp.erase(0, pos + separator.length());
287
- }
288
- result_vec.push_back(AnyValue::make_string(temp));
289
- }
290
- return AnyValue::make_array(std::move(result_vec)); },
291
- "split");
292
- return fn;
293
- }
294
-
295
- inline AnyValue &get_startsWith_fn()
296
- {
297
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
298
- {
299
- auto self = thisVal.as_string();
300
- if (args.empty())
301
- return Constants::FALSE;
302
- std::string search = args[0].to_std_string();
303
- size_t pos = (args.size() > 1) ? static_cast<size_t>(Operators_Private::ToNumber(args[1])) : 0;
304
- if (pos > self->value.length())
305
- pos = self->value.length();
306
-
307
- return AnyValue::make_boolean(self->value.rfind(search, pos) == pos); },
308
- "startsWith");
309
- return fn;
310
- }
311
-
312
- inline AnyValue &get_substring_fn()
313
- {
314
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
315
- {
316
- auto self = thisVal.as_string();
317
- int len = self->value.length();
318
- int start = args.empty() ? 0 : Operators_Private::ToInt32(args[0]);
319
- int end = (args.size() < 2 || args[1].is_undefined()) ? len : Operators_Private::ToInt32(args[1]);
320
-
321
- start = std::max(0, start);
322
- end = std::max(0, end);
323
-
324
- if (start > end)
325
- std::swap(start, end);
326
-
327
- start = std::min(len, start);
328
- end = std::min(len, end);
329
-
330
- return AnyValue::make_string(self->value.substr(start, end - start)); },
331
- "substring");
332
- return fn;
333
- }
334
-
335
- inline AnyValue &get_toLowerCase_fn()
336
- {
337
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
338
- {
339
- std::string result = thisVal.as_string()->value;
340
- std::transform(result.begin(), result.end(), result.begin(),
341
- [](unsigned char c)
342
- { return std::tolower(c); });
343
- return AnyValue::make_string(result); },
344
- "toLowerCase");
345
- return fn;
346
- }
347
-
348
- inline AnyValue &get_toUpperCase_fn()
349
- {
350
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
351
- {
352
- std::string result = thisVal.as_string()->value;
353
- std::transform(result.begin(), result.end(), result.begin(),
354
- [](unsigned char c)
355
- { return std::toupper(c); });
356
- return AnyValue::make_string(result); },
357
- "toUpperCase");
358
- return fn;
359
- }
360
-
361
- inline AnyValue &get_trim_fn()
362
- {
363
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
364
- {
365
- const char *whitespace = " \t\n\r\f\v";
366
- std::string result = thisVal.as_string()->value;
367
- result.erase(0, result.find_first_not_of(whitespace));
368
- result.erase(result.find_last_not_of(whitespace) + 1);
369
- return AnyValue::make_string(result); },
370
- "trim");
371
- return fn;
372
- }
373
-
374
- inline AnyValue &get_trimEnd_fn()
375
- {
376
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
377
- {
378
- const char *whitespace = " \t\n\r\f\v";
379
- std::string result = thisVal.as_string()->value;
380
- result.erase(result.find_last_not_of(whitespace) + 1);
381
- return AnyValue::make_string(result); },
382
- "trimEnd");
383
- return fn;
384
- }
385
-
386
- inline AnyValue &get_trimStart_fn()
387
- {
388
- static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
389
- {
390
- const char *whitespace = " \t\n\r\f\v";
391
- std::string result = thisVal.as_string()->value;
392
- result.erase(0, result.find_first_not_of(whitespace));
393
- return AnyValue::make_string(result); },
394
- "trimStart");
395
- return fn;
396
- }
397
-
398
- // This function retrieves a prototype method for a given string instance.
399
- inline std::optional<AnyValue> get(const std::string &key)
400
- {
401
- // --- toString() & valueOf() ---
402
- if (key == "toString" || key == "valueOf" || key == WellKnownSymbols::toStringTag->key)
403
- {
404
- return get_toString_fn();
405
- }
406
-
407
- // --- [Symbol.iterator]() method ---
408
- if (key == WellKnownSymbols::iterator->key)
409
- {
410
- return get_iterator_fn();
411
- }
412
-
413
- // --- length property ---
414
- if (key == "length")
415
- {
416
- return get_length_desc();
417
- }
418
-
419
- // --- charAt(pos) ---
420
- if (key == "charAt")
421
- {
422
- return get_charAt_fn();
423
- }
424
-
425
- // --- concat(str1, str2, ...) ---
426
- if (key == "concat")
427
- {
428
- return get_concat_fn();
429
- }
430
-
431
- // --- endsWith(searchString, endPosition) ---
432
- if (key == "endsWith")
433
- {
434
- return get_endsWith_fn();
435
- }
436
-
437
- // --- includes(searchString, position) ---
438
- if (key == "includes")
439
- {
440
- return get_includes_fn();
441
- }
442
-
443
- // --- indexOf(searchString, position) ---
444
- if (key == "indexOf")
445
- {
446
- return get_indexOf_fn();
447
- }
448
-
449
- // --- lastIndexOf(searchString, position) ---
450
- if (key == "lastIndexOf")
451
- {
452
- return get_lastIndexOf_fn();
453
- }
454
-
455
- // --- padEnd(targetLength, padString) ---
456
- if (key == "padEnd")
457
- {
458
- return get_padEnd_fn();
459
- }
460
-
461
- // --- padStart(targetLength, padString) ---
462
- if (key == "padStart")
463
- {
464
- return get_padStart_fn();
465
- }
466
-
467
- // --- repeat(count) ---
468
- if (key == "repeat")
469
- {
470
- return get_repeat_fn();
471
- }
472
-
473
- // --- replace(substr, newSubstr) ---
474
- if (key == "replace")
475
- {
476
- return get_replace_fn();
477
- }
478
-
479
- // --- replaceAll(substr, newSubstr) ---
480
- if (key == "replaceAll")
481
- {
482
- return get_replaceAll_fn();
483
- }
484
-
485
- // --- slice(beginIndex, endIndex) ---
486
- if (key == "slice")
487
- {
488
- return get_slice_fn();
489
- }
490
-
491
- // --- split(separator) ---
492
- if (key == "split")
493
- {
494
- return get_split_fn();
495
- }
496
-
497
- // --- startsWith(searchString, position) ---
498
- if (key == "startsWith")
499
- {
500
- return get_startsWith_fn();
501
- }
502
-
503
- // --- substring(indexStart, indexEnd) ---
504
- if (key == "substring")
505
- {
506
- return get_substring_fn();
507
- }
508
-
509
- // --- toLowerCase() ---
510
- if (key == "toLowerCase")
511
- {
512
- return get_toLowerCase_fn();
513
- }
514
-
515
- // --- toUpperCase() ---
516
- if (key == "toUpperCase")
517
- {
518
- return get_toUpperCase_fn();
519
- }
520
-
521
- // --- trim() ---
522
- if (key == "trim")
523
- {
524
- return get_trim_fn();
525
- }
526
-
527
- // --- trimEnd() ---
528
- if (key == "trimEnd")
529
- {
530
- return get_trimEnd_fn();
531
- }
532
-
533
- // --- trimStart() ---
534
- if (key == "trimStart")
535
- {
536
- return get_trimStart_fn();
537
- }
538
-
539
- return std::nullopt;
540
- }
541
- }
542
- }
1
+ #pragma once
2
+
3
+ #include "types.hpp"
4
+ #include <optional>
5
+
6
+ namespace jspp
7
+ {
8
+ class AnyValue;
9
+
10
+ namespace StringPrototypes
11
+ {
12
+ AnyValue &get_toString_fn();
13
+ AnyValue &get_iterator_fn();
14
+ AnyValue &get_length_desc();
15
+ AnyValue &get_charAt_fn();
16
+ AnyValue &get_concat_fn();
17
+ AnyValue &get_endsWith_fn();
18
+ AnyValue &get_includes_fn();
19
+ AnyValue &get_indexOf_fn();
20
+ AnyValue &get_lastIndexOf_fn();
21
+ AnyValue &get_padEnd_fn();
22
+ AnyValue &get_padStart_fn();
23
+ AnyValue &get_repeat_fn();
24
+ AnyValue &get_replace_fn();
25
+ AnyValue &get_replaceAll_fn();
26
+ AnyValue &get_slice_fn();
27
+ AnyValue &get_split_fn();
28
+ AnyValue &get_startsWith_fn();
29
+ AnyValue &get_substring_fn();
30
+ AnyValue &get_toLowerCase_fn();
31
+ AnyValue &get_toUpperCase_fn();
32
+ AnyValue &get_trim_fn();
33
+ AnyValue &get_trimEnd_fn();
34
+ AnyValue &get_trimStart_fn();
35
+
36
+ std::optional<AnyValue> get(const std::string &key);
37
+ std::optional<AnyValue> get(const AnyValue &key);
38
+ }
39
+ }