[Unicode] Add convenience APIs to Unicode encodings

Add convenience APIs to the stdlib's Unicode encodings:

* Unicode.UTF16
  * isASCII
  * isSurrogate
* Unicode.UTF8
  * isASCII
  * width
* Unicode.UTF32
  * isASCII
* Unicode.ASCII
  * isASCII

Tests added
This commit is contained in:
Michael Ilseman
2019-02-26 13:59:53 -08:00
parent b6a158e1fc
commit 4967fc08eb
13 changed files with 424 additions and 353 deletions

View File

@@ -108,7 +108,7 @@ extension UnsafeBufferPointer where Element == UInt8 {
if index == 0 || index == count {
return true
}
assert(!_isContinuation(self[_unchecked: index]))
assert(!UTF8.isContinuation(self[_unchecked: index]))
// Sub-300 latiny fast-path
if self[_unchecked: index] < 0xCC { return true }
@@ -165,7 +165,7 @@ extension UnsafeBufferPointer where Element == UInt8 {
_internalInvariant(index == count)
return true
}
return !_isContinuation(self[index])
return !UTF8.isContinuation(self[index])
}
}