[1] | 1 | 'string.sbp
|
---|
| 2 | '文字列変数の操作用
|
---|
| 3 |
|
---|
| 4 | #ifndef _INC_BASIC_STRING
|
---|
| 5 | #define _INC_BASIC_STRING
|
---|
| 6 |
|
---|
[303] | 7 | #require <Classes/System/String.ab>
|
---|
| 8 | #require <Classes/System/Text/StringBuilder.ab>
|
---|
| 9 |
|
---|
[272] | 10 | Function StrPtr(s As String) As *StrChar
|
---|
[386] | 11 | If Not ActiveBasic.IsNothing(s) Then
|
---|
[385] | 12 | StrPtr = s.StrPtr
|
---|
| 13 | End If
|
---|
[1] | 14 | End Function
|
---|
[303] | 15 | 'StringBuilder版はClasses/System/Text/StringBuilder.abに定義されている
|
---|
[1] | 16 |
|
---|
[303] | 17 | Function ZeroString(length As Long) As System.Text.StringBuilder
|
---|
| 18 | ZeroString = New System.Text.StringBuilder
|
---|
| 19 | ZeroString.Length = length
|
---|
[1] | 20 | End Function
|
---|
| 21 |
|
---|
[167] | 22 | Function MakeStr(psz As PSTR) As String
|
---|
| 23 | Return New String(psz)
|
---|
[1] | 24 | End Function
|
---|
| 25 |
|
---|
[167] | 26 | Function MakeStr(psz As PWSTR) As String
|
---|
| 27 | Return New String(psz)
|
---|
[142] | 28 | End Function
|
---|
| 29 |
|
---|
| 30 | Dim _System_AllocForConvertedString As *Function(size As SIZE_T) As VoidPtr
|
---|
| 31 | _System_AllocForConvertedString = AddressOf (GC_malloc_atomic)
|
---|
| 32 |
|
---|
| 33 | Function GetStr(psz As PSTR, ByRef wcs As PWSTR) As SIZE_T
|
---|
| 34 | If psz <> 0 Then
|
---|
[175] | 35 | Return GetStr(psz, lstrlenA(psz) As SIZE_T, wcs)
|
---|
[142] | 36 | Else
|
---|
| 37 | Return 0
|
---|
| 38 | End If
|
---|
| 39 | End Function
|
---|
| 40 |
|
---|
| 41 | Function GetStr(psz As PSTR, len As SIZE_T, ByRef wcs As PWSTR) As SIZE_T
|
---|
| 42 | If psz = 0 Then Return 0
|
---|
[385] | 43 | Dim lenWCS = MultiByteToWideChar(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, 0, 0)
|
---|
[192] | 44 | wcs = _System_AllocForConvertedString(SizeOf (WCHAR) * (lenWCS + 1)) As PWSTR
|
---|
[385] | 45 | GetStr = MultiByteToWideChar(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, wcs, lenWCS)
|
---|
[149] | 46 | wcs[GetStr] = 0
|
---|
[142] | 47 | End Function
|
---|
| 48 |
|
---|
| 49 | Function GetStr(psz As PWSTR, ByRef wcs As PWSTR) As SIZE_T
|
---|
| 50 | wcs = psz
|
---|
| 51 | If psz <> 0 Then
|
---|
[175] | 52 | Return lstrlenW(psz) As SIZE_T
|
---|
[142] | 53 | Else
|
---|
| 54 | Return 0
|
---|
| 55 | End If
|
---|
| 56 | End Function
|
---|
| 57 |
|
---|
| 58 | Function GetStr(psz As PWSTR, len As SIZE_T, ByRef wcs As PWSTR) As SIZE_T
|
---|
| 59 | wcs = psz
|
---|
| 60 | If psz <> 0 Then
|
---|
[149] | 61 | Return len
|
---|
[142] | 62 | Else
|
---|
| 63 | Return 0
|
---|
| 64 | End If
|
---|
| 65 | End Function
|
---|
| 66 |
|
---|
| 67 | Function GetStr(psz As PWSTR, ByRef mbs As PSTR) As SIZE_T
|
---|
| 68 | If psz = 0 Then
|
---|
| 69 | Return 0
|
---|
| 70 | Else
|
---|
[175] | 71 | Return GetStr(psz, lstrlenW(psz) As SIZE_T, mbs)
|
---|
[142] | 72 | End If
|
---|
| 73 | End Function
|
---|
| 74 |
|
---|
| 75 | Function GetStr(psz As PWSTR, len As SIZE_T, ByRef mbs As PSTR) As SIZE_T
|
---|
| 76 | If psz = 0 Then Return 0
|
---|
[385] | 77 | Dim lenMBS = WideCharToMultiByte(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, 0, 0, 0, 0)
|
---|
[192] | 78 | mbs = _System_AllocForConvertedString(SizeOf (SByte) * (lenMBS + 1)) As PSTR
|
---|
[385] | 79 | GetStr = WideCharToMultiByte(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, mbs, lenMBS, 0, 0) As SIZE_T
|
---|
[142] | 80 | mbs[GetStr] = 0
|
---|
| 81 | End Function
|
---|
| 82 |
|
---|
| 83 | Function GetStr(psz As PSTR, ByRef mbs As PSTR) As SIZE_T
|
---|
| 84 | mbs = psz
|
---|
| 85 | If psz <> 0 Then
|
---|
[175] | 86 | Return lstrlenA(psz) As SIZE_T
|
---|
[142] | 87 | Else
|
---|
| 88 | Return 0
|
---|
| 89 | End If
|
---|
| 90 | End Function
|
---|
| 91 |
|
---|
| 92 | Function GetStr(psz As PSTR, len As SIZE_T, ByRef mbs As PSTR) As SIZE_T
|
---|
| 93 | mbs = psz
|
---|
[149] | 94 | If psz <> 0 Then
|
---|
| 95 | Return len
|
---|
| 96 | Else
|
---|
| 97 | Return 0
|
---|
| 98 | End If
|
---|
[142] | 99 | End Function
|
---|
| 100 |
|
---|
[237] | 101 | Function GetStr(s As String, ByRef mbs As PSTR) As SIZE_T
|
---|
[272] | 102 | Return GetStr(s.StrPtr, s.Length As SIZE_T, mbs)
|
---|
[142] | 103 | End Function
|
---|
| 104 |
|
---|
[237] | 105 | Function GetStr(s As String, ByRef wcs As PWSTR) As SIZE_T
|
---|
[272] | 106 | Return GetStr(s.StrPtr, s.Length As SIZE_T, wcs)
|
---|
[142] | 107 | End Function
|
---|
| 108 |
|
---|
| 109 | Function GetWCStr(psz As PSTR, ByRef wcs As PWSTR) As SIZE_T
|
---|
| 110 | Return GetStr(psz, wcs)
|
---|
| 111 | End Function
|
---|
| 112 |
|
---|
| 113 | Function GetWCStr(psz As PSTR, len As SIZE_T, ByRef wcs As PWSTR) As SIZE_T
|
---|
| 114 | Return GetStr(psz, len, wcs)
|
---|
| 115 | End Function
|
---|
| 116 |
|
---|
| 117 | Function GetWCStr(psz As PWSTR, ByRef wcs As PWSTR) As SIZE_T
|
---|
| 118 | Return GetStr(psz, wcs)
|
---|
| 119 | End Function
|
---|
| 120 |
|
---|
| 121 | Function GetWCStr(psz As PWSTR, len As SIZE_T, ByRef wcs As PWSTR) As SIZE_T
|
---|
| 122 | Return GetStr(psz, len, wcs)
|
---|
| 123 | End Function
|
---|
| 124 |
|
---|
[237] | 125 | Function GetWCStr(s As String, ByRef wcs As PWSTR) As SIZE_T
|
---|
[272] | 126 | Return GetStr(s.StrPtr, s.Length As SIZE_T, wcs)
|
---|
[142] | 127 | End Function
|
---|
| 128 |
|
---|
| 129 | Function GetMBStr(psz As PWSTR, ByRef mbs As PSTR) As SIZE_T
|
---|
| 130 | Return GetStr(psz, mbs)
|
---|
| 131 | End Function
|
---|
| 132 |
|
---|
| 133 | Function GetMBStr(psz As PWSTR, len As SIZE_T, ByRef mbs As PSTR) As SIZE_T
|
---|
| 134 | Return GetStr(psz, len, mbs)
|
---|
| 135 | End Function
|
---|
| 136 |
|
---|
| 137 | Function GetMBStr(psz As PSTR, ByRef mbs As PSTR) As SIZE_T
|
---|
| 138 | Return GetStr(psz, mbs)
|
---|
| 139 | End Function
|
---|
| 140 |
|
---|
| 141 | Function GetMBStr(psz As PSTR, len As SIZE_T, ByRef mbs As PSTR) As SIZE_T
|
---|
| 142 | Return GetStr(psz, len, mbs)
|
---|
| 143 | End Function
|
---|
| 144 |
|
---|
[237] | 145 | Function GetMBStr(s As String, ByRef mbs As PSTR) As SIZE_T
|
---|
[272] | 146 | Return GetStr(s.StrPtr, s.Length As SIZE_T, mbs)
|
---|
[142] | 147 | End Function
|
---|
| 148 |
|
---|
| 149 | Function GetTCStr(psz As PSTR, ByRef tcs As PCTSTR) As SIZE_T
|
---|
| 150 | Return GetStr(psz, tcs)
|
---|
| 151 | End Function
|
---|
| 152 |
|
---|
| 153 | Function GetTCStr(psz As PSTR, len As SIZE_T, ByRef tcs As PCTSTR) As SIZE_T
|
---|
| 154 | Return GetStr(psz, len, tcs)
|
---|
| 155 | End Function
|
---|
| 156 |
|
---|
| 157 | Function GetTCStr(psz As PWSTR, ByRef tcs As PCTSTR) As SIZE_T
|
---|
| 158 | Return GetStr(psz, tcs)
|
---|
| 159 | End Function
|
---|
| 160 |
|
---|
| 161 | Function GetTCStr(psz As PWSTR, len As SIZE_T, ByRef tcs As PCTSTR) As SIZE_T
|
---|
| 162 | Return GetStr(psz, len, tcs)
|
---|
| 163 | End Function
|
---|
| 164 |
|
---|
[237] | 165 | Function GetTCStr(s As String, ByRef tcs As PCTSTR) As SIZE_T
|
---|
[272] | 166 | Return GetStr(s.StrPtr, s.Length As SIZE_T, tcs)
|
---|
[142] | 167 | End Function
|
---|
| 168 |
|
---|
| 169 | Function GetSCStr(psz As PSTR, ByRef ss As *StrChar) As SIZE_T
|
---|
| 170 | Return GetStr(psz, ss)
|
---|
| 171 | End Function
|
---|
| 172 |
|
---|
| 173 | Function GetSCStr(psz As PSTR, len As SIZE_T, ByRef ss As *StrChar) As SIZE_T
|
---|
| 174 | Return GetStr(psz, len, ss)
|
---|
| 175 | End Function
|
---|
| 176 |
|
---|
| 177 | Function GetSCStr(psz As PWSTR, ByRef ss As *StrChar) As SIZE_T
|
---|
| 178 | Return GetStr(psz, ss)
|
---|
| 179 | End Function
|
---|
| 180 |
|
---|
| 181 | Function GetSCStr(psz As PWSTR, len As SIZE_T, ByRef ss As *StrChar) As SIZE_T
|
---|
| 182 | Return GetStr(psz, len, ss)
|
---|
| 183 | End Function
|
---|
| 184 |
|
---|
[237] | 185 | Function GetSCStr(s As String, ByRef ss As *StrChar) As SIZE_T
|
---|
[272] | 186 | Return GetStr(s.StrPtr, s.Length As SIZE_T, ss)
|
---|
[142] | 187 | End Function
|
---|
| 188 |
|
---|
| 189 | Function ToWCStr(psz As PSTR) As PWSTR
|
---|
[149] | 190 | GetStr(psz, ToWCStr)
|
---|
[142] | 191 | End Function
|
---|
| 192 |
|
---|
| 193 | Function ToWCStr(psz As PSTR, len As SIZE_T) As PWSTR
|
---|
[149] | 194 | GetStr(psz, len, ToWCStr)
|
---|
[142] | 195 | End Function
|
---|
| 196 |
|
---|
| 197 | Function ToWCStr(psz As PWSTR) As PWSTR
|
---|
[149] | 198 | GetStr(psz, ToWCStr)
|
---|
[142] | 199 | End Function
|
---|
| 200 |
|
---|
| 201 | Function ToWCStr(psz As PWSTR, len As SIZE_T) As PWSTR
|
---|
[149] | 202 | GetStr(psz, len, ToWCStr)
|
---|
[142] | 203 | End Function
|
---|
| 204 |
|
---|
[237] | 205 | Function ToWCStr(s As String) As PWSTR
|
---|
[272] | 206 | GetStr(s.StrPtr, s.Length As SIZE_T, ToWCStr)
|
---|
[142] | 207 | End Function
|
---|
| 208 |
|
---|
| 209 | Function ToMBStr(psz As PSTR) As PSTR
|
---|
[149] | 210 | GetStr(psz, ToMBStr)
|
---|
[142] | 211 | End Function
|
---|
| 212 |
|
---|
| 213 | Function ToMBStr(psz As PSTR, len As SIZE_T) As PSTR
|
---|
[149] | 214 | GetStr(psz, len, ToMBStr)
|
---|
[142] | 215 | End Function
|
---|
| 216 |
|
---|
| 217 | Function ToMBStr(psz As PWSTR) As PSTR
|
---|
[149] | 218 | GetStr(psz, ToMBStr)
|
---|
[142] | 219 | End Function
|
---|
| 220 |
|
---|
| 221 | Function ToMBStr(psz As PWSTR, len As SIZE_T) As PSTR
|
---|
[149] | 222 | GetStr(psz, len, ToMBStr)
|
---|
[142] | 223 | End Function
|
---|
| 224 |
|
---|
[237] | 225 | Function ToMBStr(s As String) As PSTR
|
---|
[272] | 226 | GetStr(s.StrPtr, s.Length As SIZE_T, ToMBStr)
|
---|
[142] | 227 | End Function
|
---|
| 228 |
|
---|
| 229 | Function ToTCStr(psz As PSTR) As PCTSTR
|
---|
[149] | 230 | GetStr(psz, ToTCStr)
|
---|
[142] | 231 | End Function
|
---|
| 232 |
|
---|
| 233 | Function ToTCStr(psz As PSTR, len As SIZE_T) As PCTSTR
|
---|
[149] | 234 | GetStr(psz, len, ToTCStr)
|
---|
[142] | 235 | End Function
|
---|
| 236 |
|
---|
| 237 | Function ToTCStr(psz As PWSTR) As PCTSTR
|
---|
[149] | 238 | GetStr(psz, ToTCStr)
|
---|
[142] | 239 | End Function
|
---|
| 240 |
|
---|
| 241 | Function ToTCStr(psz As PWSTR, len As SIZE_T) As PCTSTR
|
---|
[149] | 242 | GetStr(psz, len, ToTCStr)
|
---|
[142] | 243 | End Function
|
---|
| 244 |
|
---|
[237] | 245 | Function ToTCStr(s As String) As PCTSTR
|
---|
[272] | 246 | GetStr(s.StrPtr, s.Length As SIZE_T, ToTCStr)
|
---|
[142] | 247 | End Function
|
---|
| 248 |
|
---|
| 249 | Function ToSCStr(psz As PSTR) As *StrChar
|
---|
[149] | 250 | GetStr(psz, ToSCStr)
|
---|
[142] | 251 | End Function
|
---|
| 252 |
|
---|
| 253 | Function ToSCStr(psz As PSTR, len As SIZE_T) As *StrChar
|
---|
[149] | 254 | GetStr(psz, len, ToSCStr)
|
---|
[142] | 255 | End Function
|
---|
| 256 |
|
---|
| 257 | Function ToSCStr(psz As PWSTR) As *StrChar
|
---|
[149] | 258 | GetStr(psz, ToSCStr)
|
---|
[142] | 259 | End Function
|
---|
| 260 |
|
---|
| 261 | Function ToSCStr(psz As PWSTR, len As SIZE_T) As *StrChar
|
---|
[149] | 262 | GetStr(psz, len, ToSCStr)
|
---|
[142] | 263 | End Function
|
---|
| 264 |
|
---|
[237] | 265 | Function ToSCStr(s As String) As *StrChar
|
---|
[272] | 266 | GetStr(s.StrPtr, s.Length As SIZE_T, ToSCStr)
|
---|
[142] | 267 | End Function
|
---|
| 268 |
|
---|
[383] | 269 | #ifdef __STRING_IS_NOT_UNICODE
|
---|
| 270 | Typedef BoxedStrChar = System.SByte
|
---|
| 271 | #else
|
---|
| 272 | TypeDef BoxedStrChar = System.UInt16
|
---|
| 273 | #endif
|
---|
| 274 |
|
---|
[1] | 275 | #endif '_INC_BASIC_STRING
|
---|