[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
|
---|
[654] | 29 | Dim lenWCS = MultiByteToWideChar(CP_ACP, 0, mbsSrc, (len As DWord) As Long, 0, 0)
|
---|
[652] | 30 | wcsDst = _System_AllocForConvertedString(SizeOf (WCHAR) * lenWCS) As PWSTR
|
---|
[654] | 31 | GetWCStr = MultiByteToWideChar(CP_ACP, 0, mbsSrc, (len As DWord) As Long, wcsDst, lenWCS)
|
---|
[395] | 32 | End Function
|
---|
| 33 |
|
---|
| 34 | Function GetWCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
| 35 | wcsDst = wcsSrc
|
---|
| 36 | GetWCStr = len
|
---|
| 37 | End Function
|
---|
| 38 |
|
---|
| 39 | Function GetMBStr(wcsSrc As PWSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
|
---|
[654] | 40 | Dim lenMBS = WideCharToMultiByte(CP_ACP, 0, wcsSrc, (len As DWord) As Long, 0, 0, 0, 0)
|
---|
[652] | 41 | mbsDst = _System_AllocForConvertedString(SizeOf (CHAR) * lenMBS) As PSTR
|
---|
[654] | 42 | GetMBStr = WideCharToMultiByte(CP_ACP, 0, wcsSrc, (wcsSrc As DWord) As Long, mbsDst, lenMBS, 0, 0) As SIZE_T
|
---|
[395] | 43 | End Function
|
---|
| 44 |
|
---|
| 45 | Function GetMBStr(mbsSrc As PSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
|
---|
| 46 | mbsDst = mbsSrc
|
---|
| 47 | GetMBStr = len
|
---|
| 48 | End Function
|
---|
[652] | 49 |
|
---|
| 50 | ' ToTCStrの補助
|
---|
| 51 | Sub GetStrNT(mbszSrc As PSTR, ByRef mbszDst As PSTR)
|
---|
| 52 | mbszDst = mbszSrc
|
---|
| 53 | End Sub
|
---|
| 54 |
|
---|
| 55 | Sub GetStrNT(mbszSrc As PSTR, ByRef wcszDst As PWSTR)
|
---|
| 56 | GetStr(mbszSrc, wcszDst)
|
---|
| 57 | End Sub
|
---|
| 58 |
|
---|
| 59 | Sub GetStrNT(wcszSrc As PWSTR, ByRef mbszDst As PSTR)
|
---|
| 60 | GetStr(wcszSrc, mbszDst)
|
---|
| 61 | End Sub
|
---|
| 62 |
|
---|
| 63 | Sub GetStrNT(wcszSrc As PWSTR, ByRef wcszDst As PWSTR)
|
---|
| 64 | wcszDst = wcszSrc
|
---|
| 65 | End Sub
|
---|
| 66 |
|
---|
[395] | 67 | End Namespace
|
---|
| 68 |
|
---|
| 69 | /*
|
---|
| 70 | 変換の組み合わせは、
|
---|
| 71 | 入力引数: wcsz, wcs + len, mbsz, mbs + len, str
|
---|
| 72 | 出力関数: wcs(z)出力GetStr, mbs(z)出力GetStr,
|
---|
[478] | 73 | GetWCStr, GetMBStr, GetTCStr,
|
---|
| 74 | ToWCStr, ToMBStr, ToTCStr,
|
---|
[652] | 75 | で、5 * 8 = 40通り。
|
---|
[395] | 76 | */
|
---|
| 77 |
|
---|
| 78 | Function GetStr(mbszSrc As PSTR, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
| 79 | If mbszSrc = 0 Then
|
---|
| 80 | wcsDst = 0
|
---|
| 81 | Return 0
|
---|
[142] | 82 | Else
|
---|
[652] | 83 | Return Detail.GetWCStr(mbszSrc, (lstrlenA(mbszSrc) + 1) As SIZE_T, wcsDst)
|
---|
[142] | 84 | End If
|
---|
| 85 | End Function
|
---|
| 86 |
|
---|
[395] | 87 | Function GetStr(mbsSrc As PSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
| 88 | If mbsSrc = 0 Then
|
---|
| 89 | wcsDst = 0
|
---|
| 90 | Return 0
|
---|
| 91 | Else
|
---|
| 92 | Return Detail.GetWCStr(mbsSrc, len, wcsDst)
|
---|
| 93 | End If
|
---|
[142] | 94 | End Function
|
---|
| 95 |
|
---|
[395] | 96 | Function GetStr(wcszSrc As PWSTR, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
| 97 | If wcszSrc = 0 Then
|
---|
| 98 | wcsDst = 0
|
---|
| 99 | Return 0
|
---|
[142] | 100 | Else
|
---|
[395] | 101 | wcsDst = wcszSrc
|
---|
[652] | 102 | Return lstrlenW(wcszSrc) As SIZE_T + 1
|
---|
[142] | 103 | End If
|
---|
| 104 | End Function
|
---|
| 105 |
|
---|
[395] | 106 | Function GetStr(wcsSrc As PWSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
| 107 | If wcsSrc = 0 Then
|
---|
| 108 | wcsDst = 0
|
---|
| 109 | Return 0
|
---|
| 110 | Else
|
---|
| 111 | wcsDst = wcsSrc
|
---|
[149] | 112 | Return len
|
---|
[142] | 113 | End If
|
---|
| 114 | End Function
|
---|
| 115 |
|
---|
[395] | 116 | Function GetStr(wcszSrc As PWSTR, ByRef mbsDst As PSTR) As SIZE_T
|
---|
| 117 | If wcszSrc = 0 Then
|
---|
| 118 | mbsDst = 0
|
---|
[142] | 119 | Return 0
|
---|
| 120 | Else
|
---|
[652] | 121 | Return Detail.GetMBStr(wcszSrc, (lstrlenW(wcszSrc) + 1) As SIZE_T, mbsDst)
|
---|
[142] | 122 | End If
|
---|
| 123 | End Function
|
---|
| 124 |
|
---|
[395] | 125 | Function GetStr(wcsSrc As PWSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
|
---|
| 126 | If wcsSrc = 0 Then
|
---|
| 127 | mbsDst = 0
|
---|
| 128 | Return 0
|
---|
| 129 | Else
|
---|
| 130 | Return Detail.GetMBStr(wcsSrc, len As SIZE_T, mbsDst)
|
---|
| 131 | End If
|
---|
[142] | 132 | End Function
|
---|
| 133 |
|
---|
[395] | 134 | Function GetStr(mbszSrc As PSTR, ByRef mbsDst As PSTR) As SIZE_T
|
---|
| 135 | If mbszSrc = 0 Then
|
---|
| 136 | mbsDst = 0
|
---|
| 137 | Return 0
|
---|
[142] | 138 | Else
|
---|
[395] | 139 | mbsDst = mbszSrc
|
---|
[652] | 140 | Return lstrlenA(mbszSrc) As SIZE_T + 1
|
---|
[142] | 141 | End If
|
---|
| 142 | End Function
|
---|
| 143 |
|
---|
[395] | 144 | Function GetStr(mbsSrc As PSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
|
---|
| 145 | If mbsSrc = 0 Then
|
---|
| 146 | mbsDst = 0
|
---|
[149] | 147 | Return len
|
---|
| 148 | Else
|
---|
[395] | 149 | mbsDst = mbsSrc
|
---|
[149] | 150 | Return 0
|
---|
| 151 | End If
|
---|
[142] | 152 | End Function
|
---|
| 153 |
|
---|
[395] | 154 | Function GetStr(strSrc As String, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
| 155 | If ActiveBasic.IsNothing(strSrc) Then
|
---|
| 156 | wcsDst = 0
|
---|
| 157 | Return 0
|
---|
| 158 | Else
|
---|
| 159 | Return Detail.GetWCStr(strSrc.StrPtr, strSrc.Length As SIZE_T, wcsDst)
|
---|
| 160 | End If
|
---|
[142] | 161 | End Function
|
---|
| 162 |
|
---|
[395] | 163 | Function GetStr(strSrc As String, ByRef mbsDst As PSTR) As SIZE_T
|
---|
| 164 | If ActiveBasic.IsNothing(strSrc) Then
|
---|
| 165 | mbsDst = 0
|
---|
| 166 | Return 0
|
---|
| 167 | Else
|
---|
| 168 | Return Detail.GetMBStr(strSrc.StrPtr, strSrc.Length As SIZE_T, mbsDst)
|
---|
| 169 | End If
|
---|
[142] | 170 | End Function
|
---|
| 171 |
|
---|
[395] | 172 | Function GetWCStr(mbszSrc As PSTR, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
| 173 | Return GetStr(mbszSrc, wcsDst)
|
---|
[142] | 174 | End Function
|
---|
| 175 |
|
---|
[395] | 176 | Function GetWCStr(mbsSrc As PSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
| 177 | Return GetStr(mbsSrc, len, wcsDst)
|
---|
[142] | 178 | End Function
|
---|
| 179 |
|
---|
[395] | 180 | Function GetWCStr(wcszSrc As PWSTR, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
| 181 | Return GetStr(wcszSrc, wcsDst)
|
---|
[142] | 182 | End Function
|
---|
| 183 |
|
---|
[395] | 184 | Function GetWCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
| 185 | Return GetStr(wcsSrc, len, wcsDst)
|
---|
[142] | 186 | End Function
|
---|
| 187 |
|
---|
[395] | 188 | Function GetWCStr(strSrc As String, ByRef wcsDst As PWSTR) As SIZE_T
|
---|
| 189 | Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, wcsDst)
|
---|
[142] | 190 | End Function
|
---|
| 191 |
|
---|
[395] | 192 | Function GetMBStr(mbszSrc As PWSTR, ByRef mbsDst As PSTR) As SIZE_T
|
---|
| 193 | Return GetStr(mbszSrc, mbsDst)
|
---|
[142] | 194 | End Function
|
---|
| 195 |
|
---|
[395] | 196 | Function GetMBStr(wcsSrc As PWSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
|
---|
| 197 | Return GetStr(wcsSrc, len, mbsDst)
|
---|
[142] | 198 | End Function
|
---|
| 199 |
|
---|
[395] | 200 | Function GetMBStr(mbszSrc As PSTR, ByRef mbsDst As PSTR) As SIZE_T
|
---|
| 201 | Return GetStr(mbszSrc, mbsDst)
|
---|
[142] | 202 | End Function
|
---|
| 203 |
|
---|
[395] | 204 | Function GetMBStr(mbsSrc As PSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
|
---|
| 205 | Return GetStr(mbsSrc, len, mbsDst)
|
---|
[142] | 206 | End Function
|
---|
| 207 |
|
---|
[395] | 208 | Function GetMBStr(strSrc As String, ByRef mbsDst As PSTR) As SIZE_T
|
---|
| 209 | Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, mbsDst)
|
---|
[142] | 210 | End Function
|
---|
| 211 |
|
---|
[395] | 212 | Function GetTCStr(mbszSrc As PSTR, ByRef tcsDst As PCTSTR) As SIZE_T
|
---|
| 213 | Return GetStr(mbszSrc, tcsDst)
|
---|
[142] | 214 | End Function
|
---|
| 215 |
|
---|
[395] | 216 | Function GetTCStr(mbsSrc As PSTR, len As SIZE_T, ByRef tcsDst As PCTSTR) As SIZE_T
|
---|
| 217 | Return GetStr(mbsSrc, len, tcsDst)
|
---|
[142] | 218 | End Function
|
---|
| 219 |
|
---|
[395] | 220 | Function GetTCStr(wcszSrc As PWSTR, ByRef tcsDst As PCTSTR) As SIZE_T
|
---|
| 221 | Return GetStr(wcszSrc, tcsDst)
|
---|
[142] | 222 | End Function
|
---|
| 223 |
|
---|
[395] | 224 | Function GetTCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef tcsDst As PCTSTR) As SIZE_T
|
---|
| 225 | Return GetStr(wcsSrc, len, tcsDst)
|
---|
[142] | 226 | End Function
|
---|
| 227 |
|
---|
[395] | 228 | Function GetTCStr(strSrc As String, ByRef tcsDst As PCTSTR) As SIZE_T
|
---|
| 229 | Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, tcsDst)
|
---|
[142] | 230 | End Function
|
---|
| 231 |
|
---|
[395] | 232 | Function ToWCStr(mbsz As PSTR) As PWSTR
|
---|
[652] | 233 | Detail.GetStrNT(mbsz, ToWCStr)
|
---|
[142] | 234 | End Function
|
---|
| 235 |
|
---|
[395] | 236 | Function ToWCStr(mbs As PSTR, len As SIZE_T) As PWSTR
|
---|
[652] | 237 | GetStr(mbs, len, ToWCStr)
|
---|
[142] | 238 | End Function
|
---|
| 239 |
|
---|
[395] | 240 | Function ToWCStr(wcsz As PWSTR) As PWSTR
|
---|
| 241 | ToWCStr = wcsz
|
---|
[142] | 242 | End Function
|
---|
| 243 |
|
---|
[395] | 244 | Function ToWCStr(wcs As PWSTR, len As SIZE_T) As PWSTR
|
---|
| 245 | ToWCStr = wcs
|
---|
[142] | 246 | End Function
|
---|
| 247 |
|
---|
[237] | 248 | Function ToWCStr(s As String) As PWSTR
|
---|
[652] | 249 | GetStr(s, ToWCStr)
|
---|
[142] | 250 | End Function
|
---|
| 251 |
|
---|
[395] | 252 | Function ToMBStr(mbsz As PSTR) As PSTR
|
---|
| 253 | ToMBStr = mbsz
|
---|
[142] | 254 | End Function
|
---|
| 255 |
|
---|
[395] | 256 | Function ToMBStr(mbs As PSTR, len As SIZE_T) As PSTR
|
---|
| 257 | ToMBStr = mbs
|
---|
[142] | 258 | End Function
|
---|
| 259 |
|
---|
[395] | 260 | Function ToMBStr(wcsz As PWSTR) As PSTR
|
---|
[652] | 261 | Detail.GetStrNT(wcsz, ToMBStr)
|
---|
[142] | 262 | End Function
|
---|
| 263 |
|
---|
[395] | 264 | Function ToMBStr(wcs As PWSTR, len As SIZE_T) As PSTR
|
---|
[652] | 265 | GetStr(wcs, len, ToMBStr)
|
---|
[142] | 266 | End Function
|
---|
| 267 |
|
---|
[237] | 268 | Function ToMBStr(s As String) As PSTR
|
---|
[652] | 269 | GetStr(s, ToMBStr)
|
---|
[142] | 270 | End Function
|
---|
| 271 |
|
---|
[395] | 272 | Function ToTCStr(mbsz As PSTR) As PCTSTR
|
---|
[652] | 273 | Detail.GetStrNT(mbsz, ToTCStr)
|
---|
[142] | 274 | End Function
|
---|
| 275 |
|
---|
[395] | 276 | Function ToTCStr(mbs As PSTR, len As SIZE_T) As PCTSTR
|
---|
[652] | 277 | GetStr(mbs, len, ToTCStr)
|
---|
[142] | 278 | End Function
|
---|
| 279 |
|
---|
[395] | 280 | Function ToTCStr(wcsz As PWSTR) As PCTSTR
|
---|
[652] | 281 | Detail.GetStrNT(wcsz, ToTCStr)
|
---|
[142] | 282 | End Function
|
---|
| 283 |
|
---|
[395] | 284 | Function ToTCStr(wcs As PWSTR, len As SIZE_T) As PCTSTR
|
---|
[652] | 285 | GetStr(wcs, len, ToTCStr)
|
---|
[142] | 286 | End Function
|
---|
| 287 |
|
---|
[237] | 288 | Function ToTCStr(s As String) As PCTSTR
|
---|
[652] | 289 | Return StrPtr(s)
|
---|
[142] | 290 | End Function
|
---|
| 291 |
|
---|
[398] | 292 | #ifndef UNICODE
|
---|
[497] | 293 | TypeDef BoxedStrChar = System.SByte
|
---|
[383] | 294 | #else
|
---|
| 295 | TypeDef BoxedStrChar = System.UInt16
|
---|
| 296 | #endif
|
---|