[stdlib] Failable String inits from UTF8/16 views

String.UTF8View and String.UTF16View may be slices that don't both start
and end on Unicode scalar boundaries, in which case conversion to a
String must fail.

Swift SVN r24669
This commit is contained in:
Dave Abrahams
2015-01-23 02:46:42 +00:00
parent 6d72340259
commit 02e70d15d1
4 changed files with 58 additions and 30 deletions

View File

@@ -415,7 +415,7 @@ extension String.UnicodeScalarIndex {
/// Return the position in `utf8` that corresponds exactly
/// to `self`.
///
/// Requires: `self` is an element of `indices(String(utf8))`.
/// Requires: `self` is an element of `indices(String(utf8)!)`.
public func samePositionIn(utf8: String.UTF8View) -> String.UTF8View.Index {
return String.UTF8View.Index(self, within: utf8)
}
@@ -423,7 +423,7 @@ extension String.UnicodeScalarIndex {
/// Return the position in `utf16` that corresponds exactly
/// to `self`.
///
/// Requires: `self` is an element of `indices(String(utf16))`.
/// Requires: `self` is an element of `indices(String(utf16)!)`.
public func samePositionIn(
utf16: String.UTF16View
) -> String.UTF16View.Index {