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

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

(SPrintF.ab) FormatIntegerExにStringBuilderを引数に取る版を追加。

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