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

Last change on this file since 370 was 370, checked in by dai, 16 years ago

System.GCクラスを追加。
64ビットコンパイラで生じる警告を改修した。

File size: 4.8 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 As SIZE_T
14    For i = 0 To ELM(n)
15        p[i] = c
16    Next
17End Sub
18
19Sub ChrFill(p As PSTR, n As SIZE_T, c As SByte)
20    Dim i As SIZE_T
21    For i = 0 To ELM(n)
22        p[i] = c
23    Next
24End Sub
25
26Function ChrCopy(dst As PCWSTR, src As PCWSTR, size As SIZE_T) As PCWSTR
27    memcpy(dst, src, size * SizeOf (WCHAR))
28    Return dst
29End Function
30
31Function ChrCopy(dst As PCSTR, src As PCSTR, size As SIZE_T) As PCSTR
32    memcpy(dst, src, size)
33    Return dst
34End Function
35
36Function ChrMove(dst As PCWSTR, src As PCWSTR, size As SIZE_T) As PCWSTR
37    MoveMemory(dst, src, size * SizeOf (WCHAR))
38    Return dst
39End Function
40
41Function ChrMove(dst As PCSTR, src As PCSTR, size As SIZE_T) As PCSTR
42    MoveMemory(dst, src, size)
43    Return dst
44End Function
45
46Function StrCmp(s1 As PCWSTR, s2 As PCWSTR) As Long
47    Dim i = 0 As SIZE_T
48    While s1[i] = s2[i]
49        If s1[i] = 0 Then
50            Exit While
51        End If
52        i++
53    Wend
54    Return s1[i] As Long - s2[i]
55End Function
56
57Function StrCmp(s1 As PCSTR, s2 As PCSTR) As Long
58    Dim i = 0 As SIZE_T
59    While s1[i] = s2[i]
60        If s1[i] = 0 Then
61            Exit While
62        End If
63        i++
64    Wend
65    Return s1[i] As Long - s2[i]
66End Function
67
68
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
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
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 As SIZE_T
108    For i = 0 To ELM(cStr)
109        If ChrFind(chars, cChars, str[i]) <> -1 Then
110            Return i
111        End If
112    Next
113    Return -1 As SIZE_T
114End Function
115
116Function ChrPBrk(str As PCSTR, cStr As SIZE_T, Chars As PCSTR, cChars As SIZE_T) As SIZE_T
117    Dim i As SIZE_T
118    For i = 0 To ELM(cStr)
119        If ChrFind(Chars, cChars, str[i]) <> -1 Then
120            Return i
121        End If
122    Next
123    Return -1 As SIZE_T
124End Function
125
126Function ChrFind(s As PCWSTR, size As SIZE_T, c As WCHAR) As SIZE_T
127    Dim i As SIZE_T
128    For i = 0 To ELM(size)
129        If s[i] = c Then
130            Return i
131        End If
132    Next
133    Return -1 As SIZE_T
134End Function
135
136Function ChrFind(s As PCSTR, size As SIZE_T, c As CHAR) As SIZE_T
137    Dim i As SIZE_T
138    For i = 0 To ELM(size)
139        If s[i] = c Then
140            Return i
141        End If
142    Next
143    Return -1 As SIZE_T
144End Function
145
146Function ChrFind(s1 As PCWSTR, len1 As SIZE_T, s2 As PCWSTR, len2 As SIZE_T) As SIZE_T
147    If len2 = 0 Then
148        'ChrFind = 0
149        Exit Function
150    End If
151    Do
152        Dim prev = ChrFind
153        ChrFind = ChrFind(VarPtr(s1[prev]), (len1 - prev) As SIZE_T, s2[0])
154        If ChrFind = -1 As SIZE_T Then
155            Exit Function
156        End If
157        ChrFind += prev
158
159        If ChrCmp(VarPtr(s1[ChrFind]), s2, len2) = 0 Then
160            Exit Function
161        End If
162        ChrFind++
163        If ChrFind = len1 Then
164            ChrFind = -1
165            Exit Function
166        End If
167    Loop
168End Function
169
170Function ChrFind(s1 As PCSTR, len1 As SIZE_T, s2 As PCSTR, len2 As SIZE_T) As SIZE_T
171    If len2 = 0 Then
172        'ChrFind = 0
173        Exit Function
174    End If
175    Do
176        Dim prev = ChrFind
177        ChrFind = ChrFind(VarPtr(s1[prev]), (len1 - prev) As SIZE_T, s2[0])
178        If ChrFind = -1 As SIZE_T Then
179            Exit Function
180        End If
181        ChrFind += prev
182
183        If ChrCmp(VarPtr(s1[ChrFind]), s2, len2) = 0 Then
184            Exit Function
185        End If
186        ChrFind++
187        If ChrFind = len1 Then
188            ChrFind = -1
189            Exit Function
190        End If
191    Loop
192End Function
193
194Namespace Detail
195Function Split(s As String, c As StrChar) As System.Collections.ArrayList
196    Split = New System.Collections.ArrayList
197
198    Dim last = 0 As Long
199    Do
200        Dim i = s.IndexOf(c, last)
201        If i < 0 Then
202            Split.Add(s.Substring(last, s.Length - last))
203            Exit Function
204        End If
205        Split.Add(s.Substring(last, i - last))
206        last = i + 1
207        If last > s.Length Then
208            Split.Add(System.String.Empty)
209        End If
210    Loop
211End Function
212End Namespace 'Detail
213
214End Namespace 'Strings
215End Namespace 'ActiveBasic
216
217#endif '__ACTIVEBASIC_STRINGS_STRINGS_AB__
Note: See TracBrowser for help on using the repository browser.