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