From d2be97d85654afa966f61b9ca1c2a6a8be2d7dd9 Mon Sep 17 00:00:00 2001 From: Maxim Moiseev Date: Tue, 10 Nov 2015 14:58:47 -0800 Subject: [PATCH] change return type of String.fromCStringRepairingIllFormedUTF8 --- stdlib/public/SDK/ObjectiveC/ObjectiveC.swift | 3 +- stdlib/public/core/CString.swift | 7 ++--- stdlib/public/core/Process.swift | 3 +- test/1_stdlib/NSStringAPI.swift | 30 ++++++++++++------- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/stdlib/public/SDK/ObjectiveC/ObjectiveC.swift b/stdlib/public/SDK/ObjectiveC/ObjectiveC.swift index 6dfd98443d5fd..d0ce9b424e393 100644 --- a/stdlib/public/SDK/ObjectiveC/ObjectiveC.swift +++ b/stdlib/public/SDK/ObjectiveC/ObjectiveC.swift @@ -149,7 +149,8 @@ extension Selector : Equatable, Hashable { extension Selector : CustomStringConvertible { /// A textual representation of `self`. public var description: String { - if let s = String.fromCStringRepairingIllFormedUTF8(sel_getName(self)).0 { + if let (s, _) = String.fromCStringRepairingIllFormedUTF8( + sel_getName(self)) { return s } return "" diff --git a/stdlib/public/core/CString.swift b/stdlib/public/core/CString.swift index bdf4c818cc235..0cacfe20e2f7a 100644 --- a/stdlib/public/core/CString.swift +++ b/stdlib/public/core/CString.swift @@ -30,7 +30,7 @@ extension String { input: UnsafeBufferPointer(start: UnsafeMutablePointer(cs), length: len)) } - /// Creates a new `String` by copying the nul-terminated UTF-8 data + /// Create a new `String` by copying the nul-terminated UTF-8 data /// referenced by a `CString`. /// /// Returns `nil` if the `CString` is `NULL`. If `CString` contains @@ -38,10 +38,9 @@ extension String { /// characters (U+FFFD). @warn_unused_result public static func fromCStringRepairingIllFormedUTF8( - cs: UnsafePointer) - -> (String?, hadError: Bool) { + cs: UnsafePointer) -> (String, hadError: Bool)? { if cs._isNull { - return (nil, hadError: false) + return nil } let len = Int(_swift_stdlib_strlen(cs)) let (result, hadError) = String._fromCodeUnitSequenceWithRepair(UTF8.self, diff --git a/stdlib/public/core/Process.swift b/stdlib/public/core/Process.swift index 1a80e97d23c00..726c48b469c2d 100644 --- a/stdlib/public/core/Process.swift +++ b/stdlib/public/core/Process.swift @@ -17,7 +17,8 @@ public enum Process { // Use lazy initialization of static properties to safely initialize the // public 'arguments' property on first use. (0..