-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTLL_Lib.htll
More file actions
584 lines (462 loc) · 11.3 KB
/
HTLL_Lib.htll
File metadata and controls
584 lines (462 loc) · 11.3 KB
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
int rax_fake := 0
arr my_string
arr my_string2
arr InStr_string_test
int size_out := 0
; ------------------------------------------
; ------------------------------------------
; ------------------------------------------
arr func_arr
int countChars_counter := 0
arr StringTrimLeft_arr_help
int StrLower_val := 0
arr SubStr_arr_help
int i := 0
; Global variables for Trim logic
int trim_start_idx := 0
int trim_end_idx := 0
int trim_char := 0
int trim_len := 0
arr trim_buffer
arr InStr_string
int InStr_string_len := 0
; ------------------------------------------
func StrLen()
func_arr.size
return rax
funcend
func Chr(num)
return num
funcend
func StringTrimRight(count)
Loop, count
func_arr.pop
loopend
funcend
func countChars(one_char)
countChars_counter := 0
func_arr.size
Loop, rax
func_arr.index A_Index
rax_fake := rax
if (rax_fake = one_char)
countChars_counter++
endif
loopend
return countChars_counter
funcend
func StringTrimLeft(count)
StringTrimLeft_arr_help.clear
func_arr.size
Loop, rax
if (A_Index >= count)
func_arr.index A_Index
StringTrimLeft_arr_help.add rax
endif
loopend
func_arr.copy StringTrimLeft_arr_help
funcend
func StrLower()
func_arr.size
Loop, rax
func_arr.index A_Index
StrLower_val := rax
; Check if 'A' (65) <= val <= 'Z' (90)
if (StrLower_val >= 65)
if2 (StrLower_val <= 90)
StrLower_val += 32 ; Convert to lowercase
func_arr.set A_Index, StrLower_val
endif2
endif
loopend
funcend
func SubStr(start, len)
SubStr_arr_help.clear
func_arr.size
i := 0
Loop, rax
i++ ; 1 indexed i need
if (i >= start)
if2 (i <= len)
func_arr.index A_Index
SubStr_arr_help.add rax
endif2
endif
loopend
func_arr.copy SubStr_arr_help
funcend
func Trim()
; 1. Find Start Index (Skip leading whitespace)
trim_start_idx := 0
func_arr.size
Loop, rax
func_arr.index A_Index
trim_char := rax
; Check if whitespace (Space=32, Tab=9, LF=10, CR=13)
if (trim_char = 32)
trim_start_idx++
continue
endif
if (trim_char = 9)
trim_start_idx++
continue
endif
if (trim_char = 10)
trim_start_idx++
continue
endif
if (trim_char = 13)
trim_start_idx++
continue
endif
; If we hit a non-whitespace, stop scanning
break
loopend
; 2. Find End Index (Skip trailing whitespace)
func_arr.size
trim_end_idx := rax
trim_end_idx-- ; Convert to 0-based index for scanning backward
togo trim_scan_backward
if (trim_end_idx < trim_start_idx)
goto trim_scan_done ; String is empty or all whitespace
endif
func_arr.index trim_end_idx
trim_char := rax
if (trim_char = 32)
trim_end_idx--
goto trim_scan_backward
endif
if (trim_char = 9)
trim_end_idx--
goto trim_scan_backward
endif
if (trim_char = 10)
trim_end_idx--
goto trim_scan_backward
endif
if (trim_char = 13)
trim_end_idx--
goto trim_scan_backward
endif
; Found non-whitespace
goto trim_scan_done
togo trim_scan_done
; 3. Calculate Length and Extract
; Length = (End - Start) + 1
trim_len := trim_end_idx
trim_len -= trim_start_idx
trim_len++
; Use manual copy logic (essentially SubStr) to fill trim_buffer
trim_buffer.clear
if (trim_len > 0)
Loop, trim_len
; Calculate source index: start_idx + A_Index
int curr_idx := trim_start_idx
curr_idx += A_Index
func_arr.index curr_idx
trim_buffer.add rax
loopend
endif
; 4. Result back to func_arr
func_arr.copy trim_buffer
funcend
int Is2arr_equal_size1 := 0
int Is2arr_equal_temp := 0
int Is2arr_equal_count := 0
arr Is2arr_equal_ARG1
arr Is2arr_equal_ARG2
func Is2arr_equal()
Is2arr_equal_ARG1.size
Is2arr_equal_size1 := rax
Is2arr_equal_ARG2.size
rax_fake := rax
if (Is2arr_equal_size1 != rax_fake)
return 0
endif
rax_fake := rax
if (Is2arr_equal_size1 = rax_fake)
if (Is2arr_equal_size1 = 0)
return 1
endif2
endif
Is2arr_equal_temp := 0
Is2arr_equal_count := 0
Loop, Is2arr_equal_size1
Is2arr_equal_ARG1.index A_Index
Is2arr_equal_temp := rax
Is2arr_equal_ARG2.index A_Index
rax_fake := rax
if (Is2arr_equal_temp = rax_fake)
Is2arr_equal_count++
goto Is2arr_equal_else_simulate
endif
rax_fake := rax
if (Is2arr_equal_temp != rax_fake)
return 0
endif
togo Is2arr_equal_else_simulate
endloop
if (Is2arr_equal_count = Is2arr_equal_size1)
return 1
endif
return 0
funcend
arr InStr_temp
arr InStr_ARG1
int InStr_out_num := 0
func InStr()
InStr_temp.clear
InStr_string_len := 0
InStr_ARG1.copy func_arr
; InStr_string is the needle in the hay InStr_ARG1
InStr_string.size
InStr_string_len := rax
func_arr.size
Loop, rax
InStr_temp.clear
if (A_Index > 0)
func_arr.copy InStr_ARG1
StringTrimLeft(1)
InStr_ARG1.copy func_arr
InStr_ARG1.size
rax_fake := rax
if2 (rax_fake <= InStr_string_len)
pop r13
pop r12
return 0
endif2
func_arr.copy InStr_ARG1
SubStr(1, InStr_string_len)
InStr_temp.copy func_arr
Is2arr_equal_ARG1.copy InStr_temp
Is2arr_equal_ARG2.copy InStr_string
Is2arr_equal()
rax_fake := rax
if2 (rax_fake = 1)
InStr_out_num := A_Index
pop r13
pop r12
return InStr_out_num
endif2
goto else_InStr_func
endif
if (A_Index = 0)
func_arr.copy InStr_ARG1
SubStr(1, InStr_string_len)
InStr_temp.copy func_arr
Is2arr_equal_ARG1.copy InStr_temp
Is2arr_equal_ARG2.copy InStr_string
Is2arr_equal()
rax_fake := rax
if2 (rax_fake = 1)
InStr_out_num := A_Index
pop r13
pop r12
return InStr_out_num
endif2
endif
togo else_InStr_func
endloop
return 0
funcend
; --- Globals for the STR function ---
int STR_main_num := 0
arr STR_temp_buffer ; For holding the reversed digits
int quotient_counter := 0
int remainder_val := 0
func INT_To_STR()
; Handle the edge case of zero
if (STR_main_num = 0)
func_arr.clear
func_arr.add 48 ; Add ASCII for '0'
return
endif
STR_temp_buffer.clear
remainder_val := STR_main_num
; --- PHASE 1: Extraction Loop ---
togo str_extraction_loop
; This is our "Mod/Div Machine"
quotient_counter := 0
togo mod_div_machine_loop
if (remainder_val < 10)
goto mod_div_machine_done
endif
remainder_val -= 10
quotient_counter++
goto mod_div_machine_loop
togo mod_div_machine_done
; Now, remainder_val is the digit (0-9)
; and quotient_counter is the new number for the next iteration.
remainder_val += 48 ; Convert digit to ASCII
STR_temp_buffer.add remainder_val
remainder_val := quotient_counter
if (remainder_val > 0)
goto str_extraction_loop
endif
; --- PHASE 2: Reversal Loop ---
func_arr.clear
STR_temp_buffer.size
Loop, rax
; We need to index backwards. The last item is at index (size - 1).
; So, the index is (size - 1) - A_Index.
STR_temp_buffer.size
int current_idx := rax
current_idx--
current_idx -= A_Index
STR_temp_buffer.index current_idx
func_arr.add rax
loopend
funcend
arr StrSplit_haystack
arr StrSplit_needle
arr StrSplit_out_buffer
int StrSplit_int1 := 0
int StrSplit_int2 := 0
int StrSplit_int3 := 0
int StrSplit_int4 := 0
func StrSplit(num)
StrSplit_needle.size
StrSplit_int1 := rax
StrSplit_haystack.size
StrSplit_int3 := rax
if (num = 1)
func_arr.copy StrSplit_haystack
InStr_string.copy StrSplit_needle
InStr()
StrSplit_int2 := rax
func_arr.copy StrSplit_haystack
SubStr(1, StrSplit_int2)
StrSplit_out_buffer.copy func_arr
endif
if (num = 2)
func_arr.copy StrSplit_haystack
InStr_string.copy StrSplit_needle
InStr()
StrSplit_int2 := rax
StrSplit_int2 += StrSplit_int1
StrSplit_int2++
func_arr.copy StrSplit_haystack
SubStr(StrSplit_int2, StrSplit_int3)
StrSplit_out_buffer.copy func_arr
endif
if (num > 2)
print("StrSplit CANT HAVE MORE THEN 2 PLS FIX IT!!!")
print("StrSplit CANT HAVE MORE THEN 2 PLS FIX IT!!!")
print("StrSplit CANT HAVE MORE THEN 2 PLS FIX IT!!!")
endif
funcend
; ------------------------------------------
; ------------------------------------------
; ------------------------------------------
main
arradd my_string Hello Man
my_string2.add 10
my_string2.add 10
my_string2.add 65
my_string2.add 66
my_string2.add 67
my_string2.add 32
my_string2.add 32
my_string2.add 32
func_arr.copy my_string
StrLen()
size_out := rax
print("The Size is:")
print(size_out)
print("-----------------------------------------")
Chr(65)
print_rax_as_char
print("")
print("-----------------------------------------")
func_arr.copy my_string
StringTrimRight(2)
my_string.copy func_arr
my_string.size
Loop, rax
my_string.index A_Index
print_rax_as_char
loopend
print("")
print("-----------------------------------------")
func_arr.copy my_string
countChars('l')
print(rax)
print("-----------------------------------------")
func_arr.copy my_string
StringTrimLeft(2)
my_string.copy func_arr
my_string.size
Loop, rax
my_string.index A_Index
print_rax_as_char
loopend
print("")
print("-----------------------------------------")
func_arr.copy my_string
StrLower()
my_string.copy func_arr
my_string.size
Loop, rax
my_string.index A_Index
print_rax_as_char
loopend
print("")
print("-----------------------------------------")
func_arr.copy my_string
SubStr(3, 5)
my_string.copy func_arr
my_string.size
Loop, rax
my_string.index A_Index
print_rax_as_char
loopend
print("")
print("-----------------------------------------")
func_arr.copy my_string2
Trim()
my_string2.copy func_arr
my_string2.size
Loop, rax
my_string2.index A_Index
print_rax_as_char
loopend
print("")
print("-----------------------------------------")
arradd my_string2 Hello man234 how are doing man
arradd InStr_string_test how are
func_arr.copy my_string2
InStr_string.copy InStr_string_test
InStr()
print(rax)
print("")
print("-----------------------------------------")
STR_main_num := 5000
INT_To_STR() ; func_arr now contains ['1', '9', '9', '1']
; Print the result to prove it works
func_arr.size
Loop, rax
func_arr.index A_Index
print_rax_as_char
loopend
print("")
print("-----------------------------------------")
arr StrSplit_my_data
arr StrSplit_my_delimiter
arr StrSplit_out
arradd StrSplit_my_data if (var1 = 4)
arradd StrSplit_my_delimiter =
StrSplit_my_delimiter.add 32
StrSplit_haystack.copy StrSplit_my_data
StrSplit_needle.copy StrSplit_my_delimiter
StrSplit(1)
StrSplit_out.copy StrSplit_out_buffer
StrSplit_out.size
Loop, rax
StrSplit_out.index A_Index
print_rax_as_char
loopend
print("")
print("-----------------------------------------")
; ------------------------------------------
; print a new line at the end just in case
print("")