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