-
Notifications
You must be signed in to change notification settings - Fork 1
/
uchars.pas
153 lines (122 loc) · 2.72 KB
/
uchars.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
unit uChars;
{$mode ObjFPC}{$H+}
{$ModeSwitch typehelpers}
interface
uses
SysUtils;
const
Null = #0;
Bell = #7;
BackSpace = #8;
Tab = #9;
VTab = #11;
FormFeed = #12;
CR = #13;
Escape = #27;
Space = #32;
SingleQuote = #39; // single quote
DoubleQuote = #34; // double quote
//on Unix '^D' on windows ^Z (#26)
{$IFDEF UNIX}
FileEnding = ^D;
{$ENDIF}
{$IFDEF WINDOWS}
FileEnding = ^Z //(#26)
{$ENDIF}
type
TCharHelper = type helper for Char
function isWhiteSpace: Boolean;
function isUnderscore: Boolean;
function isLowCaseLetter: Boolean;
function isUpCaseLetter: Boolean;
function isAlpha: Boolean;
function isDigit: Boolean;
function isAlphaNum: Boolean;
function isHexaDecimal: Boolean;
function isBinaryDecimal: Boolean;
function isOctoDecimal: Boolean;
function isSingleQuote: Boolean;
function isDoubleQuote: Boolean;
function isDot: Boolean;
function isFileEnding: Boolean;
function isLineEnding: Boolean;
function isNull: Boolean;
function toUpper: Char;
function toLower: Char;
end;
implementation
{ TCharHelper }
function TCharHelper.isWhiteSpace: Boolean;
begin
Result := Self in [Tab, LineEnding, Space];
end;
function TCharHelper.isUnderscore: Boolean;
begin
Result := Self = '_';
end;
function TCharHelper.isLowCaseLetter: Boolean;
begin
Result := Self in ['a'..'z'];
end;
function TCharHelper.isUpCaseLetter: Boolean;
begin
Result := Self in ['A'..'Z'];
end;
function TCharHelper.isAlpha: Boolean;
begin
Result := isLowCaseLetter or isUpCaseLetter;
end;
function TCharHelper.isDigit: Boolean;
begin
Result := Self in ['0'..'9'];
end;
function TCharHelper.isAlphaNum: Boolean;
begin
Result := isAlpha or isDigit;
end;
function TCharHelper.isHexaDecimal: Boolean;
begin
Result := Self in
['0'..'9', 'A', 'B', 'C', 'D', 'E', 'F', 'a', 'b', 'c', 'd', 'e', 'f'];
end;
function TCharHelper.isBinaryDecimal: Boolean;
begin
Result := Self in ['0', '1'];
end;
function TCharHelper.isOctoDecimal: Boolean;
begin
Result := Self in ['0'..'7'];
end;
function TCharHelper.isSingleQuote: Boolean;
begin
Result := Self = SingleQuote;
end;
function TCharHelper.isDoubleQuote: Boolean;
begin
Result := Self = DoubleQuote;
end;
function TCharHelper.isDot: Boolean;
begin
Result := Self = '.';
end;
function TCharHelper.isLineEnding: Boolean; inline;
begin
Result := Self = LineEnding;
end;
function TCharHelper.isNull: Boolean;
begin
Result := Self = #0;
end;
function TCharHelper.toUpper: Char;
begin
Result := Upcase(Self);
end;
function TCharHelper.toLower: Char;
begin
Result := LowerCase(Self);
end;
function TCharHelper.isFileEnding: Boolean; inline;
begin
Result := Self = FileEnding;
end;
end.