source: trunk/Include/Classes/ActiveBasic/CType/CType.ab@ 388

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

Stringなどで例外を投げるようにした。
#147の解決。
CType ASCII文字判定関数群の追加。

File size: 4.2 KB
Line 
1/*!
2@file Classes/ActiveBasic/CType/CType.ab
3@brief ASCII文字分類関数群
4@author Egtra
5@date 2007/11/25
6*/
7
8Namespace ActiveBasic
9Namespace CType
10
11Namespace Detail
12
13Function Widen(c As CHAR) As WCHAR
14 Return c As Byte As WCHAR
15End Function
16
17Function Narrow(c As WCHAR) As CHAR
18 Return c As Byte As CHAR
19End Function
20
21End Namespace 'Detail
22
23/*!
24@brief ASCIIのアルファベットまたは数字かどうか
25@author Egtra
26@date 2007/11/25
27*/
28Function IsAlnum(c As WCHAR) As Boolean
29 Return IsUpper(c) Or IsLower(c) Or IsDigit(c)
30End Function
31
32/*!
33@brief ASCIIのアルファベットかどうか
34@author Egtra
35@date 2007/11/25
36*/
37Function IsAlpha(c As WCHAR) As Boolean
38 Return IsUpper(c) Or IsLower(c)
39End Function
40
41/*!
42@brief ASCIIの行内に置ける空白文字かどうか
43@author Egtra
44@date 2007/11/25
45ようするにASCIIでは空白とタブ
46*/
47Function IsBlank(c As WCHAR) As Boolean
48 Return c = &h20 Or c = &h09 'space or tab
49End Function
50
51/*!
52@brief ASCIIの制御文字かどうか
53@author Egtra
54@date 2007/11/25
55*/
56Function IsCntrl(c As WCHAR) As Boolean
57 Return c < &h20 Or c = &h7f
58End Function
59
60/*!
61@brief ASCIIの数字かどうか
62@author Egtra
63@date 2007/11/25
64*/
65Function IsDigit(c As WCHAR) As Boolean
66 Return (c As DWord Xor &h30) < 10
67End Function
68
69/*!
70@brief ASCIIの図形文字かどうか
71@author Egtra
72@date 2007/11/25
73図形文字とは、空白以外の表示文字
74*/
75Function IsGraph(c As WCHAR) As Boolean
76 Return (c As DWord - &h21) < (&h7e - &h21)
77End Function
78
79/*!
80@brief ASCIIのアルファベッの小文字かどうか
81@author Egtra
82@date 2007/11/25
83*/
84Function IsLower(c As WCHAR) As Boolean
85 Return c As DWord - &h61 < 26 ' &h61 = Asc("a")
86End Function
87
88Function IsPrint(c As WCHAR) As Boolean
89 Return (c As DWord - &h20) < (&h7e - &h20)
90End Function
91
92/*!
93@brief ASCIIの区切り数字かどうか
94@author Egtra
95@date 2007/11/25
96アルファベットでも数字でもない図形文字のこと
97*/
98Function IsPunct(c As WCHAR) As Boolean
99 Return c < &h7f And IsGraph(c) And (Not IsAlnum(c))
100End Function
101
102/*!
103@brief ASCIIのアルファベットの大文字かどうか
104@author Egtra
105@date 2007/11/25
106*/
107Function IsUpper(c As WCHAR) As Boolean
108 Return c As DWord - &h41 < 26 ' &h41 = Asc("A")
109End Function
110
111/*!
112@brief ASCIIの十六進法で記す際に用いられる文字かどうか
113@author Egtra
114@date 2007/11/25
115*/
116Function IsXDigit(c As WCHAR) As Boolean
117 Return IsDigit(c) Or ((c As DWord And (Not &h20)) - &h41 < 5)
118End Function
119
120/*!
121@brief ASCIIのアルファベット大文字を小文字にする
122@author Egtra
123@date 2007/11/25
124*/
125Function ToLower(c As WCHAR) As WCHAR
126 If IsUpper(c) Then
127 Return c Or &h20
128 Else
129 Return c
130 End If
131End Function
132
133/*!
134@brief ASCIIのアルファベット小文字を大文字にする
135@author Egtra
136@date 2007/11/25
137*/
138Function ToUpper(c As WCHAR) As WCHAR
139 If IsLower(c) Then
140 Return c And (Not &h20)
141 Else
142 Return c
143 End If
144End Function
145
146/*!
147@overload
148*/
149Function IsAlnum(c As CHAR) As Boolean
150 Return IsAlnum(Detail.Widen(c))
151End Function
152
153/*!
154@overload
155*/
156Function IsAlpha(c As CHAR) As Boolean
157 Return IsAlpha(Detail.Widen(c))
158End Function
159
160/*!
161@overload
162*/
163Function IsBlank(c As CHAR) As Boolean
164 Return IsBlank(Detail.Widen(c))
165End Function
166
167/*!
168@overload
169*/
170Function IsCntrl(c As CHAR) As Boolean
171 Return IsCntrl(Detail.Widen(c))
172End Function
173
174/*!
175@overload
176*/
177Function IsDigit(c As CHAR) As Boolean
178 Return IsDigit(Detail.Widen(c))
179End Function
180
181/*!
182@overload
183*/
184Function IsGraph(c As CHAR) As Boolean
185 Return IsGraph(Detail.Widen(c))
186End Function
187
188/*!
189@overload
190*/
191Function IsLower(c As CHAR) As Boolean
192 Return IsLower(Detail.Widen(c))
193End Function
194
195/*!
196@overload
197*/
198Function IsPrint(c As CHAR) As Boolean
199 Return IsPrint(Detail.Widen(c))
200End Function
201
202/*!
203@overload
204*/
205Function IsPunct(c As CHAR) As Boolean
206 Return IsPunct(Detail.Widen(c))
207End Function
208
209/*!
210@overload
211*/
212Function IsUpper(c As CHAR) As Boolean
213 Return IsUpper(Detail.Widen(c))
214End Function
215
216/*!
217@overload
218*/
219Function IsXDigit(c As CHAR) As Boolean
220 Return IsXDigit(Detail.Widen(c))
221End Function
222
223/*!
224@overload
225*/
226Function ToLower(c As CHAR) As CHAR
227 Return Detail.Narrow(ToLower(Detail.Widen(c)))
228End Function
229
230/*!
231@overload
232*/
233Function ToUpper(c As CHAR) As CHAR
234 Return Detail.Narrow(ToUpper(Detail.Widen(c)))
235End Function
236
237End Namespace
238End Namespace
Note: See TracBrowser for help on using the repository browser.