You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// A type containing a `Character` instance that is guaranteed to conform to ASCII encoding.
11
-
/// Offers a validating `exactly: Character` failable initializer and a `_ lossy: Character` conversion initializer.
11
+
/// Offers a validating `exactly: Character` failable initializer and a `_ lossy: Character`
12
+
/// conversion initializer.
12
13
publicstructASCIICharacter:Hashable{
13
14
/// The ASCII character returned as a `Character`
14
15
publicletcharacterValue:Character
@@ -32,11 +33,13 @@ public struct ASCIICharacter: Hashable {
32
33
asciiValue = getASCIIValue
33
34
}
34
35
35
-
/// Returns a new `ASCIICharacter` instance from the source character, converting a non-ASCII character to its closest ASCII equivalent if necessary.
36
+
/// Returns a new `ASCIICharacter` instance from the source character, converting a non-ASCII
37
+
/// character to its closest ASCII equivalent if necessary.
36
38
@inlinable
37
39
publicinit(_ lossy:Character){
38
40
guardlet getASCIIValue = lossy.asciiValue else{
39
-
// if ASCII encoding fails, fall back to a default character instead of throwing an exception
41
+
// if ASCII encoding fails, fall back to a default character instead of throwing an
42
+
// exception
40
43
41
44
vartranslated=String(lossy).asciiStringLossy
42
45
if translated.stringValue.isEmpty { translated ="?"}
@@ -51,7 +54,8 @@ public struct ASCIICharacter: Hashable {
51
54
asciiValue = getASCIIValue
52
55
}
53
56
54
-
/// Returns a new `ASCIICharacter` instance if the source string contains a single character and the character is a valid ASCII character.
57
+
/// Returns a new `ASCIICharacter` instance if the source string contains a single character and
58
+
/// the character is a valid ASCII character.
55
59
@_disfavoredOverload
56
60
@inlinable
57
61
publicinit?<S:StringProtocol>(exactly source:S){
@@ -67,7 +71,8 @@ public struct ASCIICharacter: Hashable {
67
71
asciiValue = getASCIIValue
68
72
}
69
73
70
-
/// Returns a new `ASCIICharacter` instance if the source string contains a single character, converting a non-ASCII character to its closest ASCII equivalent if necessary.
74
+
/// Returns a new `ASCIICharacter` instance if the source string contains a single character,
75
+
/// converting a non-ASCII character to its closest ASCII equivalent if necessary.
71
76
@inlinable
72
77
publicinit<S:StringProtocol>(_ lossy:S){
73
78
letchar:Character= lossy.first ??"?"
@@ -76,7 +81,8 @@ public struct ASCIICharacter: Hashable {
76
81
}
77
82
78
83
/// Returns a new `ASCIICharacter` instance if the source data is a single ASCII character.
79
-
/// Returns `nil` if the source data is not a single byte or if it contains a non-ASCII character byte.
84
+
/// Returns `nil` if the source data is not a single byte or if it contains a non-ASCII
/// Performs a lossy conversion, transforming characters to printable ASCII substitutions where necessary.
39
+
/// Performs a lossy conversion, transforming characters to printable ASCII substitutions where
40
+
/// necessary.
40
41
///
41
-
/// Note that some characters may be transformed to representations that occupy more than one ASCII character. For example: char 189 (½) will be converted to "1/2"
42
+
/// Note that some characters may be transformed to representations that occupy more than one
43
+
/// ASCII character. For example: char 189 (½) will be converted to "1/2"
42
44
///
43
-
/// Where a suitable character substitution can't reasonably be performed, a question-mark "?" will be substituted.
45
+
/// Where a suitable character substitution can't reasonably be performed, a question-mark "?"
0 commit comments