[272] | 1 | 'Classes/ActiveBasic/Strings/Strings.ab
|
---|
| 2 |
|
---|
| 3 | Namespace ActiveBasic
|
---|
| 4 | Namespace Strings
|
---|
| 5 |
|
---|
| 6 | Sub ChrFill(p As PWSTR, n As SIZE_T, c As WCHAR)
|
---|
[383] | 7 | Dim i = 0 As SIZE_T
|
---|
| 8 | While i <> n
|
---|
[272] | 9 | p[i] = c
|
---|
[383] | 10 | i++
|
---|
| 11 | Wend
|
---|
[272] | 12 | End Sub
|
---|
| 13 |
|
---|
| 14 | Sub ChrFill(p As PSTR, n As SIZE_T, c As SByte)
|
---|
[383] | 15 | Dim i = 0 As SIZE_T
|
---|
| 16 | While i <> n
|
---|
[272] | 17 | p[i] = c
|
---|
[383] | 18 | i++
|
---|
| 19 | Wend
|
---|
[272] | 20 | End Sub
|
---|
| 21 |
|
---|
| 22 | Function ChrCopy(dst As PCWSTR, src As PCWSTR, size As SIZE_T) As PCWSTR
|
---|
| 23 | memcpy(dst, src, size * SizeOf (WCHAR))
|
---|
| 24 | Return dst
|
---|
| 25 | End Function
|
---|
| 26 |
|
---|
| 27 | Function ChrCopy(dst As PCSTR, src As PCSTR, size As SIZE_T) As PCSTR
|
---|
| 28 | memcpy(dst, src, size)
|
---|
| 29 | Return dst
|
---|
| 30 | End Function
|
---|
| 31 |
|
---|
| 32 | Function ChrMove(dst As PCWSTR, src As PCWSTR, size As SIZE_T) As PCWSTR
|
---|
| 33 | MoveMemory(dst, src, size * SizeOf (WCHAR))
|
---|
| 34 | Return dst
|
---|
| 35 | End Function
|
---|
| 36 |
|
---|
| 37 | Function ChrMove(dst As PCSTR, src As PCSTR, size As SIZE_T) As PCSTR
|
---|
| 38 | MoveMemory(dst, src, size)
|
---|
| 39 | Return dst
|
---|
| 40 | End Function
|
---|
| 41 |
|
---|
[581] | 42 | Function StrCpy(dst As PCSTR, src As PCSTR) As PCSTR
|
---|
| 43 | StrCpy = dst
|
---|
| 44 | Dim i As SIZE_T
|
---|
| 45 | Do
|
---|
| 46 | dst[i] = src[i]
|
---|
| 47 | If src[i] = 0 Then Exit Do
|
---|
| 48 | i++
|
---|
| 49 | Loop
|
---|
| 50 | End Function
|
---|
| 51 |
|
---|
| 52 | Function StrCpy(dst As PCWSTR, src As PCWSTR) As PCWSTR
|
---|
| 53 | StrCpy = dst
|
---|
| 54 | Dim i As SIZE_T
|
---|
| 55 | Do
|
---|
| 56 | dst[i] = src[i]
|
---|
| 57 | If src[i] = 0 Then Exit Do
|
---|
| 58 | i++
|
---|
| 59 | Loop
|
---|
| 60 | End Function
|
---|
| 61 |
|
---|
[272] | 62 | Function StrCmp(s1 As PCWSTR, s2 As PCWSTR) As Long
|
---|
| 63 | Dim i = 0 As SIZE_T
|
---|
| 64 | While s1[i] = s2[i]
|
---|
| 65 | If s1[i] = 0 Then
|
---|
| 66 | Exit While
|
---|
| 67 | End If
|
---|
| 68 | i++
|
---|
| 69 | Wend
|
---|
| 70 | Return s1[i] As Long - s2[i]
|
---|
| 71 | End Function
|
---|
| 72 |
|
---|
| 73 | Function StrCmp(s1 As PCSTR, s2 As PCSTR) As Long
|
---|
| 74 | Dim i = 0 As SIZE_T
|
---|
| 75 | While s1[i] = s2[i]
|
---|
| 76 | If s1[i] = 0 Then
|
---|
| 77 | Exit While
|
---|
| 78 | End If
|
---|
| 79 | i++
|
---|
| 80 | Wend
|
---|
| 81 | Return s1[i] As Long - s2[i]
|
---|
| 82 | End Function
|
---|
| 83 |
|
---|
| 84 | Function ChrCmp(s1 As PCWSTR, s2 As PCWSTR, size As SIZE_T) As Long
|
---|
| 85 | Dim i = 0 As SIZE_T
|
---|
| 86 | While i <> size 'Forではsize = 0のときにまずい
|
---|
| 87 | ChrCmp = s1[i] As Long - s2[i]
|
---|
| 88 | If ChrCmp <> 0 Then
|
---|
| 89 | Exit Function
|
---|
| 90 | End If
|
---|
| 91 | i++
|
---|
| 92 | Wend
|
---|
| 93 | End Function
|
---|
| 94 |
|
---|
| 95 | Function ChrCmp(s1 As PCSTR, s2 As PCSTR, size As SIZE_T) As Long
|
---|
| 96 | Dim i = 0 As SIZE_T
|
---|
| 97 | While i <> size
|
---|
| 98 | ChrCmp = s1[i] As Long - s2[i]
|
---|
| 99 | If ChrCmp <> 0 Then
|
---|
| 100 | Exit Function
|
---|
| 101 | End If
|
---|
| 102 | i++
|
---|
| 103 | Wend
|
---|
| 104 | End Function
|
---|
| 105 |
|
---|
| 106 | Function ChrCmp(s1 As PCWSTR, size1 As SIZE_T, s2 As PCWSTR, size2 As SIZE_T) As Long
|
---|
| 107 | ChrCmp = ChrCmp(s1, s2, System.Math.Min(size1, size2))
|
---|
| 108 | If ChrCmp = 0 Then
|
---|
[385] | 109 | ChrCmp = (( size1 - size2 ) As LONG_PTR) As Long
|
---|
[272] | 110 | End If
|
---|
| 111 | End Function
|
---|
| 112 |
|
---|
| 113 | Function ChrCmp(s1 As PCSTR, size1 As SIZE_T, s2 As PCSTR, size2 As SIZE_T) As Long
|
---|
| 114 | ChrCmp = ChrCmp(s1, s2, System.Math.Min(size1, size2))
|
---|
| 115 | If ChrCmp = 0 Then
|
---|
[385] | 116 | ChrCmp = (( size1 - size2 ) As LONG_PTR) As Long
|
---|
[272] | 117 | End If
|
---|
| 118 | End Function
|
---|
| 119 |
|
---|
| 120 | Function ChrPBrk(str As PCWSTR, cStr As SIZE_T, chars As PCWSTR, cChars As SIZE_T) As SIZE_T
|
---|
[383] | 121 | Dim i = 0 As SIZE_T
|
---|
| 122 | While i <> cStr
|
---|
[272] | 123 | If ChrFind(chars, cChars, str[i]) <> -1 Then
|
---|
| 124 | Return i
|
---|
| 125 | End If
|
---|
[383] | 126 | i++
|
---|
| 127 | Wend
|
---|
[272] | 128 | Return -1 As SIZE_T
|
---|
| 129 | End Function
|
---|
| 130 |
|
---|
| 131 | Function ChrPBrk(str As PCSTR, cStr As SIZE_T, Chars As PCSTR, cChars As SIZE_T) As SIZE_T
|
---|
[383] | 132 | Dim i = 0 As SIZE_T
|
---|
| 133 | While i <> cStr
|
---|
[272] | 134 | If ChrFind(Chars, cChars, str[i]) <> -1 Then
|
---|
| 135 | Return i
|
---|
| 136 | End If
|
---|
[383] | 137 | i++
|
---|
| 138 | Wend
|
---|
[272] | 139 | Return -1 As SIZE_T
|
---|
| 140 | End Function
|
---|
| 141 |
|
---|
| 142 | Function ChrFind(s As PCWSTR, size As SIZE_T, c As WCHAR) As SIZE_T
|
---|
[383] | 143 | Dim i = 0 As SIZE_T
|
---|
| 144 | While i <> size
|
---|
[272] | 145 | If s[i] = c Then
|
---|
| 146 | Return i
|
---|
| 147 | End If
|
---|
[383] | 148 | i++
|
---|
| 149 | Wend
|
---|
[272] | 150 | Return -1 As SIZE_T
|
---|
| 151 | End Function
|
---|
| 152 |
|
---|
| 153 | Function ChrFind(s As PCSTR, size As SIZE_T, c As CHAR) As SIZE_T
|
---|
[383] | 154 | Dim i = 0 As SIZE_T
|
---|
| 155 | While i <> size
|
---|
[272] | 156 | If s[i] = c Then
|
---|
| 157 | Return i
|
---|
| 158 | End If
|
---|
[383] | 159 | i++
|
---|
| 160 | Wend
|
---|
[272] | 161 | Return -1 As SIZE_T
|
---|
| 162 | End Function
|
---|
| 163 |
|
---|
| 164 | Function ChrFind(s1 As PCWSTR, len1 As SIZE_T, s2 As PCWSTR, len2 As SIZE_T) As SIZE_T
|
---|
| 165 | If len2 = 0 Then
|
---|
| 166 | 'ChrFind = 0
|
---|
| 167 | Exit Function
|
---|
| 168 | End If
|
---|
| 169 | Do
|
---|
| 170 | Dim prev = ChrFind
|
---|
| 171 | ChrFind = ChrFind(VarPtr(s1[prev]), (len1 - prev) As SIZE_T, s2[0])
|
---|
| 172 | If ChrFind = -1 As SIZE_T Then
|
---|
| 173 | Exit Function
|
---|
| 174 | End If
|
---|
| 175 | ChrFind += prev
|
---|
| 176 |
|
---|
| 177 | If ChrCmp(VarPtr(s1[ChrFind]), s2, len2) = 0 Then
|
---|
| 178 | Exit Function
|
---|
| 179 | End If
|
---|
| 180 | ChrFind++
|
---|
| 181 | If ChrFind = len1 Then
|
---|
| 182 | ChrFind = -1
|
---|
| 183 | Exit Function
|
---|
| 184 | End If
|
---|
| 185 | Loop
|
---|
| 186 | End Function
|
---|
| 187 |
|
---|
| 188 | Function ChrFind(s1 As PCSTR, len1 As SIZE_T, s2 As PCSTR, len2 As SIZE_T) As SIZE_T
|
---|
| 189 | If len2 = 0 Then
|
---|
| 190 | 'ChrFind = 0
|
---|
| 191 | Exit Function
|
---|
| 192 | End If
|
---|
| 193 | Do
|
---|
| 194 | Dim prev = ChrFind
|
---|
| 195 | ChrFind = ChrFind(VarPtr(s1[prev]), (len1 - prev) As SIZE_T, s2[0])
|
---|
| 196 | If ChrFind = -1 As SIZE_T Then
|
---|
| 197 | Exit Function
|
---|
| 198 | End If
|
---|
| 199 | ChrFind += prev
|
---|
| 200 |
|
---|
| 201 | If ChrCmp(VarPtr(s1[ChrFind]), s2, len2) = 0 Then
|
---|
| 202 | Exit Function
|
---|
| 203 | End If
|
---|
| 204 | ChrFind++
|
---|
| 205 | If ChrFind = len1 Then
|
---|
| 206 | ChrFind = -1
|
---|
| 207 | Exit Function
|
---|
| 208 | End If
|
---|
| 209 | Loop
|
---|
| 210 | End Function
|
---|
| 211 |
|
---|
| 212 | Namespace Detail
|
---|
[581] | 213 | Function Split(s As String, c As Char) As System.Collections.Generic.IList<String>
|
---|
[391] | 214 | Split = New System.Collections.Generic.List<String>
|
---|
[272] | 215 |
|
---|
| 216 | Dim last = 0 As Long
|
---|
| 217 | Do
|
---|
| 218 | Dim i = s.IndexOf(c, last)
|
---|
| 219 | If i < 0 Then
|
---|
| 220 | Split.Add(s.Substring(last, s.Length - last))
|
---|
| 221 | Exit Function
|
---|
| 222 | End If
|
---|
| 223 | Split.Add(s.Substring(last, i - last))
|
---|
| 224 | last = i + 1
|
---|
| 225 | If last > s.Length Then
|
---|
| 226 | Split.Add(System.String.Empty)
|
---|
| 227 | End If
|
---|
| 228 | Loop
|
---|
| 229 | End Function
|
---|
[383] | 230 |
|
---|
[272] | 231 | End Namespace 'Detail
|
---|
| 232 |
|
---|
| 233 | End Namespace 'Strings
|
---|
| 234 | End Namespace 'ActiveBasic
|
---|
| 235 |
|
---|