source: branch/egtra-stream-without-en_dec/system/string.sbp@ 673

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

Detail.GetMBStrでの誤りを修正

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