source: trunk/Include/Classes/ActiveBasic/Strings/Strings.ab@ 497

Last change on this file since 497 was 497, checked in by イグトランス (egtra), 16 years ago

インクルードガードとその他不要な前処理定義などの削除

File size: 4.6 KB
Line 
1'Classes/ActiveBasic/Strings/Strings.ab
2
3Namespace ActiveBasic
4Namespace Strings
5
6Sub ChrFill(p As PWSTR, n As SIZE_T, c As WCHAR)
7 Dim i = 0 As SIZE_T
8 While i <> n
9 p[i] = c
10 i++
11 Wend
12End Sub
13
14Sub ChrFill(p As PSTR, n As SIZE_T, c As SByte)
15 Dim i = 0 As SIZE_T
16 While i <> n
17 p[i] = c
18 i++
19 Wend
20End Sub
21
22Function ChrCopy(dst As PCWSTR, src As PCWSTR, size As SIZE_T) As PCWSTR
23 memcpy(dst, src, size * SizeOf (WCHAR))
24 Return dst
25End Function
26
27Function ChrCopy(dst As PCSTR, src As PCSTR, size As SIZE_T) As PCSTR
28 memcpy(dst, src, size)
29 Return dst
30End Function
31
32Function ChrMove(dst As PCWSTR, src As PCWSTR, size As SIZE_T) As PCWSTR
33 MoveMemory(dst, src, size * SizeOf (WCHAR))
34 Return dst
35End Function
36
37Function ChrMove(dst As PCSTR, src As PCSTR, size As SIZE_T) As PCSTR
38 MoveMemory(dst, src, size)
39 Return dst
40End Function
41
42Function 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]
51End Function
52
53Function 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]
62End Function
63
64Function 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
73End Function
74
75Function 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
84End Function
85
86Function 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
89 ChrCmp = (( size1 - size2 ) As LONG_PTR) As Long
90 End If
91End Function
92
93Function 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
96 ChrCmp = (( size1 - size2 ) As LONG_PTR) As Long
97 End If
98End Function
99
100Function ChrPBrk(str As PCWSTR, cStr As SIZE_T, chars As PCWSTR, cChars As SIZE_T) As SIZE_T
101 Dim i = 0 As SIZE_T
102 While i <> cStr
103 If ChrFind(chars, cChars, str[i]) <> -1 Then
104 Return i
105 End If
106 i++
107 Wend
108 Return -1 As SIZE_T
109End Function
110
111Function ChrPBrk(str As PCSTR, cStr As SIZE_T, Chars As PCSTR, cChars As SIZE_T) As SIZE_T
112 Dim i = 0 As SIZE_T
113 While i <> cStr
114 If ChrFind(Chars, cChars, str[i]) <> -1 Then
115 Return i
116 End If
117 i++
118 Wend
119 Return -1 As SIZE_T
120End Function
121
122Function ChrFind(s As PCWSTR, size As SIZE_T, c As WCHAR) As SIZE_T
123 Dim i = 0 As SIZE_T
124 While i <> size
125 If s[i] = c Then
126 Return i
127 End If
128 i++
129 Wend
130 Return -1 As SIZE_T
131End Function
132
133Function ChrFind(s As PCSTR, size As SIZE_T, c As CHAR) As SIZE_T
134 Dim i = 0 As SIZE_T
135 While i <> size
136 If s[i] = c Then
137 Return i
138 End If
139 i++
140 Wend
141 Return -1 As SIZE_T
142End Function
143
144Function 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
166End Function
167
168Function 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
190End Function
191
192Namespace Detail
193Function Split(s As String, c As Char) As System.Collections.Generic.List<String>
194 Split = New System.Collections.Generic.List<String>
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
209End Function
210
211End Namespace 'Detail
212
213End Namespace 'Strings
214End Namespace 'ActiveBasic
215
Note: See TracBrowser for help on using the repository browser.