-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathObject.String.ahk
599 lines (511 loc) · 32 KB
/
Object.String.ahk
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
stringCaseSense, on ; on 대소문자 구분 / off 구분안함
object.base.length := "string_length" ; The length of the string
object.base.replace := "string_replace" ; Replace string (replace string, replace string)
object.base.isExist := "string_isExist" ; The existence of the string - bool
object.base.indexOf := "string_indexOf" ; The first position (string, offset = 0) of the string (first occurrence)
object.base.lastIndexOf := "string_lastIndexOf" ; If the string is the first (last) position (string, offset = 0)
object.base.trim := "string_trim" ; Remove leading and trailing spaces in string
object.base.trimHead := "string_trimHead" ; Remove leading blanks in string
object.base.trimTail := "string_trimTail" ; Remove trailing blanks in string
object.base.getUpsideDown := "string_getUpsideDown" ; String upside down
object.base.getContentBetween := "string_getContentBetween" ; Returns the string between two strings (wrapped string, wrapped string)
object.base.lineCommentToBlockComment := "string_lineCommentToBlockComment" ; Single-line comment [-] to block comment [/ ** /]
object.base.isWhiteSpace := "string_isWhiteSpace" ; Check whether the syllable is a space [space, tab, enter] - bool (false if it is not a syllable and spaces are ignored)
object.base.getSeparateWord := "string_getSeparateWord" ; Split by whitespace to return a separate word for that index. The first word index is 0.
object.base.getLastWord := "string_getLastWord" ; 공백을 기준으로 split 하여 마지막 어절을 반환한다.
object.base.removeLeft := "string_removeLeft" ; 왼쪽 음절 제거
object.base.removeRight := "string_removeRight" ; 오른쪽 음절 제거
object.base.getLastSplitWord := "string_getLastSplitWord" ; split 하여 마지막 어절을 반환한다.
object.base.substring := "string_substring" ; substring. 최초인덱스는 0 (시작위치, 길이)
object.base.removeAHKLineComment := "string_removeAHKLineComment" ; 오토핫키 한줄코멘트 제거
object.base.removeInnerQuotation := "string_removeInnerQuotation" ; 따옴표 안의 내용 제거 (동일한 행 안에서만 적용)
object.base.getLastLineContent := "string_getLastLineContent" ; 마지막 줄의 내용
object.base.toLowerCase := "string_toLowerCase" ; 소문자로 변환
object.base.toUpperCase := "string_toUpperCase" ; 대문자로 변환
object.base.isUpperCase := "string_isUpperCase" ; 대문자인지 확인. 음절만 체크.
object.base.isLowerCase := "string_isLowerCase" ; 소문자인지 확인. 음절만 체크.
object.base.isAlphabet := "string_isAlphabet" ; 알파벳인지 확인. 음절만 체크.
object.base.isNumber := "string_isNumber" ; 숫자인지 확인. 음절만 체크.
object.base.removeTag := "string_removeTag" ; 테그 제거 (스크립트도 제거)
object.base.underbarToCamel := "string_underbarToCamel" ; 언더바형식 문자열을 카멜 형식으로 변환
object.base.camelToUnderbar := "string_camelToUnderbar" ; 카멜형식 문자열을 언더바 형식으로 변환
object.base.split := "string_split" ; Array split(deliminator)
object.base.getPostPosition := "string_getPostPosition"
object.base.getPreLetter := "string_getPreLetter"
object.base.isVarExist := "string_isVarExist"
object.base.getPostLetter := "string_getPostLetter"
object.base.isVarLetter := "string_isVarLetter"
object.base.getPosition := "string_getPosition"
string_length(this){
return strLen(this)
}
string_replace(this, old, new){
StringReplace, result, this, %old%, %new%, all
return result
}
string_isExist(this, needle){
IfInString, this, %needle%
{
return true
}
else
{
return false
}
}
string_indexOf(this, needle, offset = 0){
position := -1
StringGetPos, position, this, %needle%, L1, offset
return position
}
string_lastIndexOf(this, needle, offset = 0){
position := -1
StringGetPos, position, this, %needle%, R1, offset
return position
}
string_trimHead(this){
content := this
new_content := ""
is_trimming := false
loop, parse, content
{
if( a_index == 1 && (a_loopfield == " " || a_loopfield == a_tab || a_loopfield == "`n" || a_loopfield == "`r" || a_loopfield == "`r`n" || a_loopfield == "`n`r") )
{
is_trimming := true
}
else if(is_trimming == true && (a_loopfield == " " || a_loopfield == a_tab || a_loopfield == "`n" || a_loopfield == "`r" || a_loopfield == "`r`n" || a_loopfield == "`n`r"))
{
is_trimming := true
}
else
{
is_trimming := false
}
if(!is_trimming)
{
new_content .= a_loopfield
}
}
return new_content
}
string_getUpsideDown(this){
content := this
StringSplit, target_array, content
upsideDown := ""
loop, %target_array0%
{
new_index := target_array0 - a_index + 1
upsideDown .= target_array%new_index%
}
return upsideDown
}
string_trim(this){
this := this.trimHead()
this := this.getUpsideDown()
this := this.trimHead()
this := this.getUpsideDown()
return this
}
string_trimTail(this){
this := this.getUpsideDown()
this := this.trimHead()
this := this.getUpsideDown()
return this
}
string_getContentBetween(this, between_start, between_end){
content := this
between_content := ""
is_in_between := false
if((between_start != "" && this.indexOf(between_start) == -1) || (between_end != "" && this.indexOf(between_end) == -1)){
return ""
}
start_position := this.indexOf(between_start) + StrLen(between_start) + 1
end_position := this.indexOf(between_end, start_position - 1)
if(between_start == "") ;찾을 시작 문자열이 공백이면 처음부터
{
start_position := "1"
}
if(between_end == "") ;찾을 끝 문자열이 공백이면 마지막까지
{
end_position := StrLen(content)
}
if(start_position == -1 || end_position == -1)
{
return ""
}
length := end_position - start_position + 1
return SubStr(content, start_position, length)
}
string_lineCommentToBlockComment(this){
if(this.isExist("--") && !this.isExist("!--"))
{
return this.replace("--", "/*") . " */"
}
else
{
return this
}
}
string_getSeparateWord(this, index){ ; Split by whitespace to return a separate word for that index. The first word index is 0.
this := this.trim()
in_white_space := false
current_separate_word := ""
separate_word_count := "0"
loop, parse, this,
{
test1 := a_index
if(a_loopfield.isWhiteSpace() && in_white_space == false) ;공백시작
{
in_white_space := true
separate_word_count ++
if(index == separate_word_count - 1)
{
return current_separate_word
}
else
{
current_separate_word := ""
}
}
else if(a_loopfield.isWhiteSpace() == false && a_index != this.length()) ;내용부분(마지막 제외)
{
in_white_space := false
current_separate_word .= a_loopfield
}
else if(a_index == this.length()) ;마지막
{
separate_word_count++
current_separate_word .= a_loopfield
if(index == separate_word_count - 1)
{
return current_separate_word
}
}
}
return ""
}
string_getLastWord(this){ ; It returns the last word by splitting it with a space and "(".
new_content := this.getUpsideDown().trim()
last_word := ""
loop, parse, new_content,
{
if(!a_loopfield.isWhiteSpace() && a_loopfield != "("){
last_word .= a_loopfield
}else{
return last_word.getUpsideDown()
}
}
return last_word.getUpsideDown()
}
string_getLastSplitWord(this, deliminator){ ; Split to the syllable and return the last word.
new_content := this.getUpsideDown().trim()
last_word := ""
loop, parse, new_content,
{
if(a_loopfield != deliminator){
last_word .= a_loopfield
}else{
return last_word.getUpsideDown()
}
}
return last_word.getUpsideDown()
}
string_isWhiteSpace(this){
if(this == a_space || this == a_tab || this == "`n" || this == "`r" || this == "`n`r")
{
return true
}
return false
}
string_substring(this, index, length){
content := this
return substr(content, index + 1, length)
}
string_removeAHKLineComment(this){
content := this
new_content := ""
loop, parse, content, `n
{
current_line := a_loopfield
sleep, 1
// 주석 제거
if(current_line.isExist(";"))
{
current_line := current_line.substring(0, current_line.indexOf(";"))
}
if(new_content != "")
new_content .= "`n"
new_content .= current_line
}
return new_content
}
string_removeInnerQuotation(this){
content := this
new_content := ""
q := """"
is_inner_q := false
loop, parse, content,
{
if(a_loopfield == q)
{
if(is_inner_q == false)
{
is_inner_q := true
}
else
{
is_inner_q := false
}
new_content .= a_loopfield
}
else if(a_loopfield == "`n")
{
is_inner_q := false
new_content .= a_loopfield
}
else
{
if(is_inner_q == false)
{
new_content .= a_loopfield
}
}
}
return new_content
}
string_toLowerCase(this){
stringLower, lower, this
return lower
}
string_toUpperCase(this){
stringUpper, upper, this
return upper
}
string_split(this, deliminator){
content := this
result_array := new Array()
StringSplit, split_array, content, %deliminator%,
loop % split_array0
{
current := split_array%a_index%
result_array.add(current)
}
return result_array
}
string_getLastLineContent(this){
loop, parse, this, `n
{
current_line := a_loopfield
}
return current_line
}
string_isUpperCase(this){
if(this.length() != "1"){
return false
}
if(asc(this) >= 65 && asc(this) <= 90){
return true
}else{
return false
}
}
string_isLowerCase(this){
if(this.length() != "1"){
return false
}
if(asc(this) >= 97 && asc(this) <= 122){
return true
}else{
return false
}
}
string_isAlphabet(this){
if(this.length() != "1"){
return false
}
if(this.isUpperCase(this) || this.isLowerCase(this)){
return true
}else{
return false
}
}
string_isNumber(this){
if(this.length() != "1"){
return false
}
if(asc(this) >= 48 && asc(this) <= 57){
return true
}else{
return false
}
}
string_removeTag(this){
content := this
tag_array := new Array()
tag_array.add("p")
tag_array.add("br")
tag_array.add("div")
tag_array.add("span")
tag_array.add("img")
tag_array.add("a")
tag_array.add("strong")
tag_array.add("b")
tag_array.add("font")
tag_array.add("table")
tag_array.add("tbody")
tag_array.add("tr")
tag_array.add("td")
tag_array.add("col")
tag_array.add("colgroup")
tag_array.add("li")
tag_array.add("ul")
tag_array.add("strike")
tag_array.add("iframe")
tag_array.add("input")
tag_array.add("u")
tag_count := tag_array.length()
loop % tag_count
{
content := content.replace("<" . tag_array.get(a_index) . ">", "")
content := content.replace("</" . tag_array.get(a_index) . ">", "")
content := content.replace("<" . tag_array.get(a_index).toUpperCase() . ">", "")
content := content.replace("</" . tag_array.get(a_index).toUpperCase() . ">", "")
}
is_tag_exist := true
while(is_tag_exist == true)
{
loop % tag_count
{
current_tag := tag_array.get(a_index)
if(content.isExist("<" . current_tag) || content.isExist("<" . current_tag.toUpperCase()))
{
content := content.replace("<" . current_tag . content.getContentBetween("<" . current_tag, ">") . ">", "")
content := content.replace("<" . current_tag.toUpperCase() . content.getContentBetween("<" . current_tag.toUpperCase(), ">") . ">", "")
}
}
is_tag_exist := false
loop % tag_count
{
current_tag := tag_array.get(a_index)
if(content.isExist("<" . current_tag) || content.isExist("<" . current_tag.toUpperCase()))
{
is_tag_exist := true
}
}
}
if(content.isExist("<SCRIPT") || content.isExist("<script"))
{
content := content.replace("<SCRIPT" . content.getContentBetween("<SCRIPT", "</SCRIPT>") . "</SCRIPT>", "")
content := content.replace("<script" . content.getContentBetween("<script", "</script>") . "</script>", "")
}
return content
}
string_underbarToCamel(this){
underbar := this
camel := ""
upper_flag := false
stringLower, underbar, underbar
loop, parse, underbar
{
if(a_loopfield == "_")
{
upper_flag := true
}
else
{
if(upper_flag == true)
{
stringUpper, a_loopfieldUpper, a_loopfield
upper_flag := false
camel .= a_loopfieldUpper
}
else
{
camel .= a_loopfield
}
}
}
return camel
}
string_camelToUnderbar(this){
camel := this
underbar := ""
head_piece := new String(SubStr(camel, "1", "1"))
if(head_piece.isUpperCase())
{
return camel
}
loop, parse, camel
{
if((asc(a_loopfield) >= 65 && asc(a_loopfield) <= 90 && a_index != 1) || (asc(a_loopfield) >= 48 && asc(a_loopfield) <= 57)) ; 대문자 혹은 숫자
{
underbar .= "_" . a_loopfield
}
else
{
stringUpper, a_loopfieldUpper, a_loopfield
underbar .= a_loopfieldUpper
}
}
return underbar
}
string_removeLeft(this, length){
content := this
return content.substring(length, content.length())
}
string_removeRight(this, length){
content := this
return content.substring(0, content.length() - length)
}
string_getPosition(this, needle, offset) { ; Returns the start of the needle. index starts at 0. Return -1 if not found.
content := this
position := -1
StringGetPos, position, content, %needle%, , offset
return position
}
string_getPostPosition(this, needle, offset){ ; Returns the point after the end of the needle. Return -1 if not found.
content := this
position := -1
StringGetPos, position, content, %needle%, , offset
if(position == "-1")
return -1
else
return position + strlen(needle)
}
string_getPreLetter(this, needle){ ; Return the first character of needle
content := this
start_position := content.getPosition(needle, 0)
if(start_position != "-1" && start_position != "0" )
return substr(content, start_position, 1)
else
return ""
}
string_isVarExist(this, needle){
content := this
found_flag := false
if(content.isExist(needle) == false){
return false
}
pre_letter := content.getPreLetter(needle)
post_letter := content.getPostLetter(needle)
if(pre_letter.isVarLetter() == false && post_letter.isVarLetter() == false)
{
return true
}
}
string_getPostLetter(this, needle){ ; Return the back character of needle
content := this
post_position := content.getPostPosition(needle, 0)
if(post_position != "-1")
return substr(content, post_position + 1, 1)
else
return ""
}
string_isVarLetter(this) { ; Make sure it is a string that can be a variable (alphanumeric, underbar)
content := this
if(content.isAlphabet() || content.isNumber() || content == "_")
return true
else
return false
}