Skip to content

Commit 03eabb7

Browse files
committed
Merge pull request #16 from typelift/character-actor
Data.Char functions
2 parents ab94cf4 + 5aa9004 commit 03eabb7

File tree

4 files changed

+243
-6
lines changed

4 files changed

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

0 commit comments

Comments
 (0)