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

Last change on this file since 386 was 386, checked in by dai, 16 years ago

StrPtr内の判定ミスを修正。
SPrintFクラス内のx64に対するコードを修正。
ArrayListクラスのIListインターフェイス実装を一旦保留。
ListクラスにIEnumeratable、IEnumeratorインターフェイスを実装(まだ実装中…)。

File size: 7.1 KB
Line 
1'string.sbp
2'文字列変数の操作用
3
4#ifndef _INC_BASIC_STRING
5#define _INC_BASIC_STRING
6
7#require <Classes/System/String.ab>
8#require <Classes/System/Text/StringBuilder.ab>
9
10Function StrPtr(s As String) As *StrChar
11    If Not ActiveBasic.IsNothing(s) Then
12        StrPtr = s.StrPtr
13    End If
14End Function
15'StringBuilder版はClasses/System/Text/StringBuilder.abに定義されている
16
17Function ZeroString(length As Long) As System.Text.StringBuilder
18    ZeroString = New System.Text.StringBuilder
19    ZeroString.Length = length
20End Function
21
22Function MakeStr(psz As PSTR) As String
23    Return New String(psz)
24End Function
25
26Function MakeStr(psz As PWSTR) As String
27    Return New String(psz)
28End Function
29
30Dim _System_AllocForConvertedString As *Function(size As SIZE_T) As VoidPtr
31_System_AllocForConvertedString = AddressOf (GC_malloc_atomic)
32
33Function GetStr(psz As PSTR, ByRef wcs As PWSTR) As SIZE_T
34    If psz <> 0 Then
35        Return GetStr(psz, lstrlenA(psz) As SIZE_T, wcs)
36    Else
37        Return 0
38    End If
39End Function
40
41Function GetStr(psz As PSTR, len As SIZE_T, ByRef wcs As PWSTR) As SIZE_T
42    If psz = 0 Then Return 0
43    Dim lenWCS = MultiByteToWideChar(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, 0, 0)
44    wcs = _System_AllocForConvertedString(SizeOf (WCHAR) * (lenWCS + 1)) As PWSTR
45    GetStr = MultiByteToWideChar(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, wcs, lenWCS)
46    wcs[GetStr] = 0
47End Function
48
49Function GetStr(psz As PWSTR, ByRef wcs As PWSTR) As SIZE_T
50    wcs = psz
51    If psz <> 0 Then
52        Return lstrlenW(psz) As SIZE_T
53    Else
54        Return 0
55    End If
56End Function
57
58Function GetStr(psz As PWSTR, len As SIZE_T, ByRef wcs As PWSTR) As SIZE_T
59    wcs = psz
60    If psz <> 0 Then
61        Return len
62    Else
63        Return 0
64    End If
65End Function
66
67Function GetStr(psz As PWSTR, ByRef mbs As PSTR) As SIZE_T
68    If psz = 0 Then
69        Return 0
70    Else
71        Return GetStr(psz, lstrlenW(psz) As SIZE_T, mbs)
72    End If
73End Function
74
75Function GetStr(psz As PWSTR, len As SIZE_T, ByRef mbs As PSTR) As SIZE_T
76    If psz = 0 Then Return 0
77    Dim lenMBS = WideCharToMultiByte(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, 0, 0, 0, 0)
78    mbs = _System_AllocForConvertedString(SizeOf (SByte) * (lenMBS + 1)) As PSTR
79    GetStr = WideCharToMultiByte(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, mbs, lenMBS, 0, 0) As SIZE_T
80    mbs[GetStr] = 0
81End Function
82
83Function GetStr(psz As PSTR, ByRef mbs As PSTR) As SIZE_T
84    mbs = psz
85    If psz <> 0 Then
86        Return lstrlenA(psz) As SIZE_T
87    Else
88        Return 0
89    End If
90End Function
91
92Function GetStr(psz As PSTR, len As SIZE_T, ByRef mbs As PSTR) As SIZE_T
93    mbs = psz
94    If psz <> 0 Then
95        Return len
96    Else
97        Return 0
98    End If
99End Function
100
101Function GetStr(s As String, ByRef mbs As PSTR) As SIZE_T
102    Return GetStr(s.StrPtr, s.Length As SIZE_T, mbs)
103End Function
104
105Function GetStr(s As String, ByRef wcs As PWSTR) As SIZE_T
106    Return GetStr(s.StrPtr, s.Length As SIZE_T, wcs)
107End Function
108
109Function GetWCStr(psz As PSTR, ByRef wcs As PWSTR) As SIZE_T
110    Return GetStr(psz, wcs)
111End Function
112
113Function GetWCStr(psz As PSTR, len As SIZE_T, ByRef wcs As PWSTR) As SIZE_T
114    Return GetStr(psz, len, wcs)
115End Function
116
117Function GetWCStr(psz As PWSTR, ByRef wcs As PWSTR) As SIZE_T
118    Return GetStr(psz, wcs)
119End Function
120
121Function GetWCStr(psz As PWSTR, len As SIZE_T, ByRef wcs As PWSTR) As SIZE_T
122    Return GetStr(psz, len, wcs)
123End Function
124
125Function GetWCStr(s As String, ByRef wcs As PWSTR) As SIZE_T
126    Return GetStr(s.StrPtr, s.Length As SIZE_T, wcs)
127End Function
128
129Function GetMBStr(psz As PWSTR, ByRef mbs As PSTR) As SIZE_T
130    Return GetStr(psz, mbs)
131End Function
132
133Function GetMBStr(psz As PWSTR, len As SIZE_T, ByRef mbs As PSTR) As SIZE_T
134    Return GetStr(psz, len, mbs)
135End Function
136
137Function GetMBStr(psz As PSTR, ByRef mbs As PSTR) As SIZE_T
138    Return GetStr(psz, mbs)
139End Function
140
141Function GetMBStr(psz As PSTR, len As SIZE_T, ByRef mbs As PSTR) As SIZE_T
142    Return GetStr(psz, len, mbs)
143End Function
144
145Function GetMBStr(s As String, ByRef mbs As PSTR) As SIZE_T
146    Return GetStr(s.StrPtr, s.Length As SIZE_T, mbs)
147End Function
148
149Function GetTCStr(psz As PSTR, ByRef tcs As PCTSTR) As SIZE_T
150    Return GetStr(psz, tcs)
151End Function
152
153Function GetTCStr(psz As PSTR, len As SIZE_T, ByRef tcs As PCTSTR) As SIZE_T
154    Return GetStr(psz, len, tcs)
155End Function
156
157Function GetTCStr(psz As PWSTR, ByRef tcs As PCTSTR) As SIZE_T
158    Return GetStr(psz, tcs)
159End Function
160
161Function GetTCStr(psz As PWSTR, len As SIZE_T, ByRef tcs As PCTSTR) As SIZE_T
162    Return GetStr(psz, len, tcs)
163End Function
164
165Function GetTCStr(s As String, ByRef tcs As PCTSTR) As SIZE_T
166    Return GetStr(s.StrPtr, s.Length As SIZE_T, tcs)
167End Function
168
169Function GetSCStr(psz As PSTR, ByRef ss As *StrChar) As SIZE_T
170    Return GetStr(psz, ss)
171End Function
172
173Function GetSCStr(psz As PSTR, len As SIZE_T, ByRef ss As *StrChar) As SIZE_T
174    Return GetStr(psz, len, ss)
175End Function
176
177Function GetSCStr(psz As PWSTR, ByRef ss As *StrChar) As SIZE_T
178    Return GetStr(psz, ss)
179End Function
180
181Function GetSCStr(psz As PWSTR, len As SIZE_T, ByRef ss As *StrChar) As SIZE_T
182    Return GetStr(psz, len, ss)
183End Function
184
185Function GetSCStr(s As String, ByRef ss As *StrChar) As SIZE_T
186    Return GetStr(s.StrPtr, s.Length As SIZE_T, ss)
187End Function
188
189Function ToWCStr(psz As PSTR) As PWSTR
190    GetStr(psz, ToWCStr)
191End Function
192
193Function ToWCStr(psz As PSTR, len As SIZE_T) As PWSTR
194    GetStr(psz, len, ToWCStr)
195End Function
196
197Function ToWCStr(psz As PWSTR) As PWSTR
198    GetStr(psz, ToWCStr)
199End Function
200
201Function ToWCStr(psz As PWSTR, len As SIZE_T) As PWSTR
202    GetStr(psz, len, ToWCStr)
203End Function
204
205Function ToWCStr(s As String) As PWSTR
206    GetStr(s.StrPtr, s.Length As SIZE_T, ToWCStr)
207End Function
208
209Function ToMBStr(psz As PSTR) As PSTR
210    GetStr(psz, ToMBStr)
211End Function
212
213Function ToMBStr(psz As PSTR, len As SIZE_T) As PSTR
214    GetStr(psz, len, ToMBStr)
215End Function
216
217Function ToMBStr(psz As PWSTR) As PSTR
218    GetStr(psz, ToMBStr)
219End Function
220
221Function ToMBStr(psz As PWSTR, len As SIZE_T) As PSTR
222    GetStr(psz, len, ToMBStr)
223End Function
224
225Function ToMBStr(s As String) As PSTR
226    GetStr(s.StrPtr, s.Length As SIZE_T, ToMBStr)
227End Function
228
229Function ToTCStr(psz As PSTR) As PCTSTR
230    GetStr(psz, ToTCStr)
231End Function
232
233Function ToTCStr(psz As PSTR, len As SIZE_T) As PCTSTR
234    GetStr(psz, len, ToTCStr)
235End Function
236
237Function ToTCStr(psz As PWSTR) As PCTSTR
238    GetStr(psz, ToTCStr)
239End Function
240
241Function ToTCStr(psz As PWSTR, len As SIZE_T) As PCTSTR
242    GetStr(psz, len, ToTCStr)
243End Function
244
245Function ToTCStr(s As String) As PCTSTR
246    GetStr(s.StrPtr, s.Length As SIZE_T, ToTCStr)
247End Function
248
249Function ToSCStr(psz As PSTR) As *StrChar
250    GetStr(psz, ToSCStr)
251End Function
252
253Function ToSCStr(psz As PSTR, len As SIZE_T) As *StrChar
254    GetStr(psz, len, ToSCStr)
255End Function
256
257Function ToSCStr(psz As PWSTR) As *StrChar
258    GetStr(psz, ToSCStr)
259End Function
260
261Function ToSCStr(psz As PWSTR, len As SIZE_T) As *StrChar
262    GetStr(psz, len, ToSCStr)
263End Function
264
265Function ToSCStr(s As String) As *StrChar
266    GetStr(s.StrPtr, s.Length As SIZE_T, ToSCStr)
267End Function
268
269#ifdef __STRING_IS_NOT_UNICODE
270Typedef BoxedStrChar = System.SByte
271#else
272TypeDef BoxedStrChar = System.UInt16
273#endif
274
275#endif '_INC_BASIC_STRING
Note: See TracBrowser for help on using the repository browser.