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