source: trunk/Include/system/string.sbp@ 494

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

現在向けに修正(参照型のポインタの排除など)

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