Skip to content

Commit e0cd4f5

Browse files
committed
Data.Char functions
1 parent 4c8f24b commit e0cd4f5

File tree

4 files changed

+242
-6
lines changed

4 files changed

+242
-6
lines changed

Basis-iOS.xcodeproj/project.pbxproj

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
841FE03119DB7E390068636A /* Zip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841FE02819DB7E390068636A /* Zip.swift */; };
2222
841FE04819DB7EE80068636A /* Compare.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841FE04619DB7EE80068636A /* Compare.swift */; };
2323
841FE04919DB7EE80068636A /* Folds.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841FE04719DB7EE80068636A /* Folds.swift */; };
24+
8427737A1A5CDB6300CF1E67 /* Char.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842773791A5CDB6300CF1E67 /* Char.swift */; };
25+
8427737E1A5CDB7500CF1E67 /* CharSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8427737D1A5CDB7500CF1E67 /* CharSpec.swift */; };
2426
8434F96B19E8BA00008D9909 /* Version.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8434F96A19E8BA00008D9909 /* Version.swift */; };
2527
8434F96F19E8BDF5008D9909 /* VersionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8434F96E19E8BDF5008D9909 /* VersionSpec.swift */; };
2628
8441AAAA1A0C51C4008D5701 /* LazySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8441AAA91A0C51C4008D5701 /* LazySpec.swift */; };
@@ -81,8 +83,8 @@
8183
84D4D8EB1A16EBBE001F5E4D /* ComonadApply.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D4D8EA1A16EBBE001F5E4D /* ComonadApply.swift */; };
8284
84D4D8ED1A16EBC5001F5E4D /* ComonadFix.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D4D8EC1A16EBC5001F5E4D /* ComonadFix.swift */; };
8385
84D4D8EF1A16EBDB001F5E4D /* Copointed.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D4D8EE1A16EBDB001F5E4D /* Copointed.swift */; };
84-
84D77DFB1A3CF9FA000F5683 /* ListSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D77DFA1A3CF9FA000F5683 /* ListSpec.swift */; };
8586
84D77DF61A3BE573000F5683 /* Pointed.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D77DF51A3BE573000F5683 /* Pointed.swift */; };
87+
84D77DFB1A3CF9FA000F5683 /* ListSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D77DFA1A3CF9FA000F5683 /* ListSpec.swift */; };
8688
84F43F0119E1B3B40012CF95 /* Optional.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F43F0019E1B3B40012CF95 /* Optional.swift */; };
8789
84F43F0519E1CA970012CF95 /* Set.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F43F0419E1CA970012CF95 /* Set.swift */; };
8890
84F9063019D639980035D429 /* CompareSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F9062F19D639980035D429 /* CompareSpec.swift */; };
@@ -116,6 +118,8 @@
116118
841FE02819DB7E390068636A /* Zip.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Zip.swift; sourceTree = "<group>"; };
117119
841FE04619DB7EE80068636A /* Compare.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Compare.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
118120
841FE04719DB7EE80068636A /* Folds.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Folds.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
121+
842773791A5CDB6300CF1E67 /* Char.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Char.swift; sourceTree = "<group>"; };
122+
8427737D1A5CDB7500CF1E67 /* CharSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CharSpec.swift; sourceTree = "<group>"; };
119123
8434F96A19E8BA00008D9909 /* Version.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Version.swift; sourceTree = "<group>"; };
120124
8434F96E19E8BDF5008D9909 /* VersionSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VersionSpec.swift; sourceTree = "<group>"; };
121125
8441AAA91A0C51C4008D5701 /* LazySpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LazySpec.swift; sourceTree = "<group>"; };
@@ -180,8 +184,8 @@
180184
84D4D8EA1A16EBBE001F5E4D /* ComonadApply.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComonadApply.swift; sourceTree = "<group>"; };
181185
84D4D8EC1A16EBC5001F5E4D /* ComonadFix.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComonadFix.swift; sourceTree = "<group>"; };
182186
84D4D8EE1A16EBDB001F5E4D /* Copointed.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Copointed.swift; sourceTree = "<group>"; };
183-
84D77DFA1A3CF9FA000F5683 /* ListSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListSpec.swift; sourceTree = "<group>"; };
184187
84D77DF51A3BE573000F5683 /* Pointed.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Pointed.swift; sourceTree = "<group>"; };
188+
84D77DFA1A3CF9FA000F5683 /* ListSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListSpec.swift; sourceTree = "<group>"; };
185189
84F43F0019E1B3B40012CF95 /* Optional.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Optional.swift; sourceTree = "<group>"; };
186190
84F43F0419E1CA970012CF95 /* Set.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Set.swift; sourceTree = "<group>"; };
187191
84F9062F19D639980035D429 /* CompareSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CompareSpec.swift; sourceTree = "<group>"; };
@@ -258,6 +262,7 @@
258262
isa = PBXGroup;
259263
children = (
260264
84922C9E19D237B900AE9A7C /* ArrowSpec.swift */,
265+
8427737D1A5CDB7500CF1E67 /* CharSpec.swift */,
261266
84F9062F19D639980035D429 /* CompareSpec.swift */,
262267
84922C9D19D237B900AE9A7C /* EitherSpec.swift */,
263268
847E99DF1A48B39600B5B8CE /* FoldsSpec.swift */,
@@ -306,7 +311,6 @@
306311
84922D8319D238D400AE9A7C /* Arrow */,
307312
84922CBA19D237DA00AE9A7C /* Category.swift */,
308313
84D4D8E91A16EBB3001F5E4D /* Comonad */,
309-
84D4D8EE1A16EBDB001F5E4D /* Copointed.swift */,
310314
84922D8419D238DB00AE9A7C /* Monad */,
311315
84896B481A475854006F3EA9 /* Trampoline.swift */,
312316
);
@@ -361,6 +365,7 @@
361365
84922CB719D237DA00AE9A7C /* Bottom.swift */,
362366
84922CB819D237DA00AE9A7C /* Bounded.swift */,
363367
84922CB919D237DA00AE9A7C /* Box.swift */,
368+
842773791A5CDB6300CF1E67 /* Char.swift */,
364369
84D4D8E31A16E4E9001F5E4D /* Const.swift */,
365370
84922CBB19D237DA00AE9A7C /* Coerce.swift */,
366371
84922CBC19D237DA00AE9A7C /* Combinator.swift */,
@@ -553,6 +558,7 @@
553558
841FE02A19DB7E390068636A /* List.swift in Sources */,
554559
84D4D8E41A16E4E9001F5E4D /* Const.swift in Sources */,
555560
84922D0719D237DA00AE9A7C /* Operators.swift in Sources */,
561+
8427737A1A5CDB6300CF1E67 /* Char.swift in Sources */,
556562
84D4D8EB1A16EBBE001F5E4D /* ComonadApply.swift in Sources */,
557563
84922D0B19D237DA00AE9A7C /* ST.swift in Sources */,
558564
841FE03119DB7E390068636A /* Zip.swift in Sources */,
@@ -599,6 +605,7 @@
599605
84922CAE19D237B900AE9A7C /* StringSpec.swift in Sources */,
600606
84A802E219D3BD5000E71F93 /* MonoidSpec.swift in Sources */,
601607
84922CA719D237B900AE9A7C /* EitherSpec.swift in Sources */,
608+
8427737E1A5CDB7500CF1E67 /* CharSpec.swift in Sources */,
602609
84922CAA19D237B900AE9A7C /* InfinitySpec.swift in Sources */,
603610
84F9063019D639980035D429 /* CompareSpec.swift in Sources */,
604611
84922CAD19D237B900AE9A7C /* OperatorsSpec.swift in Sources */,

