[1] | 1 | 'string.sbp
|
---|
| 2 | '文字列変数の操作用
|
---|
| 3 |
|
---|
[478] | 4 | Function StrPtr(s As String) As *Char
|
---|
[386] | 5 | If Not ActiveBasic.IsNothing(s) Then
|
---|
[385] | 6 | StrPtr = s.StrPtr
|
---|
| 7 | End If
|
---|
[1] | 8 | End Function
|
---|
[303] | 9 | 'StringBuilder版はClasses/System/Text/StringBuilder.abに定義されている
|
---|
[1] | 10 |
|
---|
[303] | 11 | Function ZeroString(length As Long) As System.Text.StringBuilder
|
---|
| 12 | ZeroString = New System.Text.StringBuilder
|
---|
| 13 | ZeroString.Length = length
|
---|
[1] | 14 | End Function
|
---|
| 15 |
|
---|
[167] | 16 | Function MakeStr(psz As PSTR) As String
|
---|
| 17 | Return New String(psz)
|
---|
[1] | 18 | End Function
|
---|
| 19 |
|
---|
[167] | 20 | Function MakeStr(psz As PWSTR) As String
|
---|
| 21 | Return New String(psz)
|
---|
[142] | 22 | End Function
|
---|
| 23 |
|
---|
| 24 | Dim _System_AllocForConvertedString As *Function(size As SIZE_T) As VoidPtr
|
---|
| 25 | _System_AllocForConvertedString = AddressOf (GC_malloc_atomic)
|
---|
| 26 |
|
---|
[395] | 27 | Namespace 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
|
---|
| 51 | End 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 |
|
---|
| 63 | Function 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
|
---|
| 70 | End Function
|
---|
| 71 |
|
---|
[395] | 72 | Function 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] | 79 | End Function
|
---|
| 80 |
|
---|
[395] | 81 | Function 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
|
---|
| 89 | End Function
|
---|
| 90 |
|
---|
[395] | 91 | Function 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
|
---|
| 99 | End Function
|
---|
| 100 |
|
---|
[395] | 101 | Function 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
|
---|
| 108 | End Function
|
---|
| 109 |
|
---|
[395] | 110 | Function 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] | 117 | End Function
|
---|
| 118 |
|
---|
[395] | 119 | Function 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
|
---|
| 127 | End Function
|
---|
| 128 |
|
---|
[395] | 129 | Function 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] | 137 | End Function
|
---|
| 138 |
|
---|
[395] | 139 | Function 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] | 146 | End Function
|
---|
| 147 |
|
---|
[395] | 148 | Function 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] | 155 | End Function
|
---|
| 156 |
|
---|
[395] | 157 | Sub GetStrNT(mbszSrc As PSTR, ByRef mbszDst As PSTR)
|
---|
| 158 | mbszDst = mbszSrc
|
---|
| 159 | End Sub
|
---|
| 160 |
|
---|
| 161 | Sub GetStrNT(mbsSrc As PSTR, len As SIZE_T, ByRef mbszDst As PSTR)
|
---|
| 162 | mbszDst = mbsSrc
|
---|
| 163 | End Sub
|
---|
| 164 |
|
---|
| 165 | Sub GetStrNT(mbszSrc As PSTR, ByRef wcszDst As PWSTR)
|
---|
| 166 | GetStr(mbszSrc, wcszDst)
|
---|
| 167 | End Sub
|
---|
| 168 |
|
---|
| 169 | Sub GetStrNT(mbsSrc As PSTR, len As SIZE_T, ByRef wcszDst As PWSTR)
|
---|
| 170 | GetStr(mbsSrc, len, wcszDst)
|
---|
| 171 | End Sub
|
---|
| 172 |
|
---|
| 173 | Sub GetStrNT(wcszSrc As PWSTR, ByRef mbszDst As PSTR)
|
---|
| 174 | GetStr(wcszSrc, mbszDst)
|
---|
| 175 | End Sub
|
---|
| 176 |
|
---|
| 177 | Sub GetStrNT(wcsSrc As PWSTR, len As SIZE_T, ByRef mbszDst As PSTR)
|
---|
| 178 | GetStr(wcsSrc, len, mbszDst)
|
---|
| 179 | End Sub
|
---|
| 180 |
|
---|
| 181 | Sub GetStrNT(wcszSrc As PWSTR, ByRef wcszDst As PWSTR)
|
---|
| 182 | wcszDst = wcszSrc
|
---|
| 183 | End Sub
|
---|
| 184 |
|
---|
| 185 | Sub GetStrNT(wcsSrc As PWSTR, len As SIZE_T, ByRef wcszDst As PWSTR)
|
---|
| 186 | wcszDst = wcsSrc
|
---|
| 187 | End Sub
|
---|
| 188 |
|
---|
| 189 | Sub GetStrNT(strSrc As String, ByRef mbszDst As PSTR)
|
---|
| 190 | GetStr(strSrc, mbszDst)
|
---|
| 191 | End Sub
|
---|
| 192 |
|
---|
| 193 | Sub GetStrNT(strSrc As String, ByRef wcszDst As PWSTR)
|
---|
| 194 | GetStr(strSrc, wcszDst)
|
---|
| 195 | End Sub
|
---|
| 196 |
|
---|
| 197 | Function GetWCStr(mbszSrc As PSTR, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
| 198 | Return GetStr(mbszSrc, wcsDst)
|
---|
[142] | 199 | End Function
|
---|
| 200 |
|
---|
[395] | 201 | Function GetWCStr(mbsSrc As PSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
| 202 | Return GetStr(mbsSrc, len, wcsDst)
|
---|
[142] | 203 | End Function
|
---|
| 204 |
|
---|
[395] | 205 | Function GetWCStr(wcszSrc As PWSTR, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
| 206 | Return GetStr(wcszSrc, wcsDst)
|
---|
[142] | 207 | End Function
|
---|
| 208 |
|
---|
[395] | 209 | Function GetWCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
| 210 | Return GetStr(wcsSrc, len, wcsDst)
|
---|
[142] | 211 | End Function
|
---|
| 212 |
|
---|
[395] | 213 | Function GetWCStr(strSrc As String, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
| 214 | Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, wcsDst)
|
---|
[142] | 215 | End Function
|
---|
| 216 |
|
---|
[395] | 217 | Function GetMBStr(mbszSrc As PWSTR, ByRef mbsDst As PSTR) As SIZE_T
|
---|
| 218 | Return GetStr(mbszSrc, mbsDst)
|
---|
[142] | 219 | End Function
|
---|
| 220 |
|
---|
[395] | 221 | Function GetMBStr(wcsSrc As PWSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
|
---|
| 222 | Return GetStr(wcsSrc, len, mbsDst)
|
---|
[142] | 223 | End Function
|
---|
| 224 |
|
---|
[395] | 225 | Function GetMBStr(mbszSrc As PSTR, ByRef mbsDst As PSTR) As SIZE_T
|
---|
| 226 | Return GetStr(mbszSrc, mbsDst)
|
---|
[142] | 227 | End Function
|
---|
| 228 |
|
---|
[395] | 229 | Function GetMBStr(mbsSrc As PSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
|
---|
| 230 | Return GetStr(mbsSrc, len, mbsDst)
|
---|
[142] | 231 | End Function
|
---|
| 232 |
|
---|
[395] | 233 | Function GetMBStr(strSrc As String, ByRef mbsDst As PSTR) As SIZE_T
|
---|
| 234 | Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, mbsDst)
|
---|
[142] | 235 | End Function
|
---|
| 236 |
|
---|
[395] | 237 | Function GetTCStr(mbszSrc As PSTR, ByRef tcsDst As PCTSTR) As SIZE_T
|
---|
| 238 | Return GetStr(mbszSrc, tcsDst)
|
---|
[142] | 239 | End Function
|
---|
| 240 |
|
---|
[395] | 241 | Function GetTCStr(mbsSrc As PSTR, len As SIZE_T, ByRef tcsDst As PCTSTR) As SIZE_T
|
---|
| 242 | Return GetStr(mbsSrc, len, tcsDst)
|
---|
[142] | 243 | End Function
|
---|
| 244 |
|
---|
[395] | 245 | Function GetTCStr(wcszSrc As PWSTR, ByRef tcsDst As PCTSTR) As SIZE_T
|
---|
| 246 | Return GetStr(wcszSrc, tcsDst)
|
---|
[142] | 247 | End Function
|
---|
| 248 |
|
---|
[395] | 249 | Function GetTCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef tcsDst As PCTSTR) As SIZE_T
|
---|
| 250 | Return GetStr(wcsSrc, len, tcsDst)
|
---|
[142] | 251 | End Function
|
---|
| 252 |
|
---|
[395] | 253 | Function GetTCStr(strSrc As String, ByRef tcsDst As PCTSTR) As SIZE_T
|
---|
| 254 | Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, tcsDst)
|
---|
[142] | 255 | End Function
|
---|
| 256 |
|
---|
[395] | 257 | Function ToWCStr(mbsz As PSTR) As PWSTR
|
---|
| 258 | GetStrNT(mbsz, ToWCStr)
|
---|
[142] | 259 | End Function
|
---|
| 260 |
|
---|
[395] | 261 | Function ToWCStr(mbs As PSTR, len As SIZE_T) As PWSTR
|
---|
| 262 | GetStrNT(mbs, len, ToWCStr)
|
---|
[142] | 263 | End Function
|
---|
| 264 |
|
---|
[395] | 265 | Function ToWCStr(wcsz As PWSTR) As PWSTR
|
---|
| 266 | ToWCStr = wcsz
|
---|
[142] | 267 | End Function
|
---|
| 268 |
|
---|
[395] | 269 | Function ToWCStr(wcs As PWSTR, len As SIZE_T) As PWSTR
|
---|
| 270 | ToWCStr = wcs
|
---|
[142] | 271 | End Function
|
---|
| 272 |
|
---|
[237] | 273 | Function ToWCStr(s As String) As PWSTR
|
---|
[395] | 274 | GetStrNT(s, ToWCStr)
|
---|
[142] | 275 | End Function
|
---|
| 276 |
|
---|
[395] | 277 | Function ToMBStr(mbsz As PSTR) As PSTR
|
---|
| 278 | ToMBStr = mbsz
|
---|
[142] | 279 | End Function
|
---|
| 280 |
|
---|
[395] | 281 | Function ToMBStr(mbs As PSTR, len As SIZE_T) As PSTR
|
---|
| 282 | ToMBStr = mbs
|
---|
[142] | 283 | End Function
|
---|
| 284 |
|
---|
[395] | 285 | Function ToMBStr(wcsz As PWSTR) As PSTR
|
---|
| 286 | GetStrNT(wcsz, ToMBStr)
|
---|
[142] | 287 | End Function
|
---|
| 288 |
|
---|
[395] | 289 | Function ToMBStr(wcs As PWSTR, len As SIZE_T) As PSTR
|
---|
| 290 | GetStrNT(wcs, len, ToMBStr)
|
---|
[142] | 291 | End Function
|
---|
| 292 |
|
---|
[237] | 293 | Function ToMBStr(s As String) As PSTR
|
---|
[395] | 294 | GetStrNT(s, ToMBStr)
|
---|
[142] | 295 | End Function
|
---|
| 296 |
|
---|
[395] | 297 | Function ToTCStr(mbsz As PSTR) As PCTSTR
|
---|
| 298 | GetStrNT(mbsz, ToTCStr)
|
---|
[142] | 299 | End Function
|
---|
| 300 |
|
---|
[395] | 301 | Function ToTCStr(mbs As PSTR, len As SIZE_T) As PCTSTR
|
---|
| 302 | GetStrNT(mbs, len, ToTCStr)
|
---|
[142] | 303 | End Function
|
---|
| 304 |
|
---|
[395] | 305 | Function ToTCStr(wcsz As PWSTR) As PCTSTR
|
---|
| 306 | GetStrNT(wcsz, ToTCStr)
|
---|
[142] | 307 | End Function
|
---|
| 308 |
|
---|
[395] | 309 | Function ToTCStr(wcs As PWSTR, len As SIZE_T) As PCTSTR
|
---|
| 310 | GetStrNT(wcs, len, ToTCStr)
|
---|
[142] | 311 | End Function
|
---|
| 312 |
|
---|
[237] | 313 | Function ToTCStr(s As String) As PCTSTR
|
---|
[395] | 314 | GetStrNT(s, ToTCStr)
|
---|
[142] | 315 | End Function
|
---|
| 316 |
|
---|
[398] | 317 | #ifndef UNICODE
|
---|
[497] | 318 | TypeDef BoxedStrChar = System.SByte
|
---|
[383] | 319 | #else
|
---|
| 320 | TypeDef BoxedStrChar = System.UInt16
|
---|
| 321 | #endif
|
---|