[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 |
|
---|
| 42 | Function StrCmp(s1 As PCWSTR, s2 As PCWSTR) As Long
|
---|
| 43 | Dim i = 0 As SIZE_T
|
---|
| 44 | While s1[i] = s2[i]
|
---|
| 45 | If s1[i] = 0 Then
|
---|
| 46 | Exit While
|
---|
| 47 | End If
|
---|
| 48 | i++
|
---|
| 49 | Wend
|
---|
| 50 | Return s1[i] As Long - s2[i]
|
---|
| 51 | End Function
|
---|
| 52 |
|
---|
| 53 | Function StrCmp(s1 As PCSTR, s2 As PCSTR) As Long
|
---|
| 54 | Dim i = 0 As SIZE_T
|
---|
| 55 | While s1[i] = s2[i]
|
---|
| 56 | If s1[i] = 0 Then
|
---|
| 57 | Exit While
|
---|
| 58 | End If
|
---|
| 59 | i++
|
---|
| 60 | Wend
|
---|
| 61 | Return s1[i] As Long - s2[i]
|
---|
| 62 | End Function
|
---|
| 63 |
|
---|
| 64 | Function ChrCmp(s1 As PCWSTR, s2 As PCWSTR, size As SIZE_T) As Long
|
---|
| 65 | Dim i = 0 As SIZE_T
|
---|
| 66 | While i <> size 'Forではsize = 0のときにまずい
|
---|
| 67 | ChrCmp = s1[i] As Long - s2[i]
|
---|
| 68 | If ChrCmp <> 0 Then
|
---|
| 69 | Exit Function
|
---|
| 70 | End If
|
---|
| 71 | i++
|
---|
| 72 | Wend
|
---|
| 73 | End Function
|
---|
| 74 |
|
---|
| 75 | Function ChrCmp(s1 As PCSTR, s2 As PCSTR, size As SIZE_T) As Long
|
---|
| 76 | Dim i = 0 As SIZE_T
|
---|
| 77 | While i <> size
|
---|
| 78 | ChrCmp = s1[i] As Long - s2[i]
|
---|
| 79 | If ChrCmp <> 0 Then
|
---|
| 80 | Exit Function
|
---|
| 81 | End If
|
---|
| 82 | i++
|
---|
| 83 | Wend
|
---|
| 84 | End Function
|
---|
| 85 |
|
---|
| 86 | Function ChrCmp(s1 As PCWSTR, size1 As SIZE_T, s2 As PCWSTR, size2 As SIZE_T) As Long
|
---|
| 87 | ChrCmp = ChrCmp(s1, s2, System.Math.Min(size1, size2))
|
---|
| 88 | If ChrCmp = 0 Then
|
---|
[385] | 89 | ChrCmp = (( size1 - size2 ) As LONG_PTR) As Long
|
---|
[272] | 90 | End If
|
---|
| 91 | End Function
|
---|
| 92 |
|
---|
| 93 | Function ChrCmp(s1 As PCSTR, size1 As SIZE_T, s2 As PCSTR, size2 As SIZE_T) As Long
|
---|
| 94 | ChrCmp = ChrCmp(s1, s2, System.Math.Min(size1, size2))
|
---|
| 95 | If ChrCmp = 0 Then
|
---|
[385] | 96 | ChrCmp = (( size1 - size2 ) As LONG_PTR) As Long
|
---|
[272] | 97 | End If
|
---|
| 98 | End Function
|
---|
| 99 |
|
---|
| 100 | Function ChrPBrk(str As PCWSTR, cStr As SIZE_T, chars As PCWSTR, cChars As SIZE_T) As SIZE_T
|
---|
[383] | 101 | Dim i = 0 As SIZE_T
|
---|
| 102 | While i <> cStr
|
---|
[272] | 103 | If ChrFind(chars, cChars, str[i]) <> -1 Then
|
---|
| 104 | Return i
|
---|
| 105 | End If
|
---|
[383] | 106 | i++
|
---|
| 107 | Wend
|
---|
[272] | 108 | Return -1 As SIZE_T
|
---|
| 109 | End Function
|
---|
| 110 |
|
---|
| 111 | Function ChrPBrk(str As PCSTR, cStr As SIZE_T, Chars As PCSTR, cChars As SIZE_T) As SIZE_T
|
---|
[383] | 112 | Dim i = 0 As SIZE_T
|
---|
| 113 | While i <> cStr
|
---|
[272] | 114 | If ChrFind(Chars, cChars, str[i]) <> -1 Then
|
---|
| 115 | Return i
|
---|
| 116 | End If
|
---|
[383] | 117 | i++
|
---|
| 118 | Wend
|
---|
[272] | 119 | Return -1 As SIZE_T
|
---|
| 120 | End Function
|
---|
| 121 |
|
---|
| 122 | Function ChrFind(s As PCWSTR, size As SIZE_T, c As WCHAR) As SIZE_T
|
---|
[383] | 123 | Dim i = 0 As SIZE_T
|
---|
| 124 | While i <> size
|
---|
[272] | 125 | If s[i] = c Then
|
---|
| 126 | Return i
|
---|
| 127 | End If
|
---|
[383] | 128 | i++
|
---|
| 129 | Wend
|
---|
[272] | 130 | Return -1 As SIZE_T
|
---|
| 131 | End Function
|
---|
| 132 |
|
---|
| 133 | Function ChrFind(s As PCSTR, size As SIZE_T, c As CHAR) As SIZE_T
|
---|
[383] | 134 | Dim i = 0 As SIZE_T
|
---|
| 135 | While i <> size
|
---|
[272] | 136 | If s[i] = c Then
|
---|
| 137 | Return i
|
---|
| 138 | End If
|
---|
[383] | 139 | i++
|
---|
| 140 | Wend
|
---|
[272] | 141 | Return -1 As SIZE_T
|
---|
| 142 | End Function
|
---|
| 143 |
|
---|
| 144 | Function ChrFind(s1 As PCWSTR, len1 As SIZE_T, s2 As PCWSTR, len2 As SIZE_T) As SIZE_T
|
---|
| 145 | If len2 = 0 Then
|
---|
| 146 | 'ChrFind = 0
|
---|
| 147 | Exit Function
|
---|
| 148 | End If
|
---|
| 149 | Do
|
---|
| 150 | Dim prev = ChrFind
|
---|
| 151 | ChrFind = ChrFind(VarPtr(s1[prev]), (len1 - prev) As SIZE_T, s2[0])
|
---|
| 152 | If ChrFind = -1 As SIZE_T Then
|
---|
| 153 | Exit Function
|
---|
| 154 | End If
|
---|
| 155 | ChrFind += prev
|
---|
| 156 |
|
---|
| 157 | If ChrCmp(VarPtr(s1[ChrFind]), s2, len2) = 0 Then
|
---|
| 158 | Exit Function
|
---|
| 159 | End If
|
---|
| 160 | ChrFind++
|
---|
| 161 | If ChrFind = len1 Then
|
---|
| 162 | ChrFind = -1
|
---|
| 163 | Exit Function
|
---|
| 164 | End If
|
---|
| 165 | Loop
|
---|
| 166 | End Function
|
---|
| 167 |
|
---|
| 168 | Function ChrFind(s1 As PCSTR, len1 As SIZE_T, s2 As PCSTR, len2 As SIZE_T) As SIZE_T
|
---|
| 169 | If len2 = 0 Then
|
---|
| 170 | 'ChrFind = 0
|
---|
| 171 | Exit Function
|
---|
| 172 | End If
|
---|
| 173 | Do
|
---|
| 174 | Dim prev = ChrFind
|
---|
| 175 | ChrFind = ChrFind(VarPtr(s1[prev]), (len1 - prev) As SIZE_T, s2[0])
|
---|
| 176 | If ChrFind = -1 As SIZE_T Then
|
---|
| 177 | Exit Function
|
---|
| 178 | End If
|
---|
| 179 | ChrFind += prev
|
---|
| 180 |
|
---|
| 181 | If ChrCmp(VarPtr(s1[ChrFind]), s2, len2) = 0 Then
|
---|
| 182 | Exit Function
|
---|
| 183 | End If
|
---|
| 184 | ChrFind++
|
---|
| 185 | If ChrFind = len1 Then
|
---|
| 186 | ChrFind = -1
|
---|
| 187 | Exit Function
|
---|
| 188 | End If
|
---|
| 189 | Loop
|
---|
| 190 | End Function
|
---|
| 191 |
|
---|
| 192 | Namespace Detail
|
---|
[391] | 193 | Function Split(s As String, c As StrChar) As System.Collections.Generic.List<String>
|
---|
| 194 | Split = New System.Collections.Generic.List<String>
|
---|
[272] | 195 |
|
---|
| 196 | Dim last = 0 As Long
|
---|
| 197 | Do
|
---|
| 198 | Dim i = s.IndexOf(c, last)
|
---|
| 199 | If i < 0 Then
|
---|
| 200 | Split.Add(s.Substring(last, s.Length - last))
|
---|
| 201 | Exit Function
|
---|
| 202 | End If
|
---|
| 203 | Split.Add(s.Substring(last, i - last))
|
---|
| 204 | last = i + 1
|
---|
| 205 | If last > s.Length Then
|
---|
| 206 | Split.Add(System.String.Empty)
|
---|
| 207 | End If
|
---|
| 208 | Loop
|
---|
| 209 | End Function
|
---|
[383] | 210 |
|
---|
[272] | 211 | End Namespace 'Detail
|
---|
| 212 |
|
---|
| 213 | End Namespace 'Strings
|
---|
| 214 | End Namespace 'ActiveBasic
|
---|
| 215 |
|
---|