Basis.xcodeproj/project.pbxproj

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
841FE04519DB7E7C0068636A /* Zip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841FE03B19DB7E7C0068636A /* Zip.swift */; };
2424
841FE04C19DB7EEC0068636A /* Compare.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841FE04A19DB7EEC0068636A /* Compare.swift */; };
2525
841FE04D19DB7EEC0068636A /* Folds.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841FE04B19DB7EEC0068636A /* Folds.swift */; };
26+
842773781A5CD87400CF1E67 /* Char.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842773771A5CD87400CF1E67 /* Char.swift */; };
27+
8427737C1A5CDB6F00CF1E67 /* CharSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8427737B1A5CDB6F00CF1E67 /* CharSpec.swift */; };
2628
842963B219DF7A3A003FCBE8 /* Set.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842963B119DF7A3A003FCBE8 /* Set.swift */; };
2729
8434F96D19E8BA0A008D9909 /* Version.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8434F96C19E8BA0A008D9909 /* Version.swift */; };
2830
8434F97119E8BE43008D9909 /* VersionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8434F97019E8BE43008D9909 /* VersionSpec.swift */; };
@@ -85,8 +87,8 @@
8587
84D4D8F61A18095F001F5E4D /* Comonad.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D4D8F21A18095F001F5E4D /* Comonad.swift */; };
8688
84D4D8F71A18095F001F5E4D /* ComonadFix.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D4D8F31A18095F001F5E4D /* ComonadFix.swift */; };
8789
84D4D8FA1A181649001F5E4D /* ComonadApply.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D4D8F91A181649001F5E4D /* ComonadApply.swift */; };
88-
84D77DF91A3CF9F4000F5683 /* ListSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D77DF81A3CF9F4000F5683 /* ListSpec.swift */; };
8990
84D77DF31A3BDCB6000F5683 /* Pointed.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D77DF21A3BDCB6000F5683 /* Pointed.swift */; };
91+
84D77DF91A3CF9F4000F5683 /* ListSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D77DF81A3CF9F4000F5683 /* ListSpec.swift */; };
9092
84F9062E19D638BD0035D429 /* ArrowSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F9062D19D638BD0035D429 /* ArrowSpec.swift */; };
9193
/* End PBXBuildFile section */
9294

