source: trunk/ab5.0/ablib/src/system/string.sbp@ 560

Last change on this file since 560 was 497, checked in by イグトランス (egtra), 16 years ago

インクルードガードとその他不要な前処理定義などの削除

File size: 8.4 KB
Line 
1'string.sbp
2'文字列変数の操作用
3
4Function StrPtr(s As String) As *Char
5 If Not ActiveBasic.IsNothing(s) Then
6 StrPtr = s.StrPtr
7 End If
8End Function
9'StringBuilder版はClasses/System/Text/StringBuilder.abに定義されている
10
11Function ZeroString(length As Long) As System.Text.StringBuilder
12 ZeroString = New System.Text.StringBuilder
13 ZeroString.Length = length
14End Function
15
16Function MakeStr(psz As PSTR) As String
17 Return New String(psz)
18End Function
19
20Function MakeStr(psz As PWSTR) As String
21 Return New String(psz)
22End Function
23
24Dim _System_AllocForConvertedString As *Function(size As SIZE_T) As VoidPtr
25_System_AllocForConvertedString = AddressOf (GC_malloc_atomic)
26
27Namespace 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
51End 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
63Function 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
70End Function
71
72Function 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
79End Function
80
81Function 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
89End Function
90
91Function 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
99End Function
100
101Function 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
108End Function
109
110Function 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
117End Function
118
119Function 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
127End Function
128
129Function 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
137End Function
138
139Function 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
146End Function
147
148Function 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
155End Function
156
157Sub GetStrNT(mbszSrc As PSTR, ByRef mbszDst As PSTR)
158 mbszDst = mbszSrc
159End Sub
160
161Sub GetStrNT(mbsSrc As PSTR, len As SIZE_T, ByRef mbszDst As PSTR)
162 mbszDst = mbsSrc
163End Sub
164
165Sub GetStrNT(mbszSrc As PSTR, ByRef wcszDst As PWSTR)
166 GetStr(mbszSrc, wcszDst)
167End Sub
168
169Sub GetStrNT(mbsSrc As PSTR, len As SIZE_T, ByRef wcszDst As PWSTR)
170 GetStr(mbsSrc, len, wcszDst)
171End Sub
172
173Sub GetStrNT(wcszSrc As PWSTR, ByRef mbszDst As PSTR)
174 GetStr(wcszSrc, mbszDst)
175End Sub
176
177Sub GetStrNT(wcsSrc As PWSTR, len As SIZE_T, ByRef mbszDst As PSTR)
178 GetStr(wcsSrc, len, mbszDst)
179End Sub
180
181Sub GetStrNT(wcszSrc As PWSTR, ByRef wcszDst As PWSTR)
182 wcszDst = wcszSrc
183End Sub
184
185Sub GetStrNT(wcsSrc As PWSTR, len As SIZE_T, ByRef wcszDst As PWSTR)
186 wcszDst = wcsSrc
187End Sub
188
189Sub GetStrNT(strSrc As String, ByRef mbszDst As PSTR)
190 GetStr(strSrc, mbszDst)
191End Sub
192
193Sub GetStrNT(strSrc As String, ByRef wcszDst As PWSTR)
194 GetStr(strSrc, wcszDst)
195End Sub
196
197Function GetWCStr(mbszSrc As PSTR, ByRef wcsDst As PWSTR) As SIZE_T
198 Return GetStr(mbszSrc, wcsDst)
199End Function
200
201Function GetWCStr(mbsSrc As PSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
202 Return GetStr(mbsSrc, len, wcsDst)
203End Function
204
205Function GetWCStr(wcszSrc As PWSTR, ByRef wcsDst As PWSTR) As SIZE_T
206 Return GetStr(wcszSrc, wcsDst)
207End Function
208
209Function GetWCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
210 Return GetStr(wcsSrc, len, wcsDst)
211End Function
212
213Function GetWCStr(strSrc As String, ByRef wcsDst As PWSTR) As SIZE_T
214 Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, wcsDst)
215End Function
216
217Function GetMBStr(mbszSrc As PWSTR, ByRef mbsDst As PSTR) As SIZE_T
218 Return GetStr(mbszSrc, mbsDst)
219End Function
220
221Function GetMBStr(wcsSrc As PWSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
222 Return GetStr(wcsSrc, len, mbsDst)
223End Function
224
225Function GetMBStr(mbszSrc As PSTR, ByRef mbsDst As PSTR) As SIZE_T
226 Return GetStr(mbszSrc, mbsDst)
227End Function
228
229Function GetMBStr(mbsSrc As PSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
230 Return GetStr(mbsSrc, len, mbsDst)
231End Function
232
233Function GetMBStr(strSrc As String, ByRef mbsDst As PSTR) As SIZE_T
234 Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, mbsDst)
235End Function
236
237Function GetTCStr(mbszSrc As PSTR, ByRef tcsDst As PCTSTR) As SIZE_T
238 Return GetStr(mbszSrc, tcsDst)
239End Function
240
241Function GetTCStr(mbsSrc As PSTR, len As SIZE_T, ByRef tcsDst As PCTSTR) As SIZE_T
242 Return GetStr(mbsSrc, len, tcsDst)
243End Function
244
245Function GetTCStr(wcszSrc As PWSTR, ByRef tcsDst As PCTSTR) As SIZE_T
246 Return GetStr(wcszSrc, tcsDst)
247End Function
248
249Function GetTCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef tcsDst As PCTSTR) As SIZE_T
250 Return GetStr(wcsSrc, len, tcsDst)
251End Function
252
253Function GetTCStr(strSrc As String, ByRef tcsDst As PCTSTR) As SIZE_T
254 Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, tcsDst)
255End Function
256
257Function ToWCStr(mbsz As PSTR) As PWSTR
258 GetStrNT(mbsz, ToWCStr)
259End Function
260
261Function ToWCStr(mbs As PSTR, len As SIZE_T) As PWSTR
262 GetStrNT(mbs, len, ToWCStr)
263End Function
264
265Function ToWCStr(wcsz As PWSTR) As PWSTR
266 ToWCStr = wcsz
267End Function
268
269Function ToWCStr(wcs As PWSTR, len As SIZE_T) As PWSTR
270 ToWCStr = wcs
271End Function
272
273Function ToWCStr(s As String) As PWSTR
274 GetStrNT(s, ToWCStr)
275End Function
276
277Function ToMBStr(mbsz As PSTR) As PSTR
278 ToMBStr = mbsz
279End Function
280
281Function ToMBStr(mbs As PSTR, len As SIZE_T) As PSTR
282 ToMBStr = mbs
283End Function
284
285Function ToMBStr(wcsz As PWSTR) As PSTR
286 GetStrNT(wcsz, ToMBStr)
287End Function
288
289Function ToMBStr(wcs As PWSTR, len As SIZE_T) As PSTR
290 GetStrNT(wcs, len, ToMBStr)
291End Function
292
293Function ToMBStr(s As String) As PSTR
294 GetStrNT(s, ToMBStr)
295End Function
296
297Function ToTCStr(mbsz As PSTR) As PCTSTR
298 GetStrNT(mbsz, ToTCStr)
299End Function
300
301Function ToTCStr(mbs As PSTR, len As SIZE_T) As PCTSTR
302 GetStrNT(mbs, len, ToTCStr)
303End Function
304
305Function ToTCStr(wcsz As PWSTR) As PCTSTR
306 GetStrNT(wcsz, ToTCStr)
307End Function
308
309Function ToTCStr(wcs As PWSTR, len As SIZE_T) As PCTSTR
310 GetStrNT(wcs, len, ToTCStr)
311End Function
312
313Function ToTCStr(s As String) As PCTSTR
314 GetStrNT(s, ToTCStr)
315End Function
316
317#ifndef UNICODE
318TypeDef BoxedStrChar = System.SByte
319#else
320TypeDef BoxedStrChar = System.UInt16
321#endif
Note: See TracBrowser for help on using the repository browser.