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

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

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

File size: 8.5 KB
RevLine 
[1]1'string.sbp
2'文字列変数の操作用
3
4#ifndef _INC_BASIC_STRING
5#define _INC_BASIC_STRING
6
[478]7Function StrPtr(s As String) As *Char
[386]8 If Not ActiveBasic.IsNothing(s) Then
[385]9 StrPtr = s.StrPtr
10 End If
[1]11End Function
[303]12'StringBuilder版はClasses/System/Text/StringBuilder.abに定義されている
[1]13
[303]14Function ZeroString(length As Long) As System.Text.StringBuilder
15 ZeroString = New System.Text.StringBuilder
16 ZeroString.Length = length
[1]17End Function
18
[167]19Function MakeStr(psz As PSTR) As String
20 Return New String(psz)
[1]21End Function
22
[167]23Function MakeStr(psz As PWSTR) As String
24 Return New String(psz)
[142]25End Function
26
27Dim _System_AllocForConvertedString As *Function(size As SIZE_T) As VoidPtr
28_System_AllocForConvertedString = AddressOf (GC_malloc_atomic)
29
[395]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,
[478]61 GetWCStr, GetMBStr, GetTCStr,
62 ToWCStr, ToMBStr, ToTCStr,
63で、5 * 10 = 50通り。
[395]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
[142]70 Else
[395]71 Return Detail.GetWCStr(mbszSrc, lstrlenA(mbszSrc) As SIZE_T, wcsDst)
[142]72 End If
73End Function
74
[395]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
[142]82End Function
83
[395]84Function GetStr(wcszSrc As PWSTR, ByRef wcsDst As PWSTR) As SIZE_T
85 If wcszSrc = 0 Then
86 wcsDst = 0
87 Return 0
[142]88 Else
[395]89 wcsDst = wcszSrc
90 Return lstrlenW(wcszSrc) As SIZE_T
[142]91 End If
92End Function
93
[395]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
[149]100 Return len
[142]101 End If
102End Function
103
[395]104Function GetStr(wcszSrc As PWSTR, ByRef mbsDst As PSTR) As SIZE_T
105 If wcszSrc = 0 Then
106 mbsDst = 0
[142]107 Return 0
108 Else
[395]109 Return Detail.GetMBStr(wcszSrc, lstrlenW(wcszSrc) As SIZE_T, mbsDst)
[142]110 End If
111End Function
112
[395]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
[142]120End Function
121
[395]122Function GetStr(mbszSrc As PSTR, ByRef mbsDst As PSTR) As SIZE_T
123 If mbszSrc = 0 Then
124 mbsDst = 0
125 Return 0
[142]126 Else
[395]127 mbsDst = mbszSrc
128 Return lstrlenA(mbszSrc) As SIZE_T
[142]129 End If
130End Function
131
[395]132Function GetStr(mbsSrc As PSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
133 If mbsSrc = 0 Then
134 mbsDst = 0
[149]135 Return len
136 Else
[395]137 mbsDst = mbsSrc
[149]138 Return 0
139 End If
[142]140End Function
141
[395]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
[142]149End Function
150
[395]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
[142]158End Function
159
[395]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)
[142]202End Function
203
[395]204Function GetWCStr(mbsSrc As PSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
205 Return GetStr(mbsSrc, len, wcsDst)
[142]206End Function
207
[395]208Function GetWCStr(wcszSrc As PWSTR, ByRef wcsDst As PWSTR) As SIZE_T
209 Return GetStr(wcszSrc, wcsDst)
[142]210End Function
211
[395]212Function GetWCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
213 Return GetStr(wcsSrc, len, wcsDst)
[142]214End Function
215
[395]216Function GetWCStr(strSrc As String, ByRef wcsDst As PWSTR) As SIZE_T
217 Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, wcsDst)
[142]218End Function
219
[395]220Function GetMBStr(mbszSrc As PWSTR, ByRef mbsDst As PSTR) As SIZE_T
221 Return GetStr(mbszSrc, mbsDst)
[142]222End Function
223
[395]224Function GetMBStr(wcsSrc As PWSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
225 Return GetStr(wcsSrc, len, mbsDst)
[142]226End Function
227
[395]228Function GetMBStr(mbszSrc As PSTR, ByRef mbsDst As PSTR) As SIZE_T
229 Return GetStr(mbszSrc, mbsDst)
[142]230End Function
231
[395]232Function GetMBStr(mbsSrc As PSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
233 Return GetStr(mbsSrc, len, mbsDst)
[142]234End Function
235
[395]236Function GetMBStr(strSrc As String, ByRef mbsDst As PSTR) As SIZE_T
237 Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, mbsDst)
[142]238End Function
239
[395]240Function GetTCStr(mbszSrc As PSTR, ByRef tcsDst As PCTSTR) As SIZE_T
241 Return GetStr(mbszSrc, tcsDst)
[142]242End Function
243
[395]244Function GetTCStr(mbsSrc As PSTR, len As SIZE_T, ByRef tcsDst As PCTSTR) As SIZE_T
245 Return GetStr(mbsSrc, len, tcsDst)
[142]246End Function
247
[395]248Function GetTCStr(wcszSrc As PWSTR, ByRef tcsDst As PCTSTR) As SIZE_T
249 Return GetStr(wcszSrc, tcsDst)
[142]250End Function
251
[395]252Function GetTCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef tcsDst As PCTSTR) As SIZE_T
253 Return GetStr(wcsSrc, len, tcsDst)
[142]254End Function
255
[395]256Function GetTCStr(strSrc As String, ByRef tcsDst As PCTSTR) As SIZE_T
257 Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, tcsDst)
[142]258End Function
259
[395]260Function ToWCStr(mbsz As PSTR) As PWSTR
261 GetStrNT(mbsz, ToWCStr)
[142]262End Function
263
[395]264Function ToWCStr(mbs As PSTR, len As SIZE_T) As PWSTR
265 GetStrNT(mbs, len, ToWCStr)
[142]266End Function
267
[395]268Function ToWCStr(wcsz As PWSTR) As PWSTR
269 ToWCStr = wcsz
[142]270End Function
271
[395]272Function ToWCStr(wcs As PWSTR, len As SIZE_T) As PWSTR
273 ToWCStr = wcs
[142]274End Function
275
[237]276Function ToWCStr(s As String) As PWSTR
[395]277 GetStrNT(s, ToWCStr)
[142]278End Function
279
[395]280Function ToMBStr(mbsz As PSTR) As PSTR
281 ToMBStr = mbsz
[142]282End Function
283
[395]284Function ToMBStr(mbs As PSTR, len As SIZE_T) As PSTR
285 ToMBStr = mbs
[142]286End Function
287
[395]288Function ToMBStr(wcsz As PWSTR) As PSTR
289 GetStrNT(wcsz, ToMBStr)
[142]290End Function
291
[395]292Function ToMBStr(wcs As PWSTR, len As SIZE_T) As PSTR
293 GetStrNT(wcs, len, ToMBStr)
[142]294End Function
295
[237]296Function ToMBStr(s As String) As PSTR
[395]297 GetStrNT(s, ToMBStr)
[142]298End Function
299
[395]300Function ToTCStr(mbsz As PSTR) As PCTSTR
301 GetStrNT(mbsz, ToTCStr)
[142]302End Function
303
[395]304Function ToTCStr(mbs As PSTR, len As SIZE_T) As PCTSTR
305 GetStrNT(mbs, len, ToTCStr)
[142]306End Function
307
[395]308Function ToTCStr(wcsz As PWSTR) As PCTSTR
309 GetStrNT(wcsz, ToTCStr)
[142]310End Function
311
[395]312Function ToTCStr(wcs As PWSTR, len As SIZE_T) As PCTSTR
313 GetStrNT(wcs, len, ToTCStr)
[142]314End Function
315
[237]316Function ToTCStr(s As String) As PCTSTR
[395]317 GetStrNT(s, ToTCStr)
[142]318End Function
319
[398]320#ifndef UNICODE
[383]321Typedef BoxedStrChar = System.SByte
322#else
323TypeDef BoxedStrChar = System.UInt16
324#endif
325
[395]326#endif '_INC_BASIC_STRING
Note: See TracBrowser for help on using the repository browser.