source: trunk/ab5.0/ablib/src/Classes/ActiveBasic/Strings/Strings.ab@ 581

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

Unicodeコンパイルで問題になる部分を修正

File size: 5.0 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 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
50End Function
51
52Function 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
60End Function
61
62Function 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]
71End Function
72
73Function 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]
82End Function
83
84Function 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
93End Function
94
95Function 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
104End Function
105
106Function 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
109 ChrCmp = (( size1 - size2 ) As LONG_PTR) As Long
110 End If
111End Function
112
113Function 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
116 ChrCmp = (( size1 - size2 ) As LONG_PTR) As Long
117 End If
118End Function
119
120Function ChrPBrk(str As PCWSTR, cStr As SIZE_T, chars As PCWSTR, cChars As SIZE_T) As SIZE_T
121 Dim i = 0 As SIZE_T
122 While i <> cStr
123 If ChrFind(chars, cChars, str[i]) <> -1 Then
124 Return i
125 End If
126 i++
127 Wend
128 Return -1 As SIZE_T
129End Function
130
131Function ChrPBrk(str As PCSTR, cStr As SIZE_T, Chars As PCSTR, cChars As SIZE_T) As SIZE_T
132 Dim i = 0 As SIZE_T
133 While i <> cStr
134 If ChrFind(Chars, cChars, str[i]) <> -1 Then
135 Return i
136 End If
137 i++
138 Wend
139 Return -1 As SIZE_T
140End Function
141
142Function ChrFind(s As PCWSTR, size As SIZE_T, c As WCHAR) As SIZE_T
143 Dim i = 0 As SIZE_T
144 While i <> size
145 If s[i] = c Then
146 Return i
147 End If
148 i++
149 Wend
150 Return -1 As SIZE_T
151End Function
152
153Function ChrFind(s As PCSTR, size As SIZE_T, c As CHAR) As SIZE_T
154 Dim i = 0 As SIZE_T
155 While i <> size
156 If s[i] = c Then
157 Return i
158 End If
159 i++
160 Wend
161 Return -1 As SIZE_T
162End Function
163
164Function 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
186End Function
187
188Function 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
210End Function
211
212Namespace Detail
213Function Split(s As String, c As Char) As System.Collections.Generic.IList<String>
214 Split = New System.Collections.Generic.List<String>
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
229End Function
230
231End Namespace 'Detail
232
233End Namespace 'Strings
234End Namespace 'ActiveBasic
235
Note: See TracBrowser for help on using the repository browser.