Skip to content

Commit 3a92a75

Browse files
committed
Fix the rest of the deprecations.
1 parent 175963e commit 3a92a75

File tree

2 files changed

+56
-106
lines changed

2 files changed

+56
-106
lines changed

Diff for: Foundation.xcodeproj/project.pbxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
03B6F5841F15F339004F25AF /* TestURLProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03B6F5831F15F339004F25AF /* TestURLProtocol.swift */; };
1212
1513A8432044893F00539722 /* FileManager_XDG.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1513A8422044893F00539722 /* FileManager_XDG.swift */; };
1313
1520469B1D8AEABE00D02E36 /* HTTPServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1520469A1D8AEABE00D02E36 /* HTTPServer.swift */; };
14-
153CC8332214C3D100BFE8F3 /* ScannerAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 153CC8322214C3D100BFE8F3 /* ScannerAPI.swift */; };
14+
153CC8352215E00200BFE8F3 /* ScannerAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 153CC8322214C3D100BFE8F3 /* ScannerAPI.swift */; };
1515
153E951120111DC500F250BE /* CFKnownLocations.h in Headers */ = {isa = PBXBuildFile; fileRef = 153E950F20111DC500F250BE /* CFKnownLocations.h */; settings = {ATTRIBUTES = (Private, ); }; };
1616
153E951220111DC500F250BE /* CFKnownLocations.c in Sources */ = {isa = PBXBuildFile; fileRef = 153E951020111DC500F250BE /* CFKnownLocations.c */; };
1717
15496CF1212CAEBA00450F5A /* CFAttributedStringPriv.h in Headers */ = {isa = PBXBuildFile; fileRef = 15496CF0212CAEBA00450F5A /* CFAttributedStringPriv.h */; };
@@ -2369,7 +2369,7 @@
23692369
5B23AB871CE62D17000DB898 /* Boxing.swift in Sources */,
23702370
5BF7AEA41BCD51F9008F214A /* Bundle.swift in Sources */,
23712371
5B23AB891CE62D4D000DB898 /* ReferenceConvertible.swift in Sources */,
2372-
153CC8332214C3D100BFE8F3 /* ScannerAPI.swift in Sources */,
2372+
153CC8352215E00200BFE8F3 /* ScannerAPI.swift in Sources */,
23732373
D3E8D6D11C367AB600295652 /* NSSpecialValue.swift in Sources */,
23742374
EAB57B721BD1C7A5004AC5C5 /* PortMessage.swift in Sources */,
23752375
5BD31D201D5CE8C400563814 /* Bridging.swift in Sources */,

Diff for: Foundation/Scanner.swift

+54-104
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88
//
99

10-
11-
1210
import CoreFoundation
1311

1412
open class Scanner: NSObject, NSCopying {
@@ -499,120 +497,53 @@ extension String {
499497
}
500498
}
501499

