-
Notifications
You must be signed in to change notification settings - Fork 1
/
HTVM.cpp
7334 lines (7244 loc) · 230 KB
/
HTVM.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
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <algorithm>
#include <cctype>
#include <chrono>
#include <cstdint>
#include <cstdlib>
#include <ctime>
#include <filesystem>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <regex>
#include <sstream>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <unordered_set>
#include <vector>
// Forward declare OneIndexedArray template
template <typename T>
class OneIndexedArray;
#define OneIndexedArray_DEFINED
// Helper function to set the internal array's size as a string
template <typename T>
void setInternalArraySize(T& element, size_t size) {
element = static_cast<T>(size);
}
// Specialization for std::string
template <>
void setInternalArraySize<std::string>(std::string& element, size_t size) {
element = std::to_string(size);
}
// One-indexed dynamic array class
template <typename T>
class OneIndexedArray {
private:
std::vector<T> internalArray;
public:
OneIndexedArray() {
internalArray.push_back(T{}); // Placeholder for element count
}
void add(const T& newElement) {
internalArray.push_back(newElement);
setInternalArraySize(internalArray[0], internalArray.size() - 1);
}
void setArray(const std::vector<T>& newArray) {
internalArray.resize(newArray.size() + 1);
std::copy(newArray.begin(), newArray.end(), internalArray.begin() + 1);
setInternalArraySize(internalArray[0], newArray.size());
}
T& operator[](size_t index) {
if (index >= internalArray.size()) {
internalArray.resize(index + 1);
setInternalArraySize(internalArray[0], internalArray.size() - 1);
}
return internalArray[index];
}
const T& operator[](size_t index) const {
if (index >= internalArray.size()) {
throw std::out_of_range("Index out of range");
}
return internalArray[index];
}
size_t size() const {
return static_cast<size_t>(internalArray.size() - 1);
}
void pop_back() {
if (size() > 0) {
internalArray.pop_back(); // Remove last element
setInternalArraySize(internalArray[0], internalArray.size() - 1); // Update size
}
}
};
// Function to split text into words based on a delimiter
std::vector<std::string> split(const std::string& text, const std::string& delimiter) {
std::vector<std::string> words;
std::istringstream stream(text);
std::string word;
while (std::getline(stream, word, delimiter[0])) { // assuming single character delimiter
words.push_back(word);
}
return words;
}
// Function to split text into a OneIndexedArray
OneIndexedArray<std::string> arrSplit(const std::string& text, const std::string& delimiter) {
OneIndexedArray<std::string> array;
std::vector<std::string> words = split(text, delimiter);
array.setArray(words);
return array;
}
// Convert std::string to int
int INT(const std::string& str) {
std::istringstream iss(str);
int value;
iss >> value;
return value;
}
// Convert various types to std::string
std::string STR(int value) {
return std::to_string(value);
}
// Convert various types to std::string
std::string STR(long long value) {
return std::to_string(value);
}
std::string STR(float value) {
return std::to_string(value);
}
std::string STR(double value) {
return std::to_string(value);
}
std::string STR(size_t value) {
return std::to_string(value);
}
std::string STR(bool value) {
return value ? "1" : "0";
}
// Function to find the position of needle in haystack (std::string overload)
int InStr(const std::string& haystack, const std::string& needle) {
size_t pos = haystack.find(needle);
return (pos != std::string::npos) ? static_cast<int>(pos) + 1 : 0;
}
// Function to escape special characters for regex
std::string escapeRegex(const std::string& str) {
static const std::regex specialChars{R"([-[\]{}()*+?.,\^$|#\s])"};
return std::regex_replace(str, specialChars, R"(\$&)");
}
// Function to split a string based on delimiters
std::vector<std::string> LoopParseFunc(const std::string& var, const std::string& delimiter1 = "", const std::string& delimiter2 = "") {
std::vector<std::string> items;
if (delimiter1.empty() && delimiter2.empty()) {
// If no delimiters are provided, return a list of characters
for (char c : var) {
items.push_back(std::string(1, c));
}
} else {
// Escape delimiters for regex
std::string escapedDelimiters = escapeRegex(delimiter1 + delimiter2);
// Construct the regular expression pattern for splitting the string
std::string pattern = "[" + escapedDelimiters + "]+";
std::regex regexPattern(pattern);
std::sregex_token_iterator iter(var.begin(), var.end(), regexPattern, -1);
std::sregex_token_iterator end;
while (iter != end) {
items.push_back(*iter++);
}
}
return items;
}
// Print function that converts all types to string if needed
template <typename T>
void print(const T& value) {
if constexpr (std::is_same_v<T, std::string>) {
std::cout << value << std::endl;
} else if constexpr (std::is_same_v<T, int>) {
std::cout << std::to_string(value) << std::endl;
} else if constexpr (std::is_same_v<T, float>) {
std::cout << std::to_string(value) << std::endl;
} else if constexpr (std::is_same_v<T, double>) {
std::cout << std::to_string(value) << std::endl;
} else if constexpr (std::is_same_v<T, size_t>) {
std::cout << std::to_string(value) << std::endl;
} else if constexpr (std::is_same_v<T, bool>) {
std::cout << (value ? "1" : "0") << std::endl;
}
#ifdef OneIndexedArray_DEFINED
else if constexpr (std::is_base_of_v<OneIndexedArray<std::string>, T>) {
for (size_t i = 1; i <= value.size(); ++i) {
std::cout << value[i] << std::endl;
}
} else if constexpr (std::is_base_of_v<OneIndexedArray<int>, T>) {
for (size_t i = 1; i <= value.size(); ++i) {
std::cout << std::to_string(value[i]) << std::endl;
}
} else if constexpr (std::is_base_of_v<OneIndexedArray<float>, T>) {
for (size_t i = 1; i <= value.size(); ++i) {
std::cout << std::to_string(value[i]) << std::endl;
}
} else if constexpr (std::is_base_of_v<OneIndexedArray<double>, T>) {
for (size_t i = 1; i <= value.size(); ++i) {
std::cout << std::to_string(value[i]) << std::endl;
}
}
#endif
else {
std::cout << "Unsupported type" << std::endl;
}
}
std::string FileRead(const std::string& path) {
std::ifstream file;
std::filesystem::path full_path;
// Check if the file path is an absolute path
if (std::filesystem::path(path).is_absolute()) {
full_path = path;
} else {
// If it's not a full path, prepend the current working directory
full_path = std::filesystem::current_path() / path;
}
// Open the file
file.open(full_path);
if (!file.is_open()) {
throw std::runtime_error("Error: Could not open the file.");
}
// Read the file content into a string
std::string content;
std::string line;
while (std::getline(file, line)) {
content += line + '\n';
}
file.close();
return content;
}
bool FileAppend(const std::string& content, const std::string& path) {
std::ofstream file;
// Open the file in append mode
file.open(path, std::ios::app);
if (!file.is_open()) {
std::cerr << "Error: Could not open the file for appending." << std::endl;
return false;
}
// Append the content to the file
file << content;
// Close the file
file.close();
return true;
}
bool FileDelete(const std::string& path) {
std::filesystem::path file_path(path);
// Check if the file exists
if (!std::filesystem::exists(file_path)) {
return false;
}
// Attempt to remove the file
if (!std::filesystem::remove(file_path)) {
return false;
}
return true;
}
size_t StrLen(const std::string& str) {
return str.length();
}
std::string SubStr(const std::string& str, int startPos, int length = -1) {
std::string result;
size_t strLen = str.size();
// Handle negative starting positions
if (startPos < 0) {
startPos += strLen;
if (startPos < 0) startPos = 0;
} else {
if (startPos > static_cast<int>(strLen)) return ""; // Starting position beyond string length
startPos -= 1; // Convert to 0-based index
}
// Handle length
if (length < 0) {
length = strLen - startPos; // Length to end of string
} else if (startPos + length > static_cast<int>(strLen)) {
length = strLen - startPos; // Adjust length to fit within the string
}
// Extract substring
result = str.substr(startPos, length);
return result;
}
std::string Trim(const std::string &inputString) {
if (inputString.empty()) return "";
size_t start = inputString.find_first_not_of(" \t\n\r\f\v");
size_t end = inputString.find_last_not_of(" \t\n\r\f\v");
return (start == std::string::npos) ? "" : inputString.substr(start, end - start + 1);
}
std::string StrReplace(const std::string &originalString, const std::string &find, const std::string &replaceWith) {
std::string result = originalString;
size_t pos = 0;
while ((pos = result.find(find, pos)) != std::string::npos) {
result.replace(pos, find.length(), replaceWith);
pos += replaceWith.length();
}
return result;
}
std::string StringTrimLeft(const std::string &input, int numChars) {
return (numChars <= input.length()) ? input.substr(numChars) : input;
}
std::string StringTrimRight(const std::string &input, int numChars) {
return (numChars <= input.length()) ? input.substr(0, input.length() - numChars) : input;
}
std::string StrLower(const std::string &string) {
std::string result = string;
std::transform(result.begin(), result.end(), result.begin(), ::tolower);
return result;
}
std::string StrSplit(const std::string &inputStr, const std::string &delimiter, int num) {
size_t start = 0, end = 0, count = 0;
while ((end = inputStr.find(delimiter, start)) != std::string::npos) {
if (++count == num) {
return inputStr.substr(start, end - start);
}
start = end + delimiter.length();
}
if (count + 1 == num) {
return inputStr.substr(start);
}
return "";
}
std::string Chr(int number) {
return (number >= 0 && number <= 0x10FFFF) ? std::string(1, static_cast<char>(number)) : "";
}
int Mod(int dividend, int divisor) {
return dividend % divisor;
}
// Platform-specific handling for command-line arguments
#ifdef _WIN32
#define ARGC __argc
#define ARGV __argv
#else
// On Linux/macOS, we need to declare these as extern variables.
extern char **environ; // Ensure the declaration of `environ`
int ARGC;
char** ARGV;
__attribute__((constructor)) void init_args(int argc, char* argv[], char* envp[]) {
ARGC = argc;
ARGV = argv;
}
#endif
// Function to get command-line parameters
std::string GetParams() {
std::vector<std::string> params;
for (int i = 1; i < ARGC; ++i) {
std::string arg = ARGV[i];
if (std::filesystem::exists(arg)) {
arg = std::filesystem::absolute(arg).string();
}
params.push_back(arg);
}
std::string result;
for (const auto& param : params) {
result += param + "\n";
}
return result;
}
// Store the start time as a global variable
std::chrono::time_point<std::chrono::steady_clock> programStartTime = std::chrono::steady_clock::now();
// Function to get built-in variables
std::string BuildInVars(const std::string& varName) {
auto now = std::chrono::system_clock::now();
std::time_t currentTime = std::chrono::system_clock::to_time_t(now);
std::tm* localTime = std::localtime(¤tTime);
std::ostringstream oss;
if (varName == "A_TickCount") {
// Calculate milliseconds since program start
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - programStartTime).count();
if (duration > std::numeric_limits<int>::max()) {
// Handle overflow case
return "Value too large";
} else {
return std::to_string(static_cast<int>(duration));
}
} else if (varName == "A_Now") {
oss << std::put_time(localTime, "%Y-%m-%d %H:%M:%S");
} else if (varName == "A_YYYY") {
oss << std::put_time(localTime, "%Y");
} else if (varName == "A_MM") {
oss << std::put_time(localTime, "%m");
} else if (varName == "A_DD") {
oss << std::put_time(localTime, "%d");
} else if (varName == "A_MMMM") {
oss << std::put_time(localTime, "%B");
} else if (varName == "A_MMM") {
oss << std::put_time(localTime, "%b");
} else if (varName == "A_DDDD") {
oss << std::put_time(localTime, "%A");
} else if (varName == "A_DDD") {
oss << std::put_time(localTime, "%a");
} else if (varName == "A_Hour") {
oss << std::put_time(localTime, "%H");
} else if (varName == "A_Min") {
oss << std::put_time(localTime, "%M");
} else if (varName == "A_Sec") {
oss << std::put_time(localTime, "%S");
} else if (varName == "A_Space") {
return " ";
} else if (varName == "A_Tab") {
return "\t";
} else {
return "";
}
return oss.str();
}
// Function to perform regex replacement
std::string RegExReplace(const std::string& inputStr, const std::string& regexPattern, const std::string& replacement) {
std::regex re(regexPattern, std::regex_constants::ECMAScript | std::regex_constants::multiline);
return std::regex_replace(inputStr, re, replacement);
}
// Function to perform regex matching and return the match position
int RegExMatch(const std::string& haystack, const std::string& needleRegEx, std::string* outputVar = nullptr, int startingPos = 0) {
if (haystack.empty() || needleRegEx.empty()) {
return 0;
}
std::regex re(needleRegEx);
std::smatch match;
if (std::regex_search(haystack.begin() + startingPos, haystack.end(), match, re)) {
if (outputVar != nullptr) {
*outputVar = match.str(0);
}
return match.position(0) + 1; // To make it 1-based index
}
return 0;
}
void ExitApp() {
std::exit(0);
}
// Helper function to trim whitespace from both ends of a string
std::string trim(const std::string& str) {
const std::string whitespace = " \t\n\r\f\v";
size_t start = str.find_first_not_of(whitespace);
if (start == std::string::npos) return "";
size_t end = str.find_last_not_of(whitespace);
return str.substr(start, end - start + 1);
}
// Helper function to convert string to lowercase
std::string toLower(const std::string& str) {
std::string lowerStr = str;
std::transform(lowerStr.begin(), lowerStr.end(), lowerStr.begin(), ::tolower);
return lowerStr;
}
// Function to sort case-insensitively but ensure lowercase items come last
bool customSortCompare(const std::string& a, const std::string& b) {
std::string lowerA = toLower(a);
std::string lowerB = toLower(b);
if (lowerA == lowerB) {
// If case-insensitive equivalent, ensure lowercase items come last
if (std::islower(a[0]) && std::isupper(b[0])) {
return false; // a should come after b
} else if (std::isupper(a[0]) && std::islower(b[0])) {
return true; // a should come before b
}
return a < b; // Otherwise, sort lexicographically
}
return lowerA < lowerB;
}
// Function to remove exact duplicates (case-sensitive)
std::vector<std::string> removeExactDuplicates(const std::vector<std::string>& items) {
std::unordered_set<std::string> seen;
std::vector<std::string> uniqueItems;
for (const auto& item : items) {
if (seen.find(item) == seen.end()) {
seen.insert(item);
uniqueItems.push_back(item);
}
}
return uniqueItems;
}
// Main sorting function
std::string SortLikeAHK(const std::string& input, const std::string& options) {
std::string delimiter = "\n";
bool caseInsensitive = options.find('C') != std::string::npos;
bool unique = options.find('U') != std::string::npos;
bool reverse = options.find('R') != std::string::npos;
bool random = options.find("Random") != std::string::npos;
bool numeric = options.find('N') != std::string::npos;
// Custom delimiter
if (options.find('D') != std::string::npos) {
size_t delimiterPos = options.find('D') + 1;
if (delimiterPos < options.size()) {
delimiter = options.substr(delimiterPos, 1);
}
}
// Split input by delimiter
std::vector<std::string> items;
std::stringstream ss(input);
std::string item;
while (std::getline(ss, item, delimiter[0])) {
item = trim(item); // Trim whitespace from each item
if (!item.empty()) {
items.push_back(item);
}
}
// Sort items
if (numeric) {
std::sort(items.begin(), items.end(), [](const std::string& a, const std::string& b) {
return std::stoi(a) < std::stoi(b);
});
} else {
std::sort(items.begin(), items.end(), customSortCompare);
}
// Remove exact duplicates if needed
if (unique) {
items = removeExactDuplicates(items);
}
// Apply reverse order if needed
if (reverse) {
std::reverse(items.begin(), items.end());
}
// Separate uppercase and lowercase items
std::vector<std::string> uppercaseItems;
std::vector<std::string> lowercaseItems;
for (const auto& item : items) {
if (std::isupper(item[0])) {
uppercaseItems.push_back(item);
} else {
lowercaseItems.push_back(item);
}
}
// Combine sorted uppercase items with sorted lowercase items
std::string result;
for (const auto& item : uppercaseItems) {
result += item;
result += delimiter;
}
for (const auto& item : lowercaseItems) {
result += item;
if (&item != &lowercaseItems.back()) {
result += delimiter;
}
}
// Remove trailing delimiter if necessary
if (!result.empty() && result.back() == delimiter[0]) {
result.pop_back();
}
return result;
}
// Wellcome the new revolution
// keyWordsCommands rules
// OUTVAR = the output variable
// INVAR = the input variable, like the one before the =
// INOUTVAR = both the output variable and the input variable
// lineTranspile = the first keyword will be replaced with the third section
// 'param123... = a parameter with ""
// param123... = a regular parameter, nothing much, just add as many as needed
std::string KeyWordsCommands(std::string theCodeCommands, std::string mode, std::string keyWordsCommands, std::string langToTranspileTo)
{
theCodeCommands = StrReplace ( theCodeCommands , "%" , "" ) ;
if (mode == "check")
{
std::vector<std::string> items1 = LoopParseFunc(keyWordsCommands, "|");
for (size_t A_Index1 = 1; A_Index1 < items1.size() + 1; A_Index1++)
{
std::string A_LoopField1 = items1[A_Index1 - 1];
std::vector<std::string> items2 = LoopParseFunc(A_LoopField1, ",");
for (size_t A_Index2 = 1; A_Index2 < items2.size() + 1; A_Index2++)
{
std::string A_LoopField2 = items2[A_Index2 - 1];
if (A_Index2 == 1)
{
if (SubStr (StrLower (theCodeCommands) , 1 , StrLen (A_LoopField2 + ", ")) == StrLower (A_LoopField2 + ", "))
{
//MsgBox, true
return "true";
}
}
if (A_Index2 == 1)
{
if (theCodeCommands == A_LoopField2)
{
//MsgBox, true
return "true";
}
}
}
}
//MsgBox, false
return "false";
}
int AIndex;
if (mode == "transpile")
{
int keyWordsCommandsNumLine = 1;
std::vector<std::string> items3 = LoopParseFunc(keyWordsCommands, "|");
for (size_t A_Index3 = 1; A_Index3 < items3.size() + 1; A_Index3++)
{
std::string A_LoopField3 = items3[A_Index3 - 1];
AIndex = A_Index3;
std::vector<std::string> items4 = LoopParseFunc(A_LoopField3, ",");
for (size_t A_Index4 = 1; A_Index4 < items4.size() + 1; A_Index4++)
{
std::string A_LoopField4 = items4[A_Index4 - 1];
if (A_Index4 == 1)
{
if (SubStr (StrLower (theCodeCommands) , 1 , StrLen (A_LoopField4 + ", ")) == StrLower (A_LoopField4 + ", "))
{
//MsgBox, true
keyWordsCommandsNumLine = AIndex;
break;
}
}
if (A_Index4 == 1)
{
//MsgBox, %theCodeCommands% = %A_LoopField4%
if (theCodeCommands == A_LoopField4)
{
//MsgBox, true
keyWordsCommandsNumLine = AIndex;
break;
}
}
}
}
std::string outConstuctTheOutFromTheCommands = "";
std::string outConstuctTheOutFromTheCommandsFucnName = "";
std::string outConstuctTheOutFromTheCommandsParams = "";
std::string outConstuctTheOutFromTheCommandsOutVar = "";
std::string outConstuctTheOutFromTheCommandsInVar = "";
int theCodeCommandNum = 1;
int outConstuctTheOutFromTheCommandsLineTranspile = 0;
std::string outConstuctTheOutFromTheCommandsLineTranspileText = "";
std::string semicolon = "";
if (langToTranspileTo!= "py")
{
semicolon = ";";
}
OneIndexedArray<std::string> theCodeCommand;
theCodeCommands = Trim ( theCodeCommands ) ;
std::vector<std::string> items5 = LoopParseFunc(theCodeCommands, ",");
for (size_t A_Index5 = 1; A_Index5 < items5.size() + 1; A_Index5++)
{
std::string A_LoopField5 = items5[A_Index5 - 1];
theCodeCommand.add(Trim(A_LoopField5));
//MsgBox, % A_LoopField5
}
std::vector<std::string> items6 = LoopParseFunc(keyWordsCommands, "|");
for (size_t A_Index6 = 1; A_Index6 < items6.size() + 1; A_Index6++)
{
std::string A_LoopField6 = items6[A_Index6 - 1];
if (keyWordsCommandsNumLine == A_Index6)
{
//MsgBox, % A_LoopField6
std::vector<std::string> items7 = LoopParseFunc(A_LoopField6, ",");
for (size_t A_Index7 = 1; A_Index7 < items7.size() + 1; A_Index7++)
{
std::string A_LoopField7 = items7[A_Index7 - 1];
if (A_Index7 == 1)
{
outConstuctTheOutFromTheCommandsFucnName = A_LoopField7;
}
else if (A_Index7 == 2)
{
//MsgBox, % A_LoopField7
if (A_LoopField7 == "lineTranspile")
{
outConstuctTheOutFromTheCommandsLineTranspile = 1;
}
if (A_LoopField7 == "OUTVAR")
{
outConstuctTheOutFromTheCommandsOutVar = theCodeCommand[theCodeCommandNum];
}
else if (A_LoopField7 == "INOUTVAR")
{
outConstuctTheOutFromTheCommandsOutVar = theCodeCommand[theCodeCommandNum];
outConstuctTheOutFromTheCommandsInVar = theCodeCommand[theCodeCommandNum];
}
else if (A_LoopField7 == "INVAR")
{
outConstuctTheOutFromTheCommandsInVar = theCodeCommand[theCodeCommandNum];
}
else
{
if (InStr (A_LoopField7 , Chr (39)))
{
outConstuctTheOutFromTheCommandsParams += Chr ( 34 ) + theCodeCommand[theCodeCommandNum] + Chr ( 34 ) + ", ";
}
else
{
outConstuctTheOutFromTheCommandsParams += theCodeCommand[theCodeCommandNum] + ", ";
}
}
}
else if (A_Index7 == 3)
{
if (outConstuctTheOutFromTheCommandsLineTranspile == 1)
{
outConstuctTheOutFromTheCommandsLineTranspileText = A_LoopField7;
}
if (A_LoopField7 == "INVAR")
{
outConstuctTheOutFromTheCommandsInVar = theCodeCommand[theCodeCommandNum];
}
else
{
if (InStr (A_LoopField7 , Chr (39)))
{
outConstuctTheOutFromTheCommandsParams += Chr ( 34 ) + theCodeCommand[theCodeCommandNum] + Chr ( 34 ) + ", ";
}
else
{
outConstuctTheOutFromTheCommandsParams += theCodeCommand[theCodeCommandNum] + ", ";
}
}
}
else
{
//MsgBox, % theCodeCommand[theCodeCommandNum]
if (InStr (A_LoopField7 , Chr (39)))
{
if (Trim (theCodeCommand[theCodeCommandNum])!= "")
{
outConstuctTheOutFromTheCommandsParams += Chr ( 34 ) + theCodeCommand[theCodeCommandNum] + Chr ( 34 ) + ", ";
}
}
else
{
if (Trim (theCodeCommand[theCodeCommandNum])!= "")
{
outConstuctTheOutFromTheCommandsParams += theCodeCommand[theCodeCommandNum] + ", ";
}
}
}
theCodeCommandNum++;
}
break;
}
}
outConstuctTheOutFromTheCommandsParams = StringTrimRight(outConstuctTheOutFromTheCommandsParams, 2);
if (outConstuctTheOutFromTheCommandsOutVar!= "")
{
if (outConstuctTheOutFromTheCommandsParams == "")
{
outConstuctTheOutFromTheCommands = outConstuctTheOutFromTheCommandsOutVar + " = " + outConstuctTheOutFromTheCommandsFucnName + "(" + outConstuctTheOutFromTheCommandsInVar + ")" + semicolon;
}
else
{
outConstuctTheOutFromTheCommands = outConstuctTheOutFromTheCommandsOutVar + " = " + outConstuctTheOutFromTheCommandsFucnName + "(" + outConstuctTheOutFromTheCommandsInVar + ", " + outConstuctTheOutFromTheCommandsParams + ")" + semicolon;
}
}
if (outConstuctTheOutFromTheCommandsOutVar == "")
{
if (outConstuctTheOutFromTheCommandsParams == "")
{
outConstuctTheOutFromTheCommands = outConstuctTheOutFromTheCommandsFucnName + "(" + outConstuctTheOutFromTheCommandsInVar + ")" + semicolon;
}
else
{
outConstuctTheOutFromTheCommands = outConstuctTheOutFromTheCommandsFucnName + "(" + outConstuctTheOutFromTheCommandsInVar + ", " + outConstuctTheOutFromTheCommandsParams + ")" + semicolon;
}
}
if (outConstuctTheOutFromTheCommandsLineTranspile == 1)
{
outConstuctTheOutFromTheCommands = outConstuctTheOutFromTheCommandsLineTranspileText;
}
outConstuctTheOutFromTheCommands = StrReplace ( outConstuctTheOutFromTheCommands , "(, " , "( " ) ;
outConstuctTheOutFromTheCommands = StrReplace ( outConstuctTheOutFromTheCommands , "(," , "(" ) ;
return outConstuctTheOutFromTheCommands;
}
return "false";
}
std::string ExtractDigits(std::string inputString)
{
std::string digits;
std::vector<std::string> items8 = LoopParseFunc(inputString);
for (size_t A_Index8 = 1; A_Index8 < items8.size() + 1; A_Index8++)
{
std::string A_LoopField8 = items8[A_Index8 - 1];
if (RegExMatch (A_LoopField8 , "\\d"))
{
digits += A_LoopField8;
}
}
return digits;
}
std::string convertJs_cpp_Normal(std::string theCode)
{
std::string out;
std::string indexName;
std::string indexEqual;
std::string indexMax;
std::vector<std::string> items9 = LoopParseFunc(theCode, " ");
for (size_t A_Index9 = 1; A_Index9 < items9.size() + 1; A_Index9++)
{
std::string A_LoopField9 = items9[A_Index9 - 1];
if (A_Index9 == 3)
{
indexName = StrReplace ( A_LoopField9 , ";" , "" ) ;
}
if (A_Index9 == 5)
{
indexEqual = StrReplace ( A_LoopField9 , ";" , "" ) ;
}
if (A_Index9 == 8)
{
indexMax = StrReplace ( A_LoopField9 , ";" , "" ) ;
}
}
indexName = StrReplace ( indexName , ":" , "" ) ;
indexEqual = StrReplace ( indexEqual , ":" , "" ) ;
indexMax = StrReplace ( indexMax , ":" , "" ) ;
out = "for (int " + indexName + " = " + indexEqual + "; " + indexName + " < " + indexMax + "; " + indexName + "++)";
return out;
}
std::string convertJs_py_Normal(std::string theCode)
{
std::string out;
std::string indexName;
std::string indexEqual;
std::string indexMax;
std::vector<std::string> items10 = LoopParseFunc(theCode, " ");
for (size_t A_Index10 = 1; A_Index10 < items10.size() + 1; A_Index10++)
{
std::string A_LoopField10 = items10[A_Index10 - 1];
if (A_Index10 == 3)
{
indexName = StrReplace ( A_LoopField10 , ";" , "" ) ;
}
if (A_Index10 == 5)
{
indexEqual = StrReplace ( A_LoopField10 , ";" , "" ) ;
}
if (A_Index10 == 8)
{
indexMax = StrReplace ( A_LoopField10 , ";" , "" ) ;
}
}
indexName = StrReplace ( indexName , ":" , "" ) ;
indexEqual = StrReplace ( indexEqual , ":" , "" ) ;
indexMax = StrReplace ( indexMax , ":" , "" ) ;
out = "for " + indexName + " in range(" + indexEqual + ", " + indexMax + "):";
return out;
}
std::string convertPy_cpp_Normal(std::string theCode)
{
std::string out;
std::string indexName;
std::string indexEqual;
std::string indexMax;
if (InStr (theCode , ","))
{
std::vector<std::string> items11 = LoopParseFunc(theCode, " ");
for (size_t A_Index11 = 1; A_Index11 < items11.size() + 1; A_Index11++)
{
std::string A_LoopField11 = items11[A_Index11 - 1];
if (A_Index11 == 2)
{
indexName = StrReplace ( A_LoopField11 , ";" , "" ) ;
}
if (A_Index11 == 4)
{
indexEqual = Trim ( StrReplace ( StrReplace ( StrReplace ( A_LoopField11 , ";" , "" ) , "range(" , "" ) , "," , "" ) ) ;
}
if (A_Index11 == 5)
{
indexMax = Trim ( StrReplace ( StrReplace ( StrReplace ( A_LoopField11 , ";" , "" ) , ")" , "" ) , "," , "" ) ) ;
}
}
indexName = StrReplace ( indexName , ":" , "" ) ;
indexEqual = StrReplace ( indexEqual , ":" , "" ) ;
indexMax = StrReplace ( indexMax , ":" , "" ) ;
out = "for (int " + indexName + " = " + indexEqual + "; " + indexName + " < " + indexMax + "; " + indexName + "++)";
return out;
}
else
{
std::vector<std::string> items12 = LoopParseFunc(theCode, " ");
for (size_t A_Index12 = 1; A_Index12 < items12.size() + 1; A_Index12++)
{
std::string A_LoopField12 = items12[A_Index12 - 1];
if (A_Index12 == 2)
{
indexName = StrReplace ( A_LoopField12 , ";" , "" ) ;
}
if (A_Index12 == 4)
{
indexEqual = "0";
indexMax = ExtractDigits ( StrReplace ( A_LoopField12 , ";" , "" ) ) ;
}
}
indexName = StrReplace ( indexName , ":" , "" ) ;
indexEqual = StrReplace ( indexEqual , ":" , "" ) ;
indexMax = StrReplace ( indexMax , ":" , "" ) ;
out = "for (int " + indexName + " = " + indexEqual + "; " + indexName + " < " + indexMax + "; " + indexName + "++)";
return out;
}
}
std::string convertPy_js_Normal(std::string theCode)
{
std::string out;
std::string indexName;
std::string indexEqual;
std::string indexMax;
if (InStr (theCode , ","))
{
std::vector<std::string> items13 = LoopParseFunc(theCode, " ");
for (size_t A_Index13 = 1; A_Index13 < items13.size() + 1; A_Index13++)
{
std::string A_LoopField13 = items13[A_Index13 - 1];
if (A_Index13 == 2)
{
indexName = StrReplace ( A_LoopField13 , ";" , "" ) ;
}
if (A_Index13 == 4)
{
indexEqual = Trim ( StrReplace ( StrReplace ( StrReplace ( A_LoopField13 , ";" , "" ) , "range(" , "" ) , "," , "" ) ) ;
}
if (A_Index13 == 5)
{
indexMax = Trim ( StrReplace ( StrReplace ( StrReplace ( A_LoopField13 , ";" , "" ) , ")" , "" ) , "," , "" ) ) ;
}
}
indexName = StrReplace ( indexName , ":" , "" ) ;
indexEqual = StrReplace ( indexEqual , ":" , "" ) ;
indexMax = StrReplace ( indexMax , ":" , "" ) ;
out = "for (let " + indexName + " = " + indexEqual + "; " + indexName + " < " + indexMax + "; " + indexName + "++)";
return out;
}
else
{
std::vector<std::string> items14 = LoopParseFunc(theCode, " ");
for (size_t A_Index14 = 1; A_Index14 < items14.size() + 1; A_Index14++)
{
std::string A_LoopField14 = items14[A_Index14 - 1];
if (A_Index14 == 2)
{
indexName = StrReplace ( A_LoopField14 , ";" , "" ) ;
}
if (A_Index14 == 4)
{