@@ -130,6 +132,8 @@
130132
841FE03B19DB7E7C0068636A /* Zip.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Zip.swift; sourceTree = "<group>"; };
131133
841FE04A19DB7EEC0068636A /* Compare.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Compare.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
132134
841FE04B19DB7EEC0068636A /* Folds.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Folds.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
135+
842773771A5CD87400CF1E67 /* Char.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Char.swift; sourceTree = "<group>"; };
136+
8427737B1A5CDB6F00CF1E67 /* CharSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CharSpec.swift; sourceTree = "<group>"; };
133137
842963B119DF7A3A003FCBE8 /* Set.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Set.swift; sourceTree = "<group>"; };
134138
8434F96C19E8BA0A008D9909 /* Version.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Version.swift; sourceTree = "<group>"; };
135139
8434F97019E8BE43008D9909 /* VersionSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VersionSpec.swift; sourceTree = "<group>"; };
@@ -194,8 +198,8 @@
194198
84D4D8F21A18095F001F5E4D /* Comonad.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Comonad.swift; sourceTree = "<group>"; };
195199
84D4D8F31A18095F001F5E4D /* ComonadFix.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComonadFix.swift; sourceTree = "<group>"; };
196200
84D4D8F91A181649001F5E4D /* ComonadApply.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComonadApply.swift; sourceTree = "<group>"; };
197-
84D77DF81A3CF9F4000F5683 /* ListSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListSpec.swift; sourceTree = "<group>"; };
198201
84D77DF21A3BDCB6000F5683 /* Pointed.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Pointed.swift; sourceTree = "<group>"; };
202+
84D77DF81A3CF9F4000F5683 /* ListSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListSpec.swift; sourceTree = "<group>"; };
199203
84F9062D19D638BD0035D429 /* ArrowSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = ArrowSpec.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
200204
/* End PBXFileReference section */
201205

