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

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

インクルードガードとその他不要な前処理定義などの削除

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