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