# SE-0243: Codepoint and Character Literals

**URL:** <https://forums.swift.org/t/se-0243-codepoint-and-character-literals/21188>\
**Category:** Proposal Reviews\
**Created:** [March 4, 2019, 3:45pm UTC](https://forums.swift.org/t/se-0243-codepoint-and-character-literals/21188 "2019-03-04T15:45:06Z")\
**Posts on this page:** 1\
**Showing post:** 283

<div class="post-metadata">

**Author:** ![lorentey](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lorentey/32/1299_2.png) [@lorentey](https://forums.swift.org/u/lorentey)\
**Post date:** [March 17, 2019, 10:43pm UTC](https://forums.swift.org/t/se-0243-codepoint-and-character-literals/21188/283 "2019-03-17T22:43:38Z")

</div>

> [@taylorswift](#):
>
> f the problem were just limited to generating arrays of ASCII characters, I might agree with you, but as i said in my [other post](https://forums.swift.org/t/se-0243-codepoint-and-character-literals/21188/277), there are a lot of other use cases that `.utf8` doesn’t solve.

These are really useful! I really don't see your point, though -- `String.utf8` (and `Unicode.Scalar.ascii`) seem to provide perfectly elegant, safe and efficient solutions to all of them:

```swift
// storing a bytestring value
static var liga = "liga".utf8

```

```swift
// storing an ASCII scalar to mixed utf8-ASCII text
var xml: [UInt8] = ...
xml.append('/'.ascii)
xml.append('>'.ascii)

```

```swift
// ASCII range operations 
let current: UnsafePointer<UInt8> = ...
if 'a'.ascii ... 'z'.ascii ~= current.pointee {
    ...
}

```

```swift
// ASCII arithmetic operations 
let year: ArraySlice<UInt8> = ...
var value: Int = 0
for digit: UInt8 in year {
    guard '0'.ascii ... '9'.ascii ~= digit else {
        ...
    }
    value *= 10
    value += Int(digit - '0'.ascii)
}

```

```swift
// reading an ASCII scalar from mixed utf8-ASCII text 
let xml: [UInt8] = ... 
if let i: Int = xml.firstIndex(of: '<'.ascii) {
    ...
}

```

```swift
// matching ASCII signatures 
let c: UnsafeRawBufferPointer = ...
if c.starts(with: "PLTE".utf8) {
    ...
}

```

Note: I took the liberty of replacing `Int8` above with `UInt8`. As far as I know, `Int8` data typically comes from C APIs imported as `CChar`, which is a truly terrible type: it's documented to be **either** `UInt8` or `Int8`, depending on the platform. Any code that doesn't immediately and explicitly rebind C strings to `UInt8` is arguably broken.

---

_[View the full topic](https://forums.swift.org/t/se-0243-codepoint-and-character-literals/21188)._
