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