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