502-
/// Revised API for avoiding usage of AutoreleasingUnsafeMutablePointer and better Optional usage.
503-
/// - Experiment: This is a draft API currently under consideration for official import into Foundation as a suitable alternative
504-
/// - Note: Since this API is under consideration it may be either removed or revised in the near future
500+
// This extension used to house the experimental API for Scanner. This is all deprecated in favor of API with newer semantics. Some of the experimental API have been promoted to full API with slightly different semantics; see ScannerAPI.swift.
505501
extension Scanner {
506-
public func scanInt32() -> Int32? {
507-
var value: Int32 = 0
508-
return withUnsafeMutablePointer(to: &value) { (ptr: UnsafeMutablePointer<Int32>) -> Int32? in
509-
if scanInt32(ptr) {
510-
return ptr.pointee
511-
} else {
512-
return nil
513-
}
514-
}
515-
}
502+
// These methods are in a special bit of mess:
503+
// - They used to exist here; but
504+
// - They have all been replaced by methods called scan<Type>(representation:); but
505+
// - The representation parameter has a default value, so scan<Type>() is still valid and has the same semantics as the below.
506+
// This means that the new methods _aren't_ fully source compatible — most source will correctly pick up the new .scan<Type>(representation:) with the default, but things like let method = scanner.scanInt32 may or may not work any longer.
507+
// Make sure that the signatures exist here so that in case the compiler would pick them up, we can direct people to the new ones. This should be rare.
516508

517-
public func scanInt() -> Int? {
518-
var value: Int = 0
519-
return withUnsafeMutablePointer(to: &value) { (ptr: UnsafeMutablePointer<Int>) -> Int? in
520-
if scanInt(ptr) {
521-
return ptr.pointee
522-
} else {
523-
return nil
524-
}
525-
}
526-
}
509+
// scanDecimal() is not among these methods and has not changed at all, though it has been promoted to non-experimental API.
527510

528-
public func scanInt64() -> Int64? {
529-
var value: Int64 = 0
530-
return withUnsafeMutablePointer(to: &value) { (ptr: UnsafeMutablePointer<Int64>) -> Int64? in
531-
if scanInt64(ptr) {
532-
return ptr.pointee
533-
} else {
534-
return nil
535-
}
536-
}
537-
}
511+
@available(swift, obsoleted: 5.0, renamed: "scanInt(representation:)")
512+
public func scanInt() -> Int? { return scanInt(representation: .decimal) }
538513

539-
public func scanUnsignedLongLong() -> UInt64? {
540-
var value: UInt64 = 0
541-
return withUnsafeMutablePointer(to: &value) { (ptr: UnsafeMutablePointer<UInt64>) -> UInt64? in
542-
if scanUnsignedLongLong(ptr) {
543-
return ptr.pointee
544-
} else {
545-
return nil
546-
}
547-
}
548-
}
514+
@available(swift, obsoleted: 5.0, renamed: "scanInt32(representation:)")
515+
public func scanInt32() -> Int32? { return scanInt32(representation: .decimal) }
549516

550-
public func scanFloat() -> Float? {
551-
var value: Float = 0.0
552-
return withUnsafeMutablePointer(to: &value) { (ptr: UnsafeMutablePointer<Float>) -> Float? in
553-
if scanFloat(ptr) {
554-
return ptr.pointee
555-
} else {
556-
return nil
557-
}
558-
}
559-
}
517+
@available(swift, obsoleted: 5.0, renamed: "scanInt64(representation:)")
518+
public func scanInt64() -> Int64? { return scanInt64(representation: .decimal) }
560519

561-
public func scanDouble() -> Double? {
562-
var value: Double = 0.0
563-
return withUnsafeMutablePointer(to: &value) { (ptr: UnsafeMutablePointer<Double>) -> Double? in
564-
if scanDouble(ptr) {
565-
return ptr.pointee
566-
} else {
567-
return nil
568-
}
569-
}
570-
}
520+
@available(swift, obsoleted: 5.0, renamed: "scanUInt64(representation:)")
521+
public func scanUInt64() -> UInt64? { return scanUInt64(representation: .decimal) }
522+
523+
@available(swift, obsoleted: 5.0, renamed: "scanFloat(representation:)")
524+
public func scanFloat() -> Float? { return scanFloat(representation: .decimal) }
525+
526+
@available(swift, obsoleted: 5.0, renamed: "scanDouble(representation:)")
527+
public func scanDouble() -> Double? { return scanDouble(representation: .decimal) }
571528

529+
// These existed but are now deprecated in favor of the new methods:
530+
531+
@available(swift, deprecated: 5.0, renamed: "scanUInt64(representation:)")
572532
public func scanHexInt32() -> UInt32? {
573-
var value: UInt32 = 0
574-
return withUnsafeMutablePointer(to: &value) { (ptr: UnsafeMutablePointer<UInt32>) -> UInt32? in
575-
if scanHexInt32(ptr) {
576-
return ptr.pointee
577-
} else {
578-
return nil
579-
}
580-
}
533+
guard let value = scanUInt64(representation: .hexadecimal) else { return nil }
534+
return UInt32(min(value, UInt64(UInt32.max)))
581535
}
582536

583-
public func scanHexInt64() -> UInt64? {
584-
var value: UInt64 = 0
585-
return withUnsafeMutablePointer(to: &value) { (ptr: UnsafeMutablePointer<UInt64>) -> UInt64? in
586-
if scanHexInt64(ptr) {
587-
return ptr.pointee
588-
} else {
589-
return nil
590-
}
591-
}
592-
}
537+
@available(swift, deprecated: 5.0, renamed: "scanUInt64(representation:)")
538+
public func scanHexInt64() -> UInt64? { return scanUInt64(representation: .hexadecimal) }
593539

594-
public func scanHexFloat() -> Float? {
595-
var value: Float = 0.0
596-
return withUnsafeMutablePointer(to: &value) { (ptr: UnsafeMutablePointer<Float>) -> Float? in
597-
if scanHexFloat(ptr) {
598-
return ptr.pointee
599-
} else {
600-
return nil
601-
}
602-
}
603-
}
540+
@available(swift, deprecated: 5.0, renamed: "scanFloat(representation:)")
541+
public func scanHexFloat() -> Float? { return scanFloat(representation: .hexadecimal) }
604542

605-
public func scanHexDouble() -> Double? {
606-
var value: Double = 0.0
607-
return withUnsafeMutablePointer(to: &value) { (ptr: UnsafeMutablePointer<Double>) -> Double? in
608-
if scanHexDouble(ptr) {
609-
return ptr.pointee
610-
} else {
611-
return nil
612-
}
613-
}
614-
}
543+
@available(swift, deprecated: 5.0, renamed: "scanDouble(representation:)")
544+
public func scanHexDouble() -> Double? { return scanDouble(representation: .hexadecimal) }
615545

546+
@available(swift, deprecated: 5.0, renamed: "scanString(_:)")
616547
@discardableResult
617548
public func scanString(_ string:String, into ptr: UnsafeMutablePointer<String?>?) -> Bool {
618549
if let str = _scanStringSplittingGraphemes(string) {
@@ -647,6 +578,19 @@ extension Scanner {
647578

648579
@available(swift, deprecated: 5.0, renamed: "scanCharacters(from:)")
649580
public func scanCharactersFromSet(_ set: CharacterSet) -> String? {
581+
return _scanCharactersSplittingGraphemes(from: set)
582+
}
583+
584+
@available(swift, deprecated: 5.0, renamed: "scanCharacters(from:)")
585+
public func scanCharacters(from set: CharacterSet, into ptr: UnsafeMutablePointer<String?>?) -> Bool {
586+
if let str = _scanCharactersSplittingGraphemes(from: set) {
587+
ptr?.pointee = str
588+
return true
589+
}
590+
return false
591+
}
592+
593+
private func _scanCharactersSplittingGraphemes(from set: CharacterSet) -> String? {
650594
let str = self.string._bridgeToObjectiveC()
651595
var stringLoc = scanLocation
652596
let stringLen = str.length
@@ -667,6 +611,7 @@ extension Scanner {
667611
return nil
668612
}
669613

614+
@available(swift, deprecated: 5.0, renamed: "scanUpToString(_:)")
670615
@discardableResult
671616
public func scanUpTo(_ string:String, into ptr: UnsafeMutablePointer<String?>?) -> Bool {
672617
if let str = _scanUpToStringSplittingGraphemes(string) {
@@ -697,9 +642,10 @@ extension Scanner {
697642
return nil
698643
}
699644

645+
@available(swift, deprecated: 5.0, renamed: "scanUpToCharacters(from:)")
700646
@discardableResult
701647
public func scanUpToCharacters(from set: CharacterSet, into ptr: UnsafeMutablePointer<String?>?) -> Bool {
702-
if let result = scanUpToCharactersFromSet(set) {
648+
if let result = _scanSplittingGraphemesUpToCharacters(from: set) {
703649
ptr?.pointee = result
704650
return true
705651
}
@@ -708,6 +654,10 @@ extension Scanner {
708654

709655
@available(swift, deprecated: 5.0, renamed: "scanUpToCharacters(from:)")
710656
public func scanUpToCharactersFromSet(_ set: CharacterSet) -> String? {
657+
return _scanSplittingGraphemesUpToCharacters(from: set)
658+
}
659+
660+
private func _scanSplittingGraphemesUpToCharacters(from set: CharacterSet) -> String? {
711661
let str = self.string._bridgeToObjectiveC()
712662
var stringLoc = scanLocation
713663
let stringLen = str.length

0 commit comments

Comments
 (0)