| 1 | 'string.sbp
|
|---|
| 2 | '文字列変数の操作用
|
|---|
| 3 |
|
|---|
| 4 | #ifndef _INC_BASIC_STRING
|
|---|
| 5 | #define _INC_BASIC_STRING
|
|---|
| 6 |
|
|---|
| 7 | Function StrPtr(s As String) As *Char
|
|---|
| 8 | If Not ActiveBasic.IsNothing(s) Then
|
|---|
| 9 | StrPtr = s.StrPtr
|
|---|
| 10 | End If
|
|---|
| 11 | End Function
|
|---|
| 12 | 'StringBuilder版はClasses/System/Text/StringBuilder.abに定義されている
|
|---|
| 13 |
|
|---|
| 14 | Function ZeroString(length As Long) As System.Text.StringBuilder
|
|---|
| 15 | ZeroString = New System.Text.StringBuilder
|
|---|
| 16 | ZeroString.Length = length
|
|---|
| 17 | End Function
|
|---|
| 18 |
|
|---|
| 19 | Function MakeStr(psz As PSTR) As String
|
|---|
| 20 | Return New String(psz)
|
|---|
| 21 | End Function
|
|---|
| 22 |
|
|---|
| 23 | Function MakeStr(psz As PWSTR) As String
|
|---|
| 24 | Return New String(psz)
|
|---|
| 25 | End Function
|
|---|
| 26 |
|
|---|
| 27 | Dim _System_AllocForConvertedString As *Function(size As SIZE_T) As VoidPtr
|
|---|
| 28 | _System_AllocForConvertedString = AddressOf (GC_malloc_atomic)
|
|---|
| 29 |
|
|---|
| 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,
|
|---|
| 61 | GetWCStr, GetMBStr, GetTCStr,
|
|---|
| 62 | ToWCStr, ToMBStr, ToTCStr,
|
|---|
| 63 | で、5 * 10 = 50通り。
|
|---|
| 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
|
|---|
| 70 | Else
|
|---|
| 71 | Return Detail.GetWCStr(mbszSrc, lstrlenA(mbszSrc) As SIZE_T, wcsDst)
|
|---|
| 72 | End If
|
|---|
| 73 | End Function
|
|---|
| 74 |
|
|---|
| 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
|
|---|
| 82 | End Function
|
|---|
| 83 |
|
|---|
| 84 | Function GetStr(wcszSrc As PWSTR, ByRef wcsDst As PWSTR) As SIZE_T
|
|---|
| 85 | If wcszSrc = 0 Then
|
|---|
| 86 | wcsDst = 0
|
|---|
| 87 | Return 0
|
|---|
| 88 | Else
|
|---|
| 89 | wcsDst = wcszSrc
|
|---|
| 90 | Return lstrlenW(wcszSrc) As SIZE_T
|
|---|
| 91 | End If
|
|---|
| 92 | End Function
|
|---|
| 93 |
|
|---|
| 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
|
|---|
| 100 | Return len
|
|---|
| 101 | End If
|
|---|
| 102 | End Function
|
|---|
| 103 |
|
|---|
| 104 | Function GetStr(wcszSrc As PWSTR, ByRef mbsDst As PSTR) As SIZE_T
|
|---|
| 105 | If wcszSrc = 0 Then
|
|---|
| 106 | mbsDst = 0
|
|---|
| 107 | Return 0
|
|---|
| 108 | Else
|
|---|
| 109 | Return Detail.GetMBStr(wcszSrc, lstrlenW(wcszSrc) As SIZE_T, mbsDst)
|
|---|
| 110 | End If
|
|---|
| 111 | End Function
|
|---|
| 112 |
|
|---|
| 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
|
|---|
| 120 | End Function
|
|---|
| 121 |
|
|---|
| 122 | Function GetStr(mbszSrc As PSTR, ByRef mbsDst As PSTR) As SIZE_T
|
|---|
| 123 | If mbszSrc = 0 Then
|
|---|
| 124 | mbsDst = 0
|
|---|
| 125 | Return 0
|
|---|
| 126 | Else
|
|---|
| 127 | mbsDst = mbszSrc
|
|---|
| 128 | Return lstrlenA(mbszSrc) As SIZE_T
|
|---|
| 129 | End If
|
|---|
| 130 | End Function
|
|---|
| 131 |
|
|---|
| 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
|
|---|
| 135 | Return len
|
|---|
| 136 | Else
|
|---|
| 137 | mbsDst = mbsSrc
|
|---|
| 138 | Return 0
|
|---|
| 139 | End If
|
|---|
| 140 | End Function
|
|---|
| 141 |
|
|---|
| 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
|
|---|
| 149 | End Function
|
|---|
| 150 |
|
|---|
| 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
|
|---|
| 158 | End Function
|
|---|
| 159 |
|
|---|
| 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)
|
|---|
| 202 | End Function
|
|---|
| 203 |
|
|---|
| 204 | Function GetWCStr(mbsSrc As PSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
|
|---|
| 205 | Return GetStr(mbsSrc, len, wcsDst)
|
|---|
| 206 | End Function
|
|---|
| 207 |
|
|---|
| 208 | Function GetWCStr(wcszSrc As PWSTR, ByRef wcsDst As PWSTR) As SIZE_T
|
|---|
| 209 | Return GetStr(wcszSrc, wcsDst)
|
|---|
| 210 | End Function
|
|---|
| 211 |
|
|---|
| 212 | Function GetWCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
|
|---|
| 213 | Return GetStr(wcsSrc, len, wcsDst)
|
|---|
| 214 | End Function
|
|---|
| 215 |
|
|---|
| 216 | Function GetWCStr(strSrc As String, ByRef wcsDst As PWSTR) As SIZE_T
|
|---|
| 217 | Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, wcsDst)
|
|---|
| 218 | End Function
|
|---|
| 219 |
|
|---|
| 220 | Function GetMBStr(mbszSrc As PWSTR, ByRef mbsDst As PSTR) As SIZE_T
|
|---|
| 221 | Return GetStr(mbszSrc, mbsDst)
|
|---|
| 222 | End Function
|
|---|
| 223 |
|
|---|
| 224 | Function GetMBStr(wcsSrc As PWSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
|
|---|
| 225 | Return GetStr(wcsSrc, len, mbsDst)
|
|---|
| 226 | End Function
|
|---|
| 227 |
|
|---|
| 228 | Function GetMBStr(mbszSrc As PSTR, ByRef mbsDst As PSTR) As SIZE_T
|
|---|
| 229 | Return GetStr(mbszSrc, mbsDst)
|
|---|
| 230 | End Function
|
|---|
| 231 |
|
|---|
| 232 | Function GetMBStr(mbsSrc As PSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
|
|---|
| 233 | Return GetStr(mbsSrc, len, mbsDst)
|
|---|
| 234 | End Function
|
|---|
| 235 |
|
|---|
| 236 | Function GetMBStr(strSrc As String, ByRef mbsDst As PSTR) As SIZE_T
|
|---|
| 237 | Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, mbsDst)
|
|---|
| 238 | End Function
|
|---|
| 239 |
|
|---|
| 240 | Function GetTCStr(mbszSrc As PSTR, ByRef tcsDst As PCTSTR) As SIZE_T
|
|---|
| 241 | Return GetStr(mbszSrc, tcsDst)
|
|---|
| 242 | End Function
|
|---|
| 243 |
|
|---|
| 244 | Function GetTCStr(mbsSrc As PSTR, len As SIZE_T, ByRef tcsDst As PCTSTR) As SIZE_T
|
|---|
| 245 | Return GetStr(mbsSrc, len, tcsDst)
|
|---|
| 246 | End Function
|
|---|
| 247 |
|
|---|
| 248 | Function GetTCStr(wcszSrc As PWSTR, ByRef tcsDst As PCTSTR) As SIZE_T
|
|---|
| 249 | Return GetStr(wcszSrc, tcsDst)
|
|---|
| 250 | End Function
|
|---|
| 251 |
|
|---|
| 252 | Function GetTCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef tcsDst As PCTSTR) As SIZE_T
|
|---|
| 253 | Return GetStr(wcsSrc, len, tcsDst)
|
|---|
| 254 | End Function
|
|---|
| 255 |
|
|---|
| 256 | Function GetTCStr(strSrc As String, ByRef tcsDst As PCTSTR) As SIZE_T
|
|---|
| 257 | Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, tcsDst)
|
|---|
| 258 | End Function
|
|---|
| 259 |
|
|---|
| 260 | Function ToWCStr(mbsz As PSTR) As PWSTR
|
|---|
| 261 | GetStrNT(mbsz, ToWCStr)
|
|---|
| 262 | End Function
|
|---|
| 263 |
|
|---|
| 264 | Function ToWCStr(mbs As PSTR, len As SIZE_T) As PWSTR
|
|---|
| 265 | GetStrNT(mbs, len, ToWCStr)
|
|---|
| 266 | End Function
|
|---|
| 267 |
|
|---|
| 268 | Function ToWCStr(wcsz As PWSTR) As PWSTR
|
|---|
| 269 | ToWCStr = wcsz
|
|---|
| 270 | End Function
|
|---|
| 271 |
|
|---|
| 272 | Function ToWCStr(wcs As PWSTR, len As SIZE_T) As PWSTR
|
|---|
| 273 | ToWCStr = wcs
|
|---|
| 274 | End Function
|
|---|
| 275 |
|
|---|
| 276 | Function ToWCStr(s As String) As PWSTR
|
|---|
| 277 | GetStrNT(s, ToWCStr)
|
|---|
| 278 | End Function
|
|---|
| 279 |
|
|---|
| 280 | Function ToMBStr(mbsz As PSTR) As PSTR
|
|---|
| 281 | ToMBStr = mbsz
|
|---|
| 282 | End Function
|
|---|
| 283 |
|
|---|
| 284 | Function ToMBStr(mbs As PSTR, len As SIZE_T) As PSTR
|
|---|
| 285 | ToMBStr = mbs
|
|---|
| 286 | End Function
|
|---|
| 287 |
|
|---|
| 288 | Function ToMBStr(wcsz As PWSTR) As PSTR
|
|---|
| 289 | GetStrNT(wcsz, ToMBStr)
|
|---|
| 290 | End Function
|
|---|
| 291 |
|
|---|
| 292 | Function ToMBStr(wcs As PWSTR, len As SIZE_T) As PSTR
|
|---|
| 293 | GetStrNT(wcs, len, ToMBStr)
|
|---|
| 294 | End Function
|
|---|
| 295 |
|
|---|
| 296 | Function ToMBStr(s As String) As PSTR
|
|---|
| 297 | GetStrNT(s, ToMBStr)
|
|---|
| 298 | End Function
|
|---|
| 299 |
|
|---|
| 300 | Function ToTCStr(mbsz As PSTR) As PCTSTR
|
|---|
| 301 | GetStrNT(mbsz, ToTCStr)
|
|---|
| 302 | End Function
|
|---|
| 303 |
|
|---|
| 304 | Function ToTCStr(mbs As PSTR, len As SIZE_T) As PCTSTR
|
|---|
| 305 | GetStrNT(mbs, len, ToTCStr)
|
|---|
| 306 | End Function
|
|---|
| 307 |
|
|---|
| 308 | Function ToTCStr(wcsz As PWSTR) As PCTSTR
|
|---|
| 309 | GetStrNT(wcsz, ToTCStr)
|
|---|
| 310 | End Function
|
|---|
| 311 |
|
|---|
| 312 | Function ToTCStr(wcs As PWSTR, len As SIZE_T) As PCTSTR
|
|---|
| 313 | GetStrNT(wcs, len, ToTCStr)
|
|---|
| 314 | End Function
|
|---|
| 315 |
|
|---|
| 316 | Function ToTCStr(s As String) As PCTSTR
|
|---|
| 317 | GetStrNT(s, ToTCStr)
|
|---|
| 318 | End Function
|
|---|
| 319 |
|
|---|
| 320 | #ifndef UNICODE
|
|---|
| 321 | Typedef BoxedStrChar = System.SByte
|
|---|
| 322 | #else
|
|---|
| 323 | TypeDef BoxedStrChar = System.UInt16
|
|---|
| 324 | #endif
|
|---|
| 325 |
|
|---|
| 326 | #endif '_INC_BASIC_STRING
|
|---|