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

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

CP_THREAD_ACPがWindows 2000以上限定のため、CP_ACPへ変更

File size: 7.7 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_ACP, 0, mbsSrc, (len As DWord) As Long, 0, 0)
30 wcsDst = _System_AllocForConvertedString(SizeOf (WCHAR) * lenWCS) As PWSTR
31 GetWCStr = MultiByteToWideChar(CP_ACP, 0, mbsSrc, (len As DWord) As Long, wcsDst, lenWCS)
32 End Function
33
34 Function GetWCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
35 wcsDst = wcsSrc
36 GetWCStr = len
37 End Function
38
39 Function GetMBStr(wcsSrc As PWSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
40 Dim lenMBS = WideCharToMultiByte(CP_ACP, 0, wcsSrc, (len As DWord) As Long, 0, 0, 0, 0)
41 mbsDst = _System_AllocForConvertedString(SizeOf (CHAR) * lenMBS) As PSTR
42 GetMBStr = WideCharToMultiByte(CP_ACP, 0, wcsSrc, (wcsSrc As DWord) As Long, mbsDst, lenMBS, 0, 0) As SIZE_T
43 End Function
44
45 Function GetMBStr(mbsSrc As PSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
46 mbsDst = mbsSrc
47 GetMBStr = len
48 End Function
49
50 ' ToTCStrの補助
51 Sub GetStrNT(mbszSrc As PSTR, ByRef mbszDst As PSTR)
52 mbszDst = mbszSrc
53 End Sub
54
55 Sub GetStrNT(mbszSrc As PSTR, ByRef wcszDst As PWSTR)
56 GetStr(mbszSrc, wcszDst)
57 End Sub
58
59 Sub GetStrNT(wcszSrc As PWSTR, ByRef mbszDst As PSTR)
60 GetStr(wcszSrc, mbszDst)
61 End Sub
62
63 Sub GetStrNT(wcszSrc As PWSTR, ByRef wcszDst As PWSTR)
64 wcszDst = wcszSrc
65 End Sub
66
67End Namespace
68
69/*
70変換の組み合わせは、
71入力引数: wcsz, wcs + len, mbsz, mbs + len, str
72出力関数: wcs(z)出力GetStr, mbs(z)出力GetStr,
73 GetWCStr, GetMBStr, GetTCStr,
74 ToWCStr, ToMBStr, ToTCStr,
75で、5 * 8 = 40通り。
76*/
77
78Function GetStr(mbszSrc As PSTR, ByRef wcsDst As PWSTR) As SIZE_T
79 If mbszSrc = 0 Then
80 wcsDst = 0
81 Return 0
82 Else
83 Return Detail.GetWCStr(mbszSrc, (lstrlenA(mbszSrc) + 1) As SIZE_T, wcsDst)
84 End If
85End Function
86
87Function GetStr(mbsSrc As PSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
88 If mbsSrc = 0 Then
89 wcsDst = 0
90 Return 0
91 Else
92 Return Detail.GetWCStr(mbsSrc, len, wcsDst)
93 End If
94End Function
95
96Function GetStr(wcszSrc As PWSTR, ByRef wcsDst As PWSTR) As SIZE_T
97 If wcszSrc = 0 Then
98 wcsDst = 0
99 Return 0
100 Else
101 wcsDst = wcszSrc
102 Return lstrlenW(wcszSrc) As SIZE_T + 1
103 End If
104End Function
105
106Function GetStr(wcsSrc As PWSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
107 If wcsSrc = 0 Then
108 wcsDst = 0
109 Return 0
110 Else
111 wcsDst = wcsSrc
112 Return len
113 End If
114End Function
115
116Function GetStr(wcszSrc As PWSTR, ByRef mbsDst As PSTR) As SIZE_T
117 If wcszSrc = 0 Then
118 mbsDst = 0
119 Return 0
120 Else
121 Return Detail.GetMBStr(wcszSrc, (lstrlenW(wcszSrc) + 1) As SIZE_T, mbsDst)
122 End If
123End Function
124
125Function GetStr(wcsSrc As PWSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
126 If wcsSrc = 0 Then
127 mbsDst = 0
128 Return 0
129 Else
130 Return Detail.GetMBStr(wcsSrc, len As SIZE_T, mbsDst)
131 End If
132End Function
133
134Function GetStr(mbszSrc As PSTR, ByRef mbsDst As PSTR) As SIZE_T
135 If mbszSrc = 0 Then
136 mbsDst = 0
137 Return 0
138 Else
139 mbsDst = mbszSrc
140 Return lstrlenA(mbszSrc) As SIZE_T + 1
141 End If
142End Function
143
144Function GetStr(mbsSrc As PSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
145 If mbsSrc = 0 Then
146 mbsDst = 0
147 Return len
148 Else
149 mbsDst = mbsSrc
150 Return 0
151 End If
152End Function
153
154Function GetStr(strSrc As String, ByRef wcsDst As PWSTR) As SIZE_T
155 If ActiveBasic.IsNothing(strSrc) Then
156 wcsDst = 0
157 Return 0
158 Else
159 Return Detail.GetWCStr(strSrc.StrPtr, strSrc.Length As SIZE_T, wcsDst)
160 End If
161End Function
162
163Function GetStr(strSrc As String, ByRef mbsDst As PSTR) As SIZE_T
164 If ActiveBasic.IsNothing(strSrc) Then
165 mbsDst = 0
166 Return 0
167 Else
168 Return Detail.GetMBStr(strSrc.StrPtr, strSrc.Length As SIZE_T, mbsDst)
169 End If
170End Function
171
172Function GetWCStr(mbszSrc As PSTR, ByRef wcsDst As PWSTR) As SIZE_T
173 Return GetStr(mbszSrc, wcsDst)
174End Function
175
176Function GetWCStr(mbsSrc As PSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
177 Return GetStr(mbsSrc, len, wcsDst)
178End Function
179
180Function GetWCStr(wcszSrc As PWSTR, ByRef wcsDst As PWSTR) As SIZE_T
181 Return GetStr(wcszSrc, wcsDst)
182End Function
183
184Function GetWCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
185 Return GetStr(wcsSrc, len, wcsDst)
186End Function
187
188Function GetWCStr(strSrc As String, ByRef wcsDst As PWSTR) As SIZE_T
189 Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, wcsDst)
190End Function
191
192Function GetMBStr(mbszSrc As PWSTR, ByRef mbsDst As PSTR) As SIZE_T
193 Return GetStr(mbszSrc, mbsDst)
194End Function
195
196Function GetMBStr(wcsSrc As PWSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
197 Return GetStr(wcsSrc, len, mbsDst)
198End Function
199
200Function GetMBStr(mbszSrc As PSTR, ByRef mbsDst As PSTR) As SIZE_T
201 Return GetStr(mbszSrc, mbsDst)
202End Function
203
204Function GetMBStr(mbsSrc As PSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
205 Return GetStr(mbsSrc, len, mbsDst)
206End Function
207
208Function GetMBStr(strSrc As String, ByRef mbsDst As PSTR) As SIZE_T
209 Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, mbsDst)
210End Function
211
212Function GetTCStr(mbszSrc As PSTR, ByRef tcsDst As PCTSTR) As SIZE_T
213 Return GetStr(mbszSrc, tcsDst)
214End Function
215
216Function GetTCStr(mbsSrc As PSTR, len As SIZE_T, ByRef tcsDst As PCTSTR) As SIZE_T
217 Return GetStr(mbsSrc, len, tcsDst)
218End Function
219
220Function GetTCStr(wcszSrc As PWSTR, ByRef tcsDst As PCTSTR) As SIZE_T
221 Return GetStr(wcszSrc, tcsDst)
222End Function
223
224Function GetTCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef tcsDst As PCTSTR) As SIZE_T
225 Return GetStr(wcsSrc, len, tcsDst)
226End Function
227
228Function GetTCStr(strSrc As String, ByRef tcsDst As PCTSTR) As SIZE_T
229 Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, tcsDst)
230End Function
231
232Function ToWCStr(mbsz As PSTR) As PWSTR
233 Detail.GetStrNT(mbsz, ToWCStr)
234End Function
235
236Function ToWCStr(mbs As PSTR, len As SIZE_T) As PWSTR
237 GetStr(mbs, len, ToWCStr)
238End Function
239
240Function ToWCStr(wcsz As PWSTR) As PWSTR
241 ToWCStr = wcsz
242End Function
243
244Function ToWCStr(wcs As PWSTR, len As SIZE_T) As PWSTR
245 ToWCStr = wcs
246End Function
247
248Function ToWCStr(s As String) As PWSTR
249 GetStr(s, ToWCStr)
250End Function
251
252Function ToMBStr(mbsz As PSTR) As PSTR
253 ToMBStr = mbsz
254End Function
255
256Function ToMBStr(mbs As PSTR, len As SIZE_T) As PSTR
257 ToMBStr = mbs
258End Function
259
260Function ToMBStr(wcsz As PWSTR) As PSTR
261 Detail.GetStrNT(wcsz, ToMBStr)
262End Function
263
264Function ToMBStr(wcs As PWSTR, len As SIZE_T) As PSTR
265 GetStr(wcs, len, ToMBStr)
266End Function
267
268Function ToMBStr(s As String) As PSTR
269 GetStr(s, ToMBStr)
270End Function
271
272Function ToTCStr(mbsz As PSTR) As PCTSTR
273 Detail.GetStrNT(mbsz, ToTCStr)
274End Function
275
276Function ToTCStr(mbs As PSTR, len As SIZE_T) As PCTSTR
277 GetStr(mbs, len, ToTCStr)
278End Function
279
280Function ToTCStr(wcsz As PWSTR) As PCTSTR
281 Detail.GetStrNT(wcsz, ToTCStr)
282End Function
283
284Function ToTCStr(wcs As PWSTR, len As SIZE_T) As PCTSTR
285 GetStr(wcs, len, ToTCStr)
286End Function
287
288Function ToTCStr(s As String) As PCTSTR
289 Return StrPtr(s)
290End Function
291
292#ifndef UNICODE
293TypeDef BoxedStrChar = System.SByte
294#else
295TypeDef BoxedStrChar = System.UInt16
296#endif
Note: See TracBrowser for help on using the repository browser.