1 | 'string.sbp
|
---|
2 | '文字列変数の操作用
|
---|
3 |
|
---|
4 | #ifndef _INC_BASIC_STRING
|
---|
5 | #define _INC_BASIC_STRING
|
---|
6 |
|
---|
7 | #require <Classes/System/String.ab>
|
---|
8 | #require <Classes/System/Text/StringBuilder.ab>
|
---|
9 |
|
---|
10 | Function StrPtr(s As String) As *StrChar
|
---|
11 | If Not ActiveBasic.IsNothing(s) Then
|
---|
12 | StrPtr = s.StrPtr
|
---|
13 | End If
|
---|
14 | End Function
|
---|
15 | 'StringBuilder版はClasses/System/Text/StringBuilder.abに定義されている
|
---|
16 |
|
---|
17 | Function ZeroString(length As Long) As System.Text.StringBuilder
|
---|
18 | ZeroString = New System.Text.StringBuilder
|
---|
19 | ZeroString.Length = length
|
---|
20 | End Function
|
---|
21 |
|
---|
22 | Function MakeStr(psz As PSTR) As String
|
---|
23 | Return New String(psz)
|
---|
24 | End Function
|
---|
25 |
|
---|
26 | Function MakeStr(psz As PWSTR) As String
|
---|
27 | Return New String(psz)
|
---|
28 | End Function
|
---|
29 |
|
---|
30 | Dim _System_AllocForConvertedString As *Function(size As SIZE_T) As VoidPtr
|
---|
31 | _System_AllocForConvertedString = AddressOf (GC_malloc_atomic)
|
---|
32 |
|
---|
33 | Namespace Detail
|
---|
34 | Function GetWCStr(mbsSrc As PSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
35 | Dim lenWCS = MultiByteToWideChar(CP_THREAD_ACP, 0, mbsSrc, (len As DWord) As Long, 0, 0)
|
---|
36 | wcsDst = _System_AllocForConvertedString(SizeOf (WCHAR) * (lenWCS + 1)) As PWSTR
|
---|
37 | GetWCStr = MultiByteToWideChar(CP_THREAD_ACP, 0, mbsSrc, (len As DWord) As Long, wcsDst, lenWCS)
|
---|
38 | wcsDst[GetWCStr] = 0
|
---|
39 | End Function
|
---|
40 |
|
---|
41 | Function GetWCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
42 | wcsDst = wcsSrc
|
---|
43 | GetWCStr = len
|
---|
44 | End Function
|
---|
45 |
|
---|
46 | Function GetMBStr(wcsSrc As PWSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
|
---|
47 | Dim lenMBS = WideCharToMultiByte(CP_THREAD_ACP, 0, wcsSrc, (len As DWord) As Long, 0, 0, 0, 0)
|
---|
48 | mbsDst = _System_AllocForConvertedString(SizeOf (SByte) * (lenMBS + 1)) As PSTR
|
---|
49 | GetMBStr = WideCharToMultiByte(CP_THREAD_ACP, 0, wcsSrc, (wcsSrc As DWord) As Long, mbsDst, lenMBS, 0, 0) As SIZE_T
|
---|
50 | mbsDst[GetMBStr] = 0
|
---|
51 | End Function
|
---|
52 |
|
---|
53 | Function GetMBStr(mbsSrc As PSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
|
---|
54 | mbsDst = mbsSrc
|
---|
55 | GetMBStr = len
|
---|
56 | End Function
|
---|
57 | End Namespace
|
---|
58 |
|
---|
59 | /*
|
---|
60 | 変換の組み合わせは、
|
---|
61 | 入力引数: wcsz, wcs + len, mbsz, mbs + len, str
|
---|
62 | 出力関数: wcs(z)出力GetStr, mbs(z)出力GetStr,
|
---|
63 | wcs(z)出力GetStrNT, mbs(z)出力GetStrNT,
|
---|
64 | GetWCStr, GetMBStr, GetTCStr, GetSCStr,
|
---|
65 | ToWCStr, ToMBStr, ToTCStr, ToSCStr
|
---|
66 | で、5 * 12 = 60通り。
|
---|
67 | */
|
---|
68 |
|
---|
69 | Function GetStr(mbszSrc As PSTR, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
70 | If mbszSrc = 0 Then
|
---|
71 | wcsDst = 0
|
---|
72 | Return 0
|
---|
73 | Else
|
---|
74 | Return Detail.GetWCStr(mbszSrc, lstrlenA(mbszSrc) As SIZE_T, wcsDst)
|
---|
75 | End If
|
---|
76 | End Function
|
---|
77 |
|
---|
78 | Function GetStr(mbsSrc As PSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
79 | If mbsSrc = 0 Then
|
---|
80 | wcsDst = 0
|
---|
81 | Return 0
|
---|
82 | Else
|
---|
83 | Return Detail.GetWCStr(mbsSrc, len, wcsDst)
|
---|
84 | End If
|
---|
85 | End Function
|
---|
86 |
|
---|
87 | Function GetStr(wcszSrc As PWSTR, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
88 | If wcszSrc = 0 Then
|
---|
89 | wcsDst = 0
|
---|
90 | Return 0
|
---|
91 | Else
|
---|
92 | wcsDst = wcszSrc
|
---|
93 | Return lstrlenW(wcszSrc) As SIZE_T
|
---|
94 | End If
|
---|
95 | End Function
|
---|
96 |
|
---|
97 | Function GetStr(wcsSrc As PWSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
98 | If wcsSrc = 0 Then
|
---|
99 | wcsDst = 0
|
---|
100 | Return 0
|
---|
101 | Else
|
---|
102 | wcsDst = wcsSrc
|
---|
103 | Return len
|
---|
104 | End If
|
---|
105 | End Function
|
---|
106 |
|
---|
107 | Function GetStr(wcszSrc As PWSTR, ByRef mbsDst As PSTR) As SIZE_T
|
---|
108 | If wcszSrc = 0 Then
|
---|
109 | mbsDst = 0
|
---|
110 | Return 0
|
---|
111 | Else
|
---|
112 | Return Detail.GetMBStr(wcszSrc, lstrlenW(wcszSrc) As SIZE_T, mbsDst)
|
---|
113 | End If
|
---|
114 | End Function
|
---|
115 |
|
---|
116 | Function GetStr(wcsSrc As PWSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
|
---|
117 | If wcsSrc = 0 Then
|
---|
118 | mbsDst = 0
|
---|
119 | Return 0
|
---|
120 | Else
|
---|
121 | Return Detail.GetMBStr(wcsSrc, len As SIZE_T, mbsDst)
|
---|
122 | End If
|
---|
123 | End Function
|
---|
124 |
|
---|
125 | Function GetStr(mbszSrc As PSTR, ByRef mbsDst As PSTR) As SIZE_T
|
---|
126 | If mbszSrc = 0 Then
|
---|
127 | mbsDst = 0
|
---|
128 | Return 0
|
---|
129 | Else
|
---|
130 | mbsDst = mbszSrc
|
---|
131 | Return lstrlenA(mbszSrc) As SIZE_T
|
---|
132 | End If
|
---|
133 | End Function
|
---|
134 |
|
---|
135 | Function GetStr(mbsSrc As PSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
|
---|
136 | If mbsSrc = 0 Then
|
---|
137 | mbsDst = 0
|
---|
138 | Return len
|
---|
139 | Else
|
---|
140 | mbsDst = mbsSrc
|
---|
141 | Return 0
|
---|
142 | End If
|
---|
143 | End Function
|
---|
144 |
|
---|
145 | Function GetStr(strSrc As String, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
146 | If ActiveBasic.IsNothing(strSrc) Then
|
---|
147 | wcsDst = 0
|
---|
148 | Return 0
|
---|
149 | Else
|
---|
150 | Return Detail.GetWCStr(strSrc.StrPtr, strSrc.Length As SIZE_T, wcsDst)
|
---|
151 | End If
|
---|
152 | End Function
|
---|
153 |
|
---|
154 | Function GetStr(strSrc As String, ByRef mbsDst As PSTR) As SIZE_T
|
---|
155 | If ActiveBasic.IsNothing(strSrc) Then
|
---|
156 | mbsDst = 0
|
---|
157 | Return 0
|
---|
158 | Else
|
---|
159 | Return Detail.GetMBStr(strSrc.StrPtr, strSrc.Length As SIZE_T, mbsDst)
|
---|
160 | End If
|
---|
161 | End Function
|
---|
162 |
|
---|
163 | Sub GetStrNT(mbszSrc As PSTR, ByRef mbszDst As PSTR)
|
---|
164 | mbszDst = mbszSrc
|
---|
165 | End Sub
|
---|
166 |
|
---|
167 | Sub GetStrNT(mbsSrc As PSTR, len As SIZE_T, ByRef mbszDst As PSTR)
|
---|
168 | mbszDst = mbsSrc
|
---|
169 | End Sub
|
---|
170 |
|
---|
171 | Sub GetStrNT(mbszSrc As PSTR, ByRef wcszDst As PWSTR)
|
---|
172 | GetStr(mbszSrc, wcszDst)
|
---|
173 | End Sub
|
---|
174 |
|
---|
175 | Sub GetStrNT(mbsSrc As PSTR, len As SIZE_T, ByRef wcszDst As PWSTR)
|
---|
176 | GetStr(mbsSrc, len, wcszDst)
|
---|
177 | End Sub
|
---|
178 |
|
---|
179 | Sub GetStrNT(wcszSrc As PWSTR, ByRef mbszDst As PSTR)
|
---|
180 | GetStr(wcszSrc, mbszDst)
|
---|
181 | End Sub
|
---|
182 |
|
---|
183 | Sub GetStrNT(wcsSrc As PWSTR, len As SIZE_T, ByRef mbszDst As PSTR)
|
---|
184 | GetStr(wcsSrc, len, mbszDst)
|
---|
185 | End Sub
|
---|
186 |
|
---|
187 | Sub GetStrNT(wcszSrc As PWSTR, ByRef wcszDst As PWSTR)
|
---|
188 | wcszDst = wcszSrc
|
---|
189 | End Sub
|
---|
190 |
|
---|
191 | Sub GetStrNT(wcsSrc As PWSTR, len As SIZE_T, ByRef wcszDst As PWSTR)
|
---|
192 | wcszDst = wcsSrc
|
---|
193 | End Sub
|
---|
194 |
|
---|
195 | Sub GetStrNT(strSrc As String, ByRef mbszDst As PSTR)
|
---|
196 | GetStr(strSrc, mbszDst)
|
---|
197 | End Sub
|
---|
198 |
|
---|
199 | Sub GetStrNT(strSrc As String, ByRef wcszDst As PWSTR)
|
---|
200 | GetStr(strSrc, wcszDst)
|
---|
201 | End Sub
|
---|
202 |
|
---|
203 | Function GetWCStr(mbszSrc As PSTR, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
204 | Return GetStr(mbszSrc, wcsDst)
|
---|
205 | End Function
|
---|
206 |
|
---|
207 | Function GetWCStr(mbsSrc As PSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
208 | Return GetStr(mbsSrc, len, wcsDst)
|
---|
209 | End Function
|
---|
210 |
|
---|
211 | Function GetWCStr(wcszSrc As PWSTR, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
212 | Return GetStr(wcszSrc, wcsDst)
|
---|
213 | End Function
|
---|
214 |
|
---|
215 | Function GetWCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
216 | Return GetStr(wcsSrc, len, wcsDst)
|
---|
217 | End Function
|
---|
218 |
|
---|
219 | Function GetWCStr(strSrc As String, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
220 | Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, wcsDst)
|
---|
221 | End Function
|
---|
222 |
|
---|
223 | Function GetMBStr(mbszSrc As PWSTR, ByRef mbsDst As PSTR) As SIZE_T
|
---|
224 | Return GetStr(mbszSrc, mbsDst)
|
---|
225 | End Function
|
---|
226 |
|
---|
227 | Function GetMBStr(wcsSrc As PWSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
|
---|
228 | Return GetStr(wcsSrc, len, mbsDst)
|
---|
229 | End Function
|
---|
230 |
|
---|
231 | Function GetMBStr(mbszSrc As PSTR, ByRef mbsDst As PSTR) As SIZE_T
|
---|
232 | Return GetStr(mbszSrc, mbsDst)
|
---|
233 | End Function
|
---|
234 |
|
---|
235 | Function GetMBStr(mbsSrc As PSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
|
---|
236 | Return GetStr(mbsSrc, len, mbsDst)
|
---|
237 | End Function
|
---|
238 |
|
---|
239 | Function GetMBStr(strSrc As String, ByRef mbsDst As PSTR) As SIZE_T
|
---|
240 | Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, mbsDst)
|
---|
241 | End Function
|
---|
242 |
|
---|
243 | Function GetTCStr(mbszSrc As PSTR, ByRef tcsDst As PCTSTR) As SIZE_T
|
---|
244 | Return GetStr(mbszSrc, tcsDst)
|
---|
245 | End Function
|
---|
246 |
|
---|
247 | Function GetTCStr(mbsSrc As PSTR, len As SIZE_T, ByRef tcsDst As PCTSTR) As SIZE_T
|
---|
248 | Return GetStr(mbsSrc, len, tcsDst)
|
---|
249 | End Function
|
---|
250 |
|
---|
251 | Function GetTCStr(wcszSrc As PWSTR, ByRef tcsDst As PCTSTR) As SIZE_T
|
---|
252 | Return GetStr(wcszSrc, tcsDst)
|
---|
253 | End Function
|
---|
254 |
|
---|
255 | Function GetTCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef tcsDst As PCTSTR) As SIZE_T
|
---|
256 | Return GetStr(wcsSrc, len, tcsDst)
|
---|
257 | End Function
|
---|
258 |
|
---|
259 | Function GetTCStr(strSrc As String, ByRef tcsDst As PCTSTR) As SIZE_T
|
---|
260 | Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, tcsDst)
|
---|
261 | End Function
|
---|
262 |
|
---|
263 | Function GetSCStr(mbszSrc As PSTR, ByRef ssDst As *StrChar) As SIZE_T
|
---|
264 | Return GetStr(mbszSrc, ssDst)
|
---|
265 | End Function
|
---|
266 |
|
---|
267 | Function GetSCStr(mbsSrc As PSTR, len As SIZE_T, ByRef ssDst As *StrChar) As SIZE_T
|
---|
268 | Return GetStr(mbsSrc, len, ssDst)
|
---|
269 | End Function
|
---|
270 |
|
---|
271 | Function GetSCStr(wcszSrc As PWSTR, ByRef ssDst As *StrChar) As SIZE_T
|
---|
272 | Return GetStr(wcszSrc, ssDst)
|
---|
273 | End Function
|
---|
274 |
|
---|
275 | Function GetSCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef ssDst As *StrChar) As SIZE_T
|
---|
276 | Return GetStr(wcsSrc, len, ssDst)
|
---|
277 | End Function
|
---|
278 |
|
---|
279 | Function GetSCStr(strSrc As String, ByRef ssDst As *StrChar) As SIZE_T
|
---|
280 | Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, ssDst)
|
---|
281 | End Function
|
---|
282 |
|
---|
283 | Function ToWCStr(mbsz As PSTR) As PWSTR
|
---|
284 | GetStrNT(mbsz, ToWCStr)
|
---|
285 | End Function
|
---|
286 |
|
---|
287 | Function ToWCStr(mbs As PSTR, len As SIZE_T) As PWSTR
|
---|
288 | GetStrNT(mbs, len, ToWCStr)
|
---|
289 | End Function
|
---|
290 |
|
---|
291 | Function ToWCStr(wcsz As PWSTR) As PWSTR
|
---|
292 | ToWCStr = wcsz
|
---|
293 | End Function
|
---|
294 |
|
---|
295 | Function ToWCStr(wcs As PWSTR, len As SIZE_T) As PWSTR
|
---|
296 | ToWCStr = wcs
|
---|
297 | End Function
|
---|
298 |
|
---|
299 | Function ToWCStr(s As String) As PWSTR
|
---|
300 | GetStrNT(s, ToWCStr)
|
---|
301 | End Function
|
---|
302 |
|
---|
303 | Function ToMBStr(mbsz As PSTR) As PSTR
|
---|
304 | ToMBStr = mbsz
|
---|
305 | End Function
|
---|
306 |
|
---|
307 | Function ToMBStr(mbs As PSTR, len As SIZE_T) As PSTR
|
---|
308 | ToMBStr = mbs
|
---|
309 | End Function
|
---|
310 |
|
---|
311 | Function ToMBStr(wcsz As PWSTR) As PSTR
|
---|
312 | GetStrNT(wcsz, ToMBStr)
|
---|
313 | End Function
|
---|
314 |
|
---|
315 | Function ToMBStr(wcs As PWSTR, len As SIZE_T) As PSTR
|
---|
316 | GetStrNT(wcs, len, ToMBStr)
|
---|
317 | End Function
|
---|
318 |
|
---|
319 | Function ToMBStr(s As String) As PSTR
|
---|
320 | GetStrNT(s, ToMBStr)
|
---|
321 | End Function
|
---|
322 |
|
---|
323 | Function ToTCStr(mbsz As PSTR) As PCTSTR
|
---|
324 | GetStrNT(mbsz, ToTCStr)
|
---|
325 | End Function
|
---|
326 |
|
---|
327 | Function ToTCStr(mbs As PSTR, len As SIZE_T) As PCTSTR
|
---|
328 | GetStrNT(mbs, len, ToTCStr)
|
---|
329 | End Function
|
---|
330 |
|
---|
331 | Function ToTCStr(wcsz As PWSTR) As PCTSTR
|
---|
332 | GetStrNT(wcsz, ToTCStr)
|
---|
333 | End Function
|
---|
334 |
|
---|
335 | Function ToTCStr(wcs As PWSTR, len As SIZE_T) As PCTSTR
|
---|
336 | GetStrNT(wcs, len, ToTCStr)
|
---|
337 | End Function
|
---|
338 |
|
---|
339 | Function ToTCStr(s As String) As PCTSTR
|
---|
340 | GetStrNT(s, ToTCStr)
|
---|
341 | End Function
|
---|
342 |
|
---|
343 | Function ToSCStr(mbsz As PSTR) As *StrChar
|
---|
344 | GetStrNT(mbsz, ToSCStr)
|
---|
345 | End Function
|
---|
346 |
|
---|
347 | Function ToSCStr(mbs As PSTR, len As SIZE_T) As *StrChar
|
---|
348 | GetStrNT(mbs, len, ToSCStr)
|
---|
349 | End Function
|
---|
350 |
|
---|
351 | Function ToSCStr(wcsz As PWSTR) As *StrChar
|
---|
352 | GetStrNT(wcsz, ToSCStr)
|
---|
353 | End Function
|
---|
354 |
|
---|
355 | Function ToSCStr(wcs As PWSTR, len As SIZE_T) As *StrChar
|
---|
356 | GetStrNT(wcs, len, ToSCStr)
|
---|
357 | End Function
|
---|
358 |
|
---|
359 | Function ToSCStr(s As String) As *StrChar
|
---|
360 | ToSCStr = StrPtr(s)
|
---|
361 | End Function
|
---|
362 |
|
---|
363 | #ifndef UNICODE
|
---|
364 | Typedef BoxedStrChar = System.SByte
|
---|
365 | #else
|
---|
366 | TypeDef BoxedStrChar = System.UInt16
|
---|
367 | #endif
|
---|
368 |
|
---|
369 | #endif '_INC_BASIC_STRING
|
---|