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