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

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

Detail.GetMBStrでの誤りを修正

File size: 8.0 KB
RevLine 
[1]1'string.sbp
2'文字列変数の操作用
3
[671]4/*!
5@brief Stringが内部で保持しているポインタを返す。
6@param[in] s 文字列。
7@return sの内部バッファへのポインタ、ただしsがNothingならNULL。
8*/
[478]9Function StrPtr(s As String) As *Char
[386]10 If Not ActiveBasic.IsNothing(s) Then
[385]11 StrPtr = s.StrPtr
12 End If
[1]13End Function
[671]14'StringBuilder版はClasses/System/Text/StringBuilder.abに定義されている。
[1]15
[671]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
[1]24
[671]25
[167]26Function MakeStr(psz As PSTR) As String
27 Return New String(psz)
[1]28End Function
29
[167]30Function MakeStr(psz As PWSTR) As String
31 Return New String(psz)
[142]32End Function
33
34Dim _System_AllocForConvertedString As *Function(size As SIZE_T) As VoidPtr
35_System_AllocForConvertedString = AddressOf (GC_malloc_atomic)
36
[395]37Namespace Detail
38 Function GetWCStr(mbsSrc As PSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
[654]39 Dim lenWCS = MultiByteToWideChar(CP_ACP, 0, mbsSrc, (len As DWord) As Long, 0, 0)
[652]40 wcsDst = _System_AllocForConvertedString(SizeOf (WCHAR) * lenWCS) As PWSTR
[654]41 GetWCStr = MultiByteToWideChar(CP_ACP, 0, mbsSrc, (len As DWord) As Long, wcsDst, lenWCS)
[395]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
[654]50 Dim lenMBS = WideCharToMultiByte(CP_ACP, 0, wcsSrc, (len As DWord) As Long, 0, 0, 0, 0)
[652]51 mbsDst = _System_AllocForConvertedString(SizeOf (CHAR) * lenMBS) As PSTR
[671]52 GetMBStr = WideCharToMultiByte(CP_ACP, 0, wcsSrc, (len As DWord) As Long, mbsDst, lenMBS, 0, 0) As SIZE_T
[395]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
[652]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
[395]77End Namespace
78
79/*
80変換の組み合わせは、
81入力引数: wcsz, wcs + len, mbsz, mbs + len, str
82出力関数: wcs(z)出力GetStr, mbs(z)出力GetStr,
[478]83 GetWCStr, GetMBStr, GetTCStr,
84 ToWCStr, ToMBStr, ToTCStr,
[652]85で、5 * 8 = 40通り。
[395]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
[142]92 Else
[652]93 Return Detail.GetWCStr(mbszSrc, (lstrlenA(mbszSrc) + 1) As SIZE_T, wcsDst)
[142]94 End If
95End Function
96
[395]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
[142]104End Function
105
[395]106Function GetStr(wcszSrc As PWSTR, ByRef wcsDst As PWSTR) As SIZE_T
107 If wcszSrc = 0 Then
108 wcsDst = 0
109 Return 0
[142]110 Else
[395]111 wcsDst = wcszSrc
[652]112 Return lstrlenW(wcszSrc) As SIZE_T + 1
[142]113 End If
114End Function
115
[395]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
[149]122 Return len
[142]123 End If
124End Function
125
[395]126Function GetStr(wcszSrc As PWSTR, ByRef mbsDst As PSTR) As SIZE_T
127 If wcszSrc = 0 Then
128 mbsDst = 0
[142]129 Return 0
130 Else
[652]131 Return Detail.GetMBStr(wcszSrc, (lstrlenW(wcszSrc) + 1) As SIZE_T, mbsDst)
[142]132 End If
133End Function
134
[395]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
[142]142End Function
143
[395]144Function GetStr(mbszSrc As PSTR, ByRef mbsDst As PSTR) As SIZE_T
145 If mbszSrc = 0 Then
146 mbsDst = 0
147 Return 0
[142]148 Else
[395]149 mbsDst = mbszSrc
[652]150 Return lstrlenA(mbszSrc) As SIZE_T + 1
[142]151 End If
152End Function
153
[395]154Function GetStr(mbsSrc As PSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
155 If mbsSrc = 0 Then
156 mbsDst = 0
[149]157 Return len
158 Else
[395]159 mbsDst = mbsSrc
[149]160 Return 0
161 End If
[142]162End Function
163
[395]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
[142]171End Function
172
[395]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
[142]180End Function
181
[395]182Function GetWCStr(mbszSrc As PSTR, ByRef wcsDst As PWSTR) As SIZE_T
183 Return GetStr(mbszSrc, wcsDst)
[142]184End Function
185
[395]186Function GetWCStr(mbsSrc As PSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
187 Return GetStr(mbsSrc, len, wcsDst)
[142]188End Function
189
[395]190Function GetWCStr(wcszSrc As PWSTR, ByRef wcsDst As PWSTR) As SIZE_T
191 Return GetStr(wcszSrc, wcsDst)
[142]192End Function
193
[395]194Function GetWCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
195 Return GetStr(wcsSrc, len, wcsDst)
[142]196End Function
197
[395]198Function GetWCStr(strSrc As String, ByRef wcsDst As PWSTR) As SIZE_T
199 Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, wcsDst)
[142]200End Function
201
[395]202Function GetMBStr(mbszSrc As PWSTR, ByRef mbsDst As PSTR) As SIZE_T
203 Return GetStr(mbszSrc, mbsDst)
[142]204End Function
205
[395]206Function GetMBStr(wcsSrc As PWSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
207 Return GetStr(wcsSrc, len, mbsDst)
[142]208End Function
209
[395]210Function GetMBStr(mbszSrc As PSTR, ByRef mbsDst As PSTR) As SIZE_T
211 Return GetStr(mbszSrc, mbsDst)
[142]212End Function
213
[395]214Function GetMBStr(mbsSrc As PSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
215 Return GetStr(mbsSrc, len, mbsDst)
[142]216End Function
217
[395]218Function GetMBStr(strSrc As String, ByRef mbsDst As PSTR) As SIZE_T
219 Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, mbsDst)
[142]220End Function
221
[395]222Function GetTCStr(mbszSrc As PSTR, ByRef tcsDst As PCTSTR) As SIZE_T
223 Return GetStr(mbszSrc, tcsDst)
[142]224End Function
225
[395]226Function GetTCStr(mbsSrc As PSTR, len As SIZE_T, ByRef tcsDst As PCTSTR) As SIZE_T
227 Return GetStr(mbsSrc, len, tcsDst)
[142]228End Function
229
[395]230Function GetTCStr(wcszSrc As PWSTR, ByRef tcsDst As PCTSTR) As SIZE_T
231 Return GetStr(wcszSrc, tcsDst)
[142]232End Function
233
[395]234Function GetTCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef tcsDst As PCTSTR) As SIZE_T
235 Return GetStr(wcsSrc, len, tcsDst)
[142]236End Function
237
[395]238Function GetTCStr(strSrc As String, ByRef tcsDst As PCTSTR) As SIZE_T
239 Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, tcsDst)
[142]240End Function
241
[395]242Function ToWCStr(mbsz As PSTR) As PWSTR
[652]243 Detail.GetStrNT(mbsz, ToWCStr)
[142]244End Function
245
[395]246Function ToWCStr(mbs As PSTR, len As SIZE_T) As PWSTR
[652]247 GetStr(mbs, len, ToWCStr)
[142]248End Function
249
[395]250Function ToWCStr(wcsz As PWSTR) As PWSTR
251 ToWCStr = wcsz
[142]252End Function
253
[395]254Function ToWCStr(wcs As PWSTR, len As SIZE_T) As PWSTR
255 ToWCStr = wcs
[142]256End Function
257
[237]258Function ToWCStr(s As String) As PWSTR
[652]259 GetStr(s, ToWCStr)
[142]260End Function
261
[395]262Function ToMBStr(mbsz As PSTR) As PSTR
263 ToMBStr = mbsz
[142]264End Function
265
[395]266Function ToMBStr(mbs As PSTR, len As SIZE_T) As PSTR
267 ToMBStr = mbs
[142]268End Function
269
[395]270Function ToMBStr(wcsz As PWSTR) As PSTR
[652]271 Detail.GetStrNT(wcsz, ToMBStr)
[142]272End Function
273
[395]274Function ToMBStr(wcs As PWSTR, len As SIZE_T) As PSTR
[652]275 GetStr(wcs, len, ToMBStr)
[142]276End Function
277
[237]278Function ToMBStr(s As String) As PSTR
[652]279 GetStr(s, ToMBStr)
[142]280End Function
281
[395]282Function ToTCStr(mbsz As PSTR) As PCTSTR
[652]283 Detail.GetStrNT(mbsz, ToTCStr)
[142]284End Function
285
[395]286Function ToTCStr(mbs As PSTR, len As SIZE_T) As PCTSTR
[652]287 GetStr(mbs, len, ToTCStr)
[142]288End Function
289
[395]290Function ToTCStr(wcsz As PWSTR) As PCTSTR
[652]291 Detail.GetStrNT(wcsz, ToTCStr)
[142]292End Function
293
[395]294Function ToTCStr(wcs As PWSTR, len As SIZE_T) As PCTSTR
[652]295 GetStr(wcs, len, ToTCStr)
[142]296End Function
297
[237]298Function ToTCStr(s As String) As PCTSTR
[652]299 Return StrPtr(s)
[142]300End Function
301
[398]302#ifndef UNICODE
[497]303TypeDef BoxedStrChar = System.SByte
[383]304#else
305TypeDef BoxedStrChar = System.UInt16
306#endif
Note: See TracBrowser for help on using the repository browser.