source: trunk/ab5.0/ablib/src/system/string.sbp@ 654

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

CP_THREAD_ACPがWindows 2000以上限定のため、CP_ACPへ変更

File size: 7.7 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
[654]29 Dim lenWCS = MultiByteToWideChar(CP_ACP, 0, mbsSrc, (len As DWord) As Long, 0, 0)
[652]30 wcsDst = _System_AllocForConvertedString(SizeOf (WCHAR) * lenWCS) As PWSTR
[654]31 GetWCStr = MultiByteToWideChar(CP_ACP, 0, mbsSrc, (len As DWord) As Long, wcsDst, lenWCS)
[395]32 End Function
33
34 Function GetWCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
35 wcsDst = wcsSrc
36 GetWCStr = len
37 End Function
38
39 Function GetMBStr(wcsSrc As PWSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
[654]40 Dim lenMBS = WideCharToMultiByte(CP_ACP, 0, wcsSrc, (len As DWord) As Long, 0, 0, 0, 0)
[652]41 mbsDst = _System_AllocForConvertedString(SizeOf (CHAR) * lenMBS) As PSTR
[654]42 GetMBStr = WideCharToMultiByte(CP_ACP, 0, wcsSrc, (wcsSrc As DWord) As Long, mbsDst, lenMBS, 0, 0) As SIZE_T
[395]43 End Function
44
45 Function GetMBStr(mbsSrc As PSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
46 mbsDst = mbsSrc
47 GetMBStr = len
48 End Function
[652]49
50 ' ToTCStrの補助
51 Sub GetStrNT(mbszSrc As PSTR, ByRef mbszDst As PSTR)
52 mbszDst = mbszSrc
53 End Sub
54
55 Sub GetStrNT(mbszSrc As PSTR, ByRef wcszDst As PWSTR)
56 GetStr(mbszSrc, wcszDst)
57 End Sub
58
59 Sub GetStrNT(wcszSrc As PWSTR, ByRef mbszDst As PSTR)
60 GetStr(wcszSrc, mbszDst)
61 End Sub
62
63 Sub GetStrNT(wcszSrc As PWSTR, ByRef wcszDst As PWSTR)
64 wcszDst = wcszSrc
65 End Sub
66
[395]67End Namespace
68
69/*
70変換の組み合わせは、
71入力引数: wcsz, wcs + len, mbsz, mbs + len, str
72出力関数: wcs(z)出力GetStr, mbs(z)出力GetStr,
[478]73 GetWCStr, GetMBStr, GetTCStr,
74 ToWCStr, ToMBStr, ToTCStr,
[652]75で、5 * 8 = 40通り。
[395]76*/
77
78Function GetStr(mbszSrc As PSTR, ByRef wcsDst As PWSTR) As SIZE_T
79 If mbszSrc = 0 Then
80 wcsDst = 0
81 Return 0
[142]82 Else
[652]83 Return Detail.GetWCStr(mbszSrc, (lstrlenA(mbszSrc) + 1) As SIZE_T, wcsDst)
[142]84 End If
85End Function
86
[395]87Function GetStr(mbsSrc As PSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
88 If mbsSrc = 0 Then
89 wcsDst = 0
90 Return 0
91 Else
92 Return Detail.GetWCStr(mbsSrc, len, wcsDst)
93 End If
[142]94End Function
95
[395]96Function GetStr(wcszSrc As PWSTR, ByRef wcsDst As PWSTR) As SIZE_T
97 If wcszSrc = 0 Then
98 wcsDst = 0
99 Return 0
[142]100 Else
[395]101 wcsDst = wcszSrc
[652]102 Return lstrlenW(wcszSrc) As SIZE_T + 1
[142]103 End If
104End Function
105
[395]106Function GetStr(wcsSrc As PWSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
107 If wcsSrc = 0 Then
108 wcsDst = 0
109 Return 0
110 Else
111 wcsDst = wcsSrc
[149]112 Return len
[142]113 End If
114End Function
115
[395]116Function GetStr(wcszSrc As PWSTR, ByRef mbsDst As PSTR) As SIZE_T
117 If wcszSrc = 0 Then
118 mbsDst = 0
[142]119 Return 0
120 Else
[652]121 Return Detail.GetMBStr(wcszSrc, (lstrlenW(wcszSrc) + 1) As SIZE_T, mbsDst)
[142]122 End If
123End Function
124
[395]125Function GetStr(wcsSrc As PWSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
126 If wcsSrc = 0 Then
127 mbsDst = 0
128 Return 0
129 Else
130 Return Detail.GetMBStr(wcsSrc, len As SIZE_T, mbsDst)
131 End If
[142]132End Function
133
[395]134Function GetStr(mbszSrc As PSTR, ByRef mbsDst As PSTR) As SIZE_T
135 If mbszSrc = 0 Then
136 mbsDst = 0
137 Return 0
[142]138 Else
[395]139 mbsDst = mbszSrc
[652]140 Return lstrlenA(mbszSrc) As SIZE_T + 1
[142]141 End If
142End Function
143
[395]144Function GetStr(mbsSrc As PSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
145 If mbsSrc = 0 Then
146 mbsDst = 0
[149]147 Return len
148 Else
[395]149 mbsDst = mbsSrc
[149]150 Return 0
151 End If
[142]152End Function
153
[395]154Function GetStr(strSrc As String, ByRef wcsDst As PWSTR) As SIZE_T
155 If ActiveBasic.IsNothing(strSrc) Then
156 wcsDst = 0
157 Return 0
158 Else
159 Return Detail.GetWCStr(strSrc.StrPtr, strSrc.Length As SIZE_T, wcsDst)
160 End If
[142]161End Function
162
[395]163Function GetStr(strSrc As String, ByRef mbsDst As PSTR) As SIZE_T
164 If ActiveBasic.IsNothing(strSrc) Then
165 mbsDst = 0
166 Return 0
167 Else
168 Return Detail.GetMBStr(strSrc.StrPtr, strSrc.Length As SIZE_T, mbsDst)
169 End If
[142]170End Function
171
[395]172Function GetWCStr(mbszSrc As PSTR, ByRef wcsDst As PWSTR) As SIZE_T
173 Return GetStr(mbszSrc, wcsDst)
[142]174End Function
175
[395]176Function GetWCStr(mbsSrc As PSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
177 Return GetStr(mbsSrc, len, wcsDst)
[142]178End Function
179
[395]180Function GetWCStr(wcszSrc As PWSTR, ByRef wcsDst As PWSTR) As SIZE_T
181 Return GetStr(wcszSrc, wcsDst)
[142]182End Function
183
[395]184Function GetWCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
185 Return GetStr(wcsSrc, len, wcsDst)
[142]186End Function
187
[395]188Function GetWCStr(strSrc As String, ByRef wcsDst As PWSTR) As SIZE_T
189 Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, wcsDst)
[142]190End Function
191
[395]192Function GetMBStr(mbszSrc As PWSTR, ByRef mbsDst As PSTR) As SIZE_T
193 Return GetStr(mbszSrc, mbsDst)
[142]194End Function
195
[395]196Function GetMBStr(wcsSrc As PWSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
197 Return GetStr(wcsSrc, len, mbsDst)
[142]198End Function
199
[395]200Function GetMBStr(mbszSrc As PSTR, ByRef mbsDst As PSTR) As SIZE_T
201 Return GetStr(mbszSrc, mbsDst)
[142]202End Function
203
[395]204Function GetMBStr(mbsSrc As PSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
205 Return GetStr(mbsSrc, len, mbsDst)
[142]206End Function
207
[395]208Function GetMBStr(strSrc As String, ByRef mbsDst As PSTR) As SIZE_T
209 Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, mbsDst)
[142]210End Function
211
[395]212Function GetTCStr(mbszSrc As PSTR, ByRef tcsDst As PCTSTR) As SIZE_T
213 Return GetStr(mbszSrc, tcsDst)
[142]214End Function
215
[395]216Function GetTCStr(mbsSrc As PSTR, len As SIZE_T, ByRef tcsDst As PCTSTR) As SIZE_T
217 Return GetStr(mbsSrc, len, tcsDst)
[142]218End Function
219
[395]220Function GetTCStr(wcszSrc As PWSTR, ByRef tcsDst As PCTSTR) As SIZE_T
221 Return GetStr(wcszSrc, tcsDst)
[142]222End Function
223
[395]224Function GetTCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef tcsDst As PCTSTR) As SIZE_T
225 Return GetStr(wcsSrc, len, tcsDst)
[142]226End Function
227
[395]228Function GetTCStr(strSrc As String, ByRef tcsDst As PCTSTR) As SIZE_T
229 Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, tcsDst)
[142]230End Function
231
[395]232Function ToWCStr(mbsz As PSTR) As PWSTR
[652]233 Detail.GetStrNT(mbsz, ToWCStr)
[142]234End Function
235
[395]236Function ToWCStr(mbs As PSTR, len As SIZE_T) As PWSTR
[652]237 GetStr(mbs, len, ToWCStr)
[142]238End Function
239
[395]240Function ToWCStr(wcsz As PWSTR) As PWSTR
241 ToWCStr = wcsz
[142]242End Function
243
[395]244Function ToWCStr(wcs As PWSTR, len As SIZE_T) As PWSTR
245 ToWCStr = wcs
[142]246End Function
247
[237]248Function ToWCStr(s As String) As PWSTR
[652]249 GetStr(s, ToWCStr)
[142]250End Function
251
[395]252Function ToMBStr(mbsz As PSTR) As PSTR
253 ToMBStr = mbsz
[142]254End Function
255
[395]256Function ToMBStr(mbs As PSTR, len As SIZE_T) As PSTR
257 ToMBStr = mbs
[142]258End Function
259
[395]260Function ToMBStr(wcsz As PWSTR) As PSTR
[652]261 Detail.GetStrNT(wcsz, ToMBStr)
[142]262End Function
263
[395]264Function ToMBStr(wcs As PWSTR, len As SIZE_T) As PSTR
[652]265 GetStr(wcs, len, ToMBStr)
[142]266End Function
267
[237]268Function ToMBStr(s As String) As PSTR
[652]269 GetStr(s, ToMBStr)
[142]270End Function
271
[395]272Function ToTCStr(mbsz As PSTR) As PCTSTR
[652]273 Detail.GetStrNT(mbsz, ToTCStr)
[142]274End Function
275
[395]276Function ToTCStr(mbs As PSTR, len As SIZE_T) As PCTSTR
[652]277 GetStr(mbs, len, ToTCStr)
[142]278End Function
279
[395]280Function ToTCStr(wcsz As PWSTR) As PCTSTR
[652]281 Detail.GetStrNT(wcsz, ToTCStr)
[142]282End Function
283
[395]284Function ToTCStr(wcs As PWSTR, len As SIZE_T) As PCTSTR
[652]285 GetStr(wcs, len, ToTCStr)
[142]286End Function
287
[237]288Function ToTCStr(s As String) As PCTSTR
[652]289 Return StrPtr(s)
[142]290End Function
291
[398]292#ifndef UNICODE
[497]293TypeDef BoxedStrChar = System.SByte
[383]294#else
295TypeDef BoxedStrChar = System.UInt16
296#endif
Note: See TracBrowser for help on using the repository browser.