let asciiString = ASCIIString("ÂŚÇÏÎ")
// returns typed as String
asciiString.stringValue // "ASCII"
// returns Data representation of string
asciiString.rawData // Data([0x41, 0x53, 0x43, 0x49, 0x49])
ASCIICharacter
// failable init
ASCIICharacter(exactly: "A") // succeeds
ASCIICharacter(exactly: "Ω") // nil
// lossy string conversion making ASCII-compatible substitutions
ASCIICharacter("A") // "A" (unchanged)
ASCIICharacter("Ã") // "A" (substituted)
// lossy character conversion through Character literal type inference
let char: ASCIICharacter = "Ä"
print(char) // "A" (substituted)
// failable ASCII integer literal init
ASCIICharacter(65) // "A"
ASCIICharacter(300) // nil
let asciiString = ASCIICharacter("Ä")
// returns typed as Character
asciiString.characterValue // Character("A")
// returns ASCII integer literal
asciiString.asciiValue // 65
// returns Data representation of character
asciiString.rawData // Data([0x41])
Author
Coded by a bunch of 🐹 hamsters in a trenchcoat that calls itself @orchetect.
License
Licensed under the MIT license. See LICENSE for details.
Contributions
Contributions are welcome. Feel free to post an Issue to discuss.
SwiftASCII
ASCIIString
andASCIICharacter
types for Swift offering validation and lossy conversion fromString
.Complete unit test coverage.
Getting Started
Swift Package Manager (SPM)
Add SwiftASCII as a dependency using Swift Package Manager.
In an app project or framework, in Xcode:
https://github.com/orchetect/SwiftASCII
In a Swift Package, add it to the Package.swift dependencies:
Import the library:
ASCIIString
ASCIICharacter
Author
Coded by a bunch of 🐹 hamsters in a trenchcoat that calls itself @orchetect.
License
Licensed under the MIT license. See LICENSE for details.
Contributions
Contributions are welcome. Feel free to post an Issue to discuss.