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
|
-
|
|
!
-
|
|
!
-
|
|
!
-
|
|
!
-
|
|
!
-
|
-
|
!
|
-
|
-
|
!
|
|
!
-
|
|
!
-
|
|
!
|
#ifndef __STR_UTIL__
#define global __STR_UTIL__
#module strutil
#uselib "user32.dll"
#func CharLower "CharLowerA" var
#func CharUpper "CharUpperA" var
#uselib "kernel32.dll"
#cfunc LCMapString "LCMapStringA" int, int, sptr, int, var, int
#cfunc GetUserDefaultLCID "GetUserDefaultLCID"
#cfunc IsDBCSLeadByteEx "IsDBCSLeadByteEx" sptr, sptr
#const LCMAP_LOWERCASE 0x00000100 #const LCMAP_UPPERCASE 0x00000200 #const LCMAP_SORTKEY 0x00000400 #const LCMAP_BYTEREV 0x00000800 #const LCMAP_HIRAGANA 0x00100000 #const LCMAP_KATAKANA 0x00200000 #const LCMAP_HALFWIDTH 0x00400000 #const LCMAP_FULLWIDTH 0x00800000 #const LCMAP_LINGUISTIC_CASING 0x01000000 #const LCMAP_SIMPLIFIED_CHINESE 0x02000000 #const LCMAP_TRADITIONAL_CHINESE 0x04000000 #const CP_ACP 0
#const CP_OEMCP 1
#deffunc Lower var vTarget
CharLower vTarget : return
#deffunc Upper var vTarget
CharUpper vTarget : return
#defcfunc toLower str sParam, local lTarget
lTarget = sParam : Lower lTarget
return lTarget
#defcfunc toUpper str sParam, local lTarget
lTarget = sParam : Upper lTarget
return lTarget
#defcfunc HanToZen str s1, var v1, int p1
return LCMapString(GetUserDefaultLCID(), LCMAP_FULLWIDTH, s1, -1, v1, p1)
#defcfunc ZenToHan str s1, var v1, int p1
return LCMapString(GetUserDefaultLCID(), LCMAP_HALFWIDTH, s1, -1, v1, p1)
#defcfunc toZen str sTarget, local lSize, local lBuffer
lSize = HanToZen(sTarget, lBuffer, 0)
sdim lBuffer, lSize
lSize = HanToZen(sTarget, lBuffer, lSize)
return lBuffer
#defcfunc toHan str sTarget, local lSize, local lBuffer
lSize = ZenToHan(sTarget, lBuffer, 0)
sdim lBuffer, lSize
lSize = ZenToHan(sTarget, lBuffer, lSize)
return lBuffer
#defcfunc areHan str sParam, local lStat, local lTarget
lStat = 1 : lTarget = sParam
repeat strlen(lTarget)
if IsDBCSLeadByteEx(CP_ACP, peek(lTarget, cnt)) {
lStat = 0
break
}
loop
return lStat
#defcfunc areZen str sParam, local lStat, local lTarget
lStat = 1 : lTarget = sParam
if strlen(lTarget)\2 : return 0
repeat strlen(lTarget)/2
if IsDBCSLeadByteEx(CP_ACP, peek(lTarget, cnt * 2)) == 0 {
lStat = 0
break
}
loop
return lStat
#defcfunc areDigit str sParam, local lTarget, local lStat
lTarget = toHan(sParam) : lStat = 1
repeat strlen(lTarget)
if (peek(lTarget, cnt) < '0')|('9' < peek(lTarget, cnt)) {
lStat = 0
break
}
loop
return lStat
#defcfunc areAlpha str sParam, local lTarget, local lStat
lTarget = toLower(toHan(sParam)) : lStat = 1
repeat strlen(lTarget)
if (peek(lTarget, cnt) < 'a')|('z' < peek(lTarget, cnt)) {
lStat = 0
break
}
loop
return lStat
#defcfunc getElement str sParam, local lTarget, local lStat, local lTmp
lTarget = toHan(sParam) : lStat = 0
repeat strlen(lTarget)
lTmp = areAlpha(strmid(lTarget, cnt, 1)) * 2 + areDigit(strmid(lTarget, cnt, 1))
if lTmp == 0 : lTmp = %1000000
lStat |= lTmp
loop
return lStat
#defcfunc _insComma@strutil str sParam, int p1, local lTarget, local lMod, local sRefstr
if p1 <= 0 : logmes "桁の指定が異常です。" : return ""
lTarget = toHan(sParam) : lMod = ((strlen(lTarget) - 1) \ p1) + 1
sRefstr = strmid(lTarget, 0, lMod)
repeat (strlen(lTarget) - 1)/p1
sRefstr += "," + strmid(lTarget, cnt * p1 + lMod, p1)
loop
return sRefstr
#define global ctype insComma(%1, %2 = 3) _insComma@strutil(%1, %2)
#deffunc split array arr, str target, str devider
if devider = "" {
return 1
}
dim part_strlen, 10 part_strlen_max = 0 parts_num = 1 _target = target target_strlen = strlen(target) devider_strlen = strlen(devider)
repeat
ins = instr(_target, cnt, devider)
if ins == -1 {
part_strlen(parts_num - 1) = target_strlen - cnt
if part_strlen_max < part_strlen(parts_num - 1) {
part_strlen_max = part_strlen(parts_num - 1)
}
break
} else {
part_strlen(parts_num - 1) = ins
if part_strlen_max < part_strlen(parts_num - 1) {
part_strlen_max = part_strlen(parts_num - 1)
}
parts_num++
continue cnt + ins + devider_strlen
}
loop
sdim arr, part_strlen_max + 1, parts_num
position = 0
foreach arr
arr(cnt) = strmid(_target, position, part_strlen(cnt))
position += part_strlen(cnt) + devider_strlen
loop
return 0
#deffunc join var result, array target, str connecter
if vartype(target) != 2 {
return 1
}
connecter_strlen = strlen(connecter)
result_strlen = connecter_strlen * (length(target) - 1)
repeat length(target)
target_strlen(cnt) = strlen(target(cnt))
result_length += target_strlen(cnt)
loop
sdim result, result_length + 1
position = 0
foreach target
if cnt {
poke result, position, connecter
position += connecter_strlen
}
poke result, position, target(cnt)
position += target_strlen(cnt)
loop
return 0
#global
#endif
|