@@ -241,7 +245,6 @@
241245
84922D7A19D2381800AE9A7C /* Arrow */,
242246
84922D1E19D237E000AE9A7C /* Category.swift */,
243247
84D4D8F51A18095F001F5E4D /* Comonad */,
244-
84D4D8F01A180959001F5E4D /* Copointed.swift */,
245248
84922D7B19D2382000AE9A7C /* Monad */,
246249
84896B421A469179006F3EA9 /* Trampoline.swift */,
247250
);
@@ -307,6 +310,7 @@
307310
84922D1B19D237E000AE9A7C /* Bottom.swift */,
308311
84922D1C19D237E000AE9A7C /* Bounded.swift */,
309312
84922D1D19D237E000AE9A7C /* Box.swift */,
313+
842773771A5CD87400CF1E67 /* Char.swift */,
310314
84D4D8E51A16E6B4001F5E4D /* Const.swift */,
311315
84922D1F19D237E000AE9A7C /* Coerce.swift */,
312316
84922D2019D237E000AE9A7C /* Combinator.swift */,
@@ -370,6 +374,7 @@
370374
isa = PBXGroup;
371375
children = (
372376
84F9062D19D638BD0035D429 /* ArrowSpec.swift */,
377+
8427737B1A5CDB6F00CF1E67 /* CharSpec.swift */,
373378
8434F97219E8C2FC008D9909 /* CompareSpec.swift */,
374379
8418FC5119CFB3480010923E /* EitherSpec.swift */,
375380
847E99DD1A48B38A00B5B8CE /* FoldsSpec.swift */,
@@ -567,6 +572,7 @@
567572
84922D6219D237E000AE9A7C /* Lift.swift in Sources */,
568573
84D4D8E61A16E6B4001F5E4D /* Const.swift in Sources */,
569574
841FE03E19DB7E7C0068636A /* List.swift in Sources */,
575+
842773781A5CD87400CF1E67 /* Char.swift in Sources */,
570576
84D4D8FA1A181649001F5E4D /* ComonadApply.swift in Sources */,
571577
84922D6B19D237E000AE9A7C /* Operators.swift in Sources */,
572578
84922D6F19D237E000AE9A7C /* ST.swift in Sources */,
@@ -613,6 +619,7 @@
613619
84C9970519CE8A970046906D /* InfinitySpec.swift in Sources */,
614620
8434F97119E8BE43008D9909 /* VersionSpec.swift in Sources */,
615621
84C9970419CE8A970046906D /* FunctionsSpec.swift in Sources */,
622+
8427737C1A5CDB6F00CF1E67 /* CharSpec.swift in Sources */,
616623
8418FC5219CFB3480010923E /* EitherSpec.swift in Sources */,
617624
84423DE81A033BA700361829 /* ZipSpec.swift in Sources */,
618625
84A802E019D3BD3D00E71F93 /* MonoidSpec.swift in Sources */,

Basis/Char.swift

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
//
2+
// Char.swift
3+
// Basis
4+
//
5+
// Created by Robert Widmann on 1/6/15.
6+
// Copyright (c) 2015 Robert Widmann. All rights reserved.
7+
//
8+
9+
import Darwin
10+
11+
extension Character {
12+
/// Returns the unicode codepoint value for the first unicode value in the grapheme cluster.
13+
public func unicodeValue() -> UInt32 {
14+
for s in String(self).unicodeScalars {
15+
return s.value
16+
}
17+
return 0
18+
}
19+
20+
/// Returns whether the reciever is a valid ASCII character.
21+
public func isASCII() -> Bool {
22+
return self < "\u{80}"
23+
}
24+
25+
/// Returns whether the reciever is a valid Latin1 Character.
26+
public func isLatin1() -> Bool {
27+
return self <= "\u{ff}"
28+
}
29+
30+
/// Returns wehether the reciever is an ASCII digit ([0-9]).
31+
public func isDigit() -> Bool {
32+
return self >= "0" && self <= "9"
33+
}
34+
35+
/// Returns wehether the reciever is an ASCII octal digit ([0-7]).
36+
public func isOctalDigit() -> Bool {
37+
return self >= "0" && self <= "7"
38+
}
39+
40+
/// Returns wehether the reciever is an ASCII hexadecimal digit ([0-9a-fA-F]).
41+
public func isHexadecimalDigit() -> Bool {
42+
return self.isDigit() || (self >= "a" && self <= "f") || (self >= "A" && self <= "F")
43+
}
44+
45+
/// Returns whether the reciever is a valid ASCII lowercase character ([a-z])
46+
public func isASCIILower() -> Bool {
47+
return self >= "a" && self <= "z"
48+
}
49+
50+
/// Returns whether the reciever is a valid ASCII uppercase character ([A-Z])
51+
public func isASCIIUpper() -> Bool {
52+
return self >= "A" && self <= "Z"
53+
}
54+
55+
/// Returns whether the reciever is a valid Unicode lowercase character ([a-z])
56+
public func isLower() -> Bool {
57+
return iswlower(Int32(self.unicodeValue())) != 0
58+
}
59+
60+
/// Returns whether the reciever is a valid Unicode uppercase character ([A-Z])
61+
public func isUpper() -> Bool {
62+
return iswupper(Int32(self.unicodeValue())) != 0
63+
}
64+
65+
/// Returns whether the reciever is a Unicode space character.
66+
public func isSpace() -> Bool {
67+
return iswspace(Int32(self.unicodeValue())) != 0
68+
}
69+
70+
/// Returns whether the reciever is a Latin1 control character.
71+
public func isControl() -> Bool {
72+
return iswcntrl(Int32(self.unicodeValue())) != 0
73+
}
74+
75+
/// Returns whether the reciever is a printable Unicode character.
76+
public func isPrintable() -> Bool {
77+
return iswprint(Int32(self.unicodeValue())) != 0
78+
}
79+
80+
/// Converts the reciever to its corresponding uppercase letter, if any.
81+
public func toUpper() -> Character {
82+
return Character(UnicodeScalar(self.unicodeValue()).toUpper())
83+
}
84+
85+
/// Converts the reciever to its corresponding lowercase letter, if any.
86+
public func toLower() -> Character {
87+
return Character(UnicodeScalar(self.unicodeValue()).toLower())
88+
}
89+
}
90+
91+
extension UnicodeScalar {
92+
/// Returns whether the reciever represents a valid ASCII character.
93+
public func isASCII() -> Bool {
94+
return self < "\u{80}"
95+
}
96+
97+
/// Returns whether the reciever represents a valid Latin1 character.
98+
public func isLatin1() -> Bool {
99+
return self <= "\u{ff}"
100+
}
101+
102+
/// Returns wehether the reciever is an ASCII digit ([0-9]).
103+
public func isDigit() -> Bool {
104+
return self >= "0" && self <= "9"
105+
}
106+
107+
/// Returns wehether the reciever is an ASCII octal digit ([0-7]).
108+
public func isOctalDigit() -> Bool {
109+
return self >= "0" && self <= "7"
110+
}
111+
112+
/// Returns wehether the reciever is an ASCII hexadecimal digit ([0-9a-fA-F]).
113+
public func isHexadecimalDigit() -> Bool {
114+
return self.isDigit() || (self >= "a" && self <= "f") || (self >= "A" && self <= "F")
115+
}
116+
117+
/// Returns whether the reciever is a valid ASCII lowercase character ([a-z])
118+
public func isASCIILower() -> Bool {
119+
return self >= "a" && self <= "z"
120+
}
121+
122+
/// Returns whether the reciever is a valid ASCII uppercase character ([A-Z])
123+
public func isASCIIUpper() -> Bool {
124+
return self >= "A" && self <= "Z"
125+
}
126+
127+
/// Returns whether the reciever is a valid Unicode lowercase character ([a-z])
128+
public func isLower() -> Bool {
129+
return iswlower(Int32(self.value)) != 0
130+
}
131+
132+
/// Returns whether the reciever is a valid Unicode uppercase character ([A-Z])
133+
public func isUpper() -> Bool {
134+
return iswupper(Int32(self.value)) != 0
135+
}
136+
137+
/// Returns whether the reciever is a Unicode space character.
138+
public func isSpace() -> Bool {
139+
return iswspace(Int32(self.value)) != 0 || self == "\u{21A1}" || self == "\u{000B}"
140+
}
141+
142+
/// Returns whether the reciever is a Latin1 control character.
143+
public func isControl() -> Bool {
144+
return iswcntrl(Int32(self.value)) != 0
145+
}
146+
147+
/// Returns whether the reciever is a printable Unicode character.
148+
public func isPrintable() -> Bool {
149+
return iswprint(Int32(self.value)) != 0
150+
}
151+
152+
/// Converts the reciever to its corresponding uppercase letter, if any.
153+
public func toUpper() -> UnicodeScalar {
154+
return UnicodeScalar(UInt32(towupper(Int32(self.value))))
155+
}
156+
157+
/// Converts the reciever to its corresponding lowercase letter, if any.
158+
public func toLower() -> UnicodeScalar {
159+
return UnicodeScalar(UInt32(towlower(Int32(self.value))))
160+
}
161+
}

0 commit comments

Comments
 (0)