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
RevLine 
[1]1'string.sbp
2'文字列変数の操作用
3
4#ifndef _INC_BASIC_STRING
5#define _INC_BASIC_STRING
6
[303]7#require <Classes/System/String.ab>
8#require <Classes/System/Text/StringBuilder.ab>
9
[272]10Function StrPtr(s As String) As *StrChar
[386]11 If Not ActiveBasic.IsNothing(s) Then
[385]12 StrPtr = s.StrPtr
13 End If
[1]14End Function
[303]15'StringBuilder版はClasses/System/Text/StringBuilder.abに定義されている
[1]16
[303]17Function ZeroString(length As Long) As System.Text.StringBuilder
18 ZeroString = New System.Text.StringBuilder
19 ZeroString.Length = length
[1]20End Function
21
[167]22Function MakeStr(psz As PSTR) As String
23 Return New String(psz)
[1]24End Function
25
[167]26Function MakeStr(psz As PWSTR) As String
27 Return New String(psz)
[142]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
[175]35 Return GetStr(psz, lstrlenA(psz) As SIZE_T, wcs)
[142]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
[385]43 Dim lenWCS = MultiByteToWideChar(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, 0, 0)
[192]44 wcs = _System_AllocForConvertedString(SizeOf (WCHAR) * (lenWCS + 1)) As PWSTR
[385]45 GetStr = MultiByteToWideChar(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, wcs, lenWCS)
[149]46 wcs[GetStr] = 0
[142]47End Function
48
49Function GetStr(psz As PWSTR, ByRef wcs As PWSTR) As SIZE_T
50 wcs = psz
51 If psz <> 0 Then
[175]52 Return lstrlenW(psz) As SIZE_T
[142]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
[149]61 Return len
[142]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
[175]71 Return GetStr(psz, lstrlenW(psz) As SIZE_T, mbs)
[142]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
[385]77 Dim lenMBS = WideCharToMultiByte(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, 0, 0, 0, 0)
[192]78 mbs = _System_AllocForConvertedString(SizeOf (SByte) * (lenMBS + 1)) As PSTR
[385]79 GetStr = WideCharToMultiByte(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, mbs, lenMBS, 0, 0) As SIZE_T
[142]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
[175]86 Return lstrlenA(psz) As SIZE_T
[142]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
[149]94 If psz <> 0 Then
95 Return len
96 Else
97 Return 0
98 End If
[142]99End Function
100
[237]101Function GetStr(s As String, ByRef mbs As PSTR) As SIZE_T
[272]102 Return GetStr(s.StrPtr, s.Length As SIZE_T, mbs)
[142]103End Function
104
[237]105Function GetStr(s As String, ByRef wcs As PWSTR) As SIZE_T
[272]106 Return GetStr(s.StrPtr, s.Length As SIZE_T, wcs)
[142]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
[237]125Function GetWCStr(s As String, ByRef wcs As PWSTR) As SIZE_T
[272]126 Return GetStr(s.StrPtr, s.Length As SIZE_T, wcs)
[142]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
[237]145Function GetMBStr(s As String, ByRef mbs As PSTR) As SIZE_T
[272]146 Return GetStr(s.StrPtr, s.Length As SIZE_T, mbs)
[142]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
[237]165Function GetTCStr(s As String, ByRef tcs As PCTSTR) As SIZE_T
[272]166 Return GetStr(s.StrPtr, s.Length As SIZE_T, tcs)
[142]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
[237]185Function GetSCStr(s As String, ByRef ss As *StrChar) As SIZE_T
[272]186 Return GetStr(s.StrPtr, s.Length As SIZE_T, ss)
[142]187End Function
188
189Function ToWCStr(psz As PSTR) As PWSTR
[149]190 GetStr(psz, ToWCStr)
[142]191End Function
192
193Function ToWCStr(psz As PSTR, len As SIZE_T) As PWSTR
[149]194 GetStr(psz, len, ToWCStr)
[142]195End Function
196
197Function ToWCStr(psz As PWSTR) As PWSTR
[149]198 GetStr(psz, ToWCStr)
[142]199End Function
200
201Function ToWCStr(psz As PWSTR, len As SIZE_T) As PWSTR
[149]202 GetStr(psz, len, ToWCStr)
[142]203End Function
204
[237]205Function ToWCStr(s As String) As PWSTR
[272]206 GetStr(s.StrPtr, s.Length As SIZE_T, ToWCStr)
[142]207End Function
208
209Function ToMBStr(psz As PSTR) As PSTR
[149]210 GetStr(psz, ToMBStr)
[142]211End Function
212
213Function ToMBStr(psz As PSTR, len As SIZE_T) As PSTR
[149]214 GetStr(psz, len, ToMBStr)
[142]215End Function
216
217Function ToMBStr(psz As PWSTR) As PSTR
[149]218 GetStr(psz, ToMBStr)
[142]219End Function
220
221Function ToMBStr(psz As PWSTR, len As SIZE_T) As PSTR
[149]222 GetStr(psz, len, ToMBStr)
[142]223End Function
224
[237]225Function ToMBStr(s As String) As PSTR
[272]226 GetStr(s.StrPtr, s.Length As SIZE_T, ToMBStr)
[142]227End Function
228
229Function ToTCStr(psz As PSTR) As PCTSTR
[149]230 GetStr(psz, ToTCStr)
[142]231End Function
232
233Function ToTCStr(psz As PSTR, len As SIZE_T) As PCTSTR
[149]234 GetStr(psz, len, ToTCStr)
[142]235End Function
236
237Function ToTCStr(psz As PWSTR) As PCTSTR
[149]238 GetStr(psz, ToTCStr)
[142]239End Function
240
241Function ToTCStr(psz As PWSTR, len As SIZE_T) As PCTSTR
[149]242 GetStr(psz, len, ToTCStr)
[142]243End Function
244
[237]245Function ToTCStr(s As String) As PCTSTR
[272]246 GetStr(s.StrPtr, s.Length As SIZE_T, ToTCStr)
[142]247End Function
248
249Function ToSCStr(psz As PSTR) As *StrChar
[149]250 GetStr(psz, ToSCStr)
[142]251End Function
252
253Function ToSCStr(psz As PSTR, len As SIZE_T) As *StrChar
[149]254 GetStr(psz, len, ToSCStr)
[142]255End Function
256
257Function ToSCStr(psz As PWSTR) As *StrChar
[149]258 GetStr(psz, ToSCStr)
[142]259End Function
260
261Function ToSCStr(psz As PWSTR, len As SIZE_T) As *StrChar
[149]262 GetStr(psz, len, ToSCStr)
[142]263End Function
264
[237]265Function ToSCStr(s As String) As *StrChar
[272]266 GetStr(s.StrPtr, s.Length As SIZE_T, ToSCStr)
[142]267End Function
268
[383]269#ifdef __STRING_IS_NOT_UNICODE
270Typedef BoxedStrChar = System.SByte
271#else
272TypeDef BoxedStrChar = System.UInt16
273#endif
274
[1]275#endif '_INC_BASIC_STRING
Note: See TracBrowser for help on using the repository browser.