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 |
|
---|
10 | Function StrPtr(s As String) As *StrChar
|
---|
11 | If Not ActiveBasic.IsNothing(s) Then
|
---|
12 | StrPtr = s.StrPtr
|
---|
13 | End If
|
---|
14 | End Function
|
---|
15 | 'StringBuilder版はClasses/System/Text/StringBuilder.abに定義されている
|
---|
16 |
|
---|
17 | Function ZeroString(length As Long) As System.Text.StringBuilder
|
---|
18 | ZeroString = New System.Text.StringBuilder
|
---|
19 | ZeroString.Length = length
|
---|
20 | End Function
|
---|
21 |
|
---|
22 | Function MakeStr(psz As PSTR) As String
|
---|
23 | Return New String(psz)
|
---|
24 | End Function
|
---|
25 |
|
---|
26 | Function MakeStr(psz As PWSTR) As String
|
---|
27 | Return New String(psz)
|
---|
28 | End Function
|
---|
29 |
|
---|
30 | Dim _System_AllocForConvertedString As *Function(size As SIZE_T) As VoidPtr
|
---|
31 | _System_AllocForConvertedString = AddressOf (GC_malloc_atomic)
|
---|
32 |
|
---|
33 | Function 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
|
---|
39 | End Function
|
---|
40 |
|
---|
41 | Function 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
|
---|
47 | End Function
|
---|
48 |
|
---|
49 | Function 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
|
---|
56 | End Function
|
---|
57 |
|
---|
58 | Function 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
|
---|
65 | End Function
|
---|
66 |
|
---|
67 | Function 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
|
---|
73 | End Function
|
---|
74 |
|
---|
75 | Function 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
|
---|
81 | End Function
|
---|
82 |
|
---|
83 | Function 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
|
---|
90 | End Function
|
---|
91 |
|
---|
92 | Function 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
|
---|
99 | End Function
|
---|
100 |
|
---|
101 | Function GetStr(s As String, ByRef mbs As PSTR) As SIZE_T
|
---|
102 | Return GetStr(s.StrPtr, s.Length As SIZE_T, mbs)
|
---|
103 | End Function
|
---|
104 |
|
---|
105 | Function GetStr(s As String, ByRef wcs As PWSTR) As SIZE_T
|
---|
106 | Return GetStr(s.StrPtr, s.Length As SIZE_T, wcs)
|
---|
107 | End Function
|
---|
108 |
|
---|
109 | Function GetWCStr(psz As PSTR, ByRef wcs As PWSTR) As SIZE_T
|
---|
110 | Return GetStr(psz, wcs)
|
---|
111 | End Function
|
---|
112 |
|
---|
113 | Function GetWCStr(psz As PSTR, len As SIZE_T, ByRef wcs As PWSTR) As SIZE_T
|
---|
114 | Return GetStr(psz, len, wcs)
|
---|
115 | End Function
|
---|
116 |
|
---|
117 | Function GetWCStr(psz As PWSTR, ByRef wcs As PWSTR) As SIZE_T
|
---|
118 | Return GetStr(psz, wcs)
|
---|
119 | End Function
|
---|
120 |
|
---|
121 | Function GetWCStr(psz As PWSTR, len As SIZE_T, ByRef wcs As PWSTR) As SIZE_T
|
---|
122 | Return GetStr(psz, len, wcs)
|
---|
123 | End Function
|
---|
124 |
|
---|
125 | Function GetWCStr(s As String, ByRef wcs As PWSTR) As SIZE_T
|
---|
126 | Return GetStr(s.StrPtr, s.Length As SIZE_T, wcs)
|
---|
127 | End Function
|
---|
128 |
|
---|
129 | Function GetMBStr(psz As PWSTR, ByRef mbs As PSTR) As SIZE_T
|
---|
130 | Return GetStr(psz, mbs)
|
---|
131 | End Function
|
---|
132 |
|
---|
133 | Function GetMBStr(psz As PWSTR, len As SIZE_T, ByRef mbs As PSTR) As SIZE_T
|
---|
134 | Return GetStr(psz, len, mbs)
|
---|
135 | End Function
|
---|
136 |
|
---|
137 | Function GetMBStr(psz As PSTR, ByRef mbs As PSTR) As SIZE_T
|
---|
138 | Return GetStr(psz, mbs)
|
---|
139 | End Function
|
---|
140 |
|
---|
141 | Function GetMBStr(psz As PSTR, len As SIZE_T, ByRef mbs As PSTR) As SIZE_T
|
---|
142 | Return GetStr(psz, len, mbs)
|
---|
143 | End Function
|
---|
144 |
|
---|
145 | Function GetMBStr(s As String, ByRef mbs As PSTR) As SIZE_T
|
---|
146 | Return GetStr(s.StrPtr, s.Length As SIZE_T, mbs)
|
---|
147 | End Function
|
---|
148 |
|
---|
149 | Function GetTCStr(psz As PSTR, ByRef tcs As PCTSTR) As SIZE_T
|
---|
150 | Return GetStr(psz, tcs)
|
---|
151 | End Function
|
---|
152 |
|
---|
153 | Function GetTCStr(psz As PSTR, len As SIZE_T, ByRef tcs As PCTSTR) As SIZE_T
|
---|
154 | Return GetStr(psz, len, tcs)
|
---|
155 | End Function
|
---|
156 |
|
---|
157 | Function GetTCStr(psz As PWSTR, ByRef tcs As PCTSTR) As SIZE_T
|
---|
158 | Return GetStr(psz, tcs)
|
---|
159 | End Function
|
---|
160 |
|
---|
161 | Function GetTCStr(psz As PWSTR, len As SIZE_T, ByRef tcs As PCTSTR) As SIZE_T
|
---|
162 | Return GetStr(psz, len, tcs)
|
---|
163 | End Function
|
---|
164 |
|
---|
165 | Function GetTCStr(s As String, ByRef tcs As PCTSTR) As SIZE_T
|
---|
166 | Return GetStr(s.StrPtr, s.Length As SIZE_T, tcs)
|
---|
167 | End Function
|
---|
168 |
|
---|
169 | Function GetSCStr(psz As PSTR, ByRef ss As *StrChar) As SIZE_T
|
---|
170 | Return GetStr(psz, ss)
|
---|
171 | End Function
|
---|
172 |
|
---|
173 | Function GetSCStr(psz As PSTR, len As SIZE_T, ByRef ss As *StrChar) As SIZE_T
|
---|
174 | Return GetStr(psz, len, ss)
|
---|
175 | End Function
|
---|
176 |
|
---|
177 | Function GetSCStr(psz As PWSTR, ByRef ss As *StrChar) As SIZE_T
|
---|
178 | Return GetStr(psz, ss)
|
---|
179 | End Function
|
---|
180 |
|
---|
181 | Function GetSCStr(psz As PWSTR, len As SIZE_T, ByRef ss As *StrChar) As SIZE_T
|
---|
182 | Return GetStr(psz, len, ss)
|
---|
183 | End Function
|
---|
184 |
|
---|
185 | Function GetSCStr(s As String, ByRef ss As *StrChar) As SIZE_T
|
---|
186 | Return GetStr(s.StrPtr, s.Length As SIZE_T, ss)
|
---|
187 | End Function
|
---|
188 |
|
---|
189 | Function ToWCStr(psz As PSTR) As PWSTR
|
---|
190 | GetStr(psz, ToWCStr)
|
---|
191 | End Function
|
---|
192 |
|
---|
193 | Function ToWCStr(psz As PSTR, len As SIZE_T) As PWSTR
|
---|
194 | GetStr(psz, len, ToWCStr)
|
---|
195 | End Function
|
---|
196 |
|
---|
197 | Function ToWCStr(psz As PWSTR) As PWSTR
|
---|
198 | GetStr(psz, ToWCStr)
|
---|
199 | End Function
|
---|
200 |
|
---|
201 | Function ToWCStr(psz As PWSTR, len As SIZE_T) As PWSTR
|
---|
202 | GetStr(psz, len, ToWCStr)
|
---|
203 | End Function
|
---|
204 |
|
---|
205 | Function ToWCStr(s As String) As PWSTR
|
---|
206 | GetStr(s.StrPtr, s.Length As SIZE_T, ToWCStr)
|
---|
207 | End Function
|
---|
208 |
|
---|
209 | Function ToMBStr(psz As PSTR) As PSTR
|
---|
210 | GetStr(psz, ToMBStr)
|
---|
211 | End Function
|
---|
212 |
|
---|
213 | Function ToMBStr(psz As PSTR, len As SIZE_T) As PSTR
|
---|
214 | GetStr(psz, len, ToMBStr)
|
---|
215 | End Function
|
---|
216 |
|
---|
217 | Function ToMBStr(psz As PWSTR) As PSTR
|
---|
218 | GetStr(psz, ToMBStr)
|
---|
219 | End Function
|
---|
220 |
|
---|
221 | Function ToMBStr(psz As PWSTR, len As SIZE_T) As PSTR
|
---|
222 | GetStr(psz, len, ToMBStr)
|
---|
223 | End Function
|
---|
224 |
|
---|
225 | Function ToMBStr(s As String) As PSTR
|
---|
226 | GetStr(s.StrPtr, s.Length As SIZE_T, ToMBStr)
|
---|
227 | End Function
|
---|
228 |
|
---|
229 | Function ToTCStr(psz As PSTR) As PCTSTR
|
---|
230 | GetStr(psz, ToTCStr)
|
---|
231 | End Function
|
---|
232 |
|
---|
233 | Function ToTCStr(psz As PSTR, len As SIZE_T) As PCTSTR
|
---|
234 | GetStr(psz, len, ToTCStr)
|
---|
235 | End Function
|
---|
236 |
|
---|
237 | Function ToTCStr(psz As PWSTR) As PCTSTR
|
---|
238 | GetStr(psz, ToTCStr)
|
---|
239 | End Function
|
---|
240 |
|
---|
241 | Function ToTCStr(psz As PWSTR, len As SIZE_T) As PCTSTR
|
---|
242 | GetStr(psz, len, ToTCStr)
|
---|
243 | End Function
|
---|
244 |
|
---|
245 | Function ToTCStr(s As String) As PCTSTR
|
---|
246 | GetStr(s.StrPtr, s.Length As SIZE_T, ToTCStr)
|
---|
247 | End Function
|
---|
248 |
|
---|
249 | Function ToSCStr(psz As PSTR) As *StrChar
|
---|
250 | GetStr(psz, ToSCStr)
|
---|
251 | End Function
|
---|
252 |
|
---|
253 | Function ToSCStr(psz As PSTR, len As SIZE_T) As *StrChar
|
---|
254 | GetStr(psz, len, ToSCStr)
|
---|
255 | End Function
|
---|
256 |
|
---|
257 | Function ToSCStr(psz As PWSTR) As *StrChar
|
---|
258 | GetStr(psz, ToSCStr)
|
---|
259 | End Function
|
---|
260 |
|
---|
261 | Function ToSCStr(psz As PWSTR, len As SIZE_T) As *StrChar
|
---|
262 | GetStr(psz, len, ToSCStr)
|
---|
263 | End Function
|
---|
264 |
|
---|
265 | Function ToSCStr(s As String) As *StrChar
|
---|
266 | GetStr(s.StrPtr, s.Length As SIZE_T, ToSCStr)
|
---|
267 | End Function
|
---|
268 |
|
---|
269 | #ifdef __STRING_IS_NOT_UNICODE
|
---|
270 | Typedef BoxedStrChar = System.SByte
|
---|
271 | #else
|
---|
272 | TypeDef BoxedStrChar = System.UInt16
|
---|
273 | #endif
|
---|
274 |
|
---|
275 | #endif '_INC_BASIC_STRING
|
---|