Skip to content

Commit c60c771

Browse files
committed
Ninja does not quite support this extension arrangement.
- Move `_parseArguments` into UserDefaults.swift.
1 parent 2134642 commit c60c771

File tree

4 files changed

+51
-62
lines changed

4 files changed

+51
-62
lines changed

Foundation.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
1520469B1D8AEABE00D02E36 /* HTTPServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1520469A1D8AEABE00D02E36 /* HTTPServer.swift */; };
1313
153E951120111DC500F250BE /* CFKnownLocations.h in Headers */ = {isa = PBXBuildFile; fileRef = 153E950F20111DC500F250BE /* CFKnownLocations.h */; settings = {ATTRIBUTES = (Private, ); }; };
1414
153E951220111DC500F250BE /* CFKnownLocations.c in Sources */ = {isa = PBXBuildFile; fileRef = 153E951020111DC500F250BE /* CFKnownLocations.c */; };
15-
153E95162012A29900F250BE /* UserDefaults_Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 153E95152012A29900F250BE /* UserDefaults_Arguments.swift */; };
1615
159884921DCC877700E3314C /* TestHTTPCookieStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 159884911DCC877700E3314C /* TestHTTPCookieStorage.swift */; };
1716
231503DB1D8AEE5D0061694D /* TestDecimal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 231503DA1D8AEE5D0061694D /* TestDecimal.swift */; };
1817
294E3C1D1CC5E19300E4F44C /* TestNSAttributedString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 294E3C1C1CC5E19300E4F44C /* TestNSAttributedString.swift */; };
@@ -503,7 +502,6 @@
503502
1520469A1D8AEABE00D02E36 /* HTTPServer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPServer.swift; sourceTree = "<group>"; };
504503
153E950F20111DC500F250BE /* CFKnownLocations.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CFKnownLocations.h; sourceTree = "<group>"; };
505504
153E951020111DC500F250BE /* CFKnownLocations.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = CFKnownLocations.c; sourceTree = "<group>"; };
506-
153E95152012A29900F250BE /* UserDefaults_Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaults_Arguments.swift; sourceTree = "<group>"; };
507505
159884911DCC877700E3314C /* TestHTTPCookieStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestHTTPCookieStorage.swift; sourceTree = "<group>"; };
508506
22B9C1E01C165D7A00DECFF9 /* TestDate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestDate.swift; sourceTree = "<group>"; };
509507
231503DA1D8AEE5D0061694D /* TestDecimal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestDecimal.swift; sourceTree = "<group>"; };
@@ -1795,7 +1793,6 @@
17951793
isa = PBXGroup;
17961794
children = (
17971795
EADE0B871BD15DFF00C49C64 /* UserDefaults.swift */,
1798-
153E95152012A29900F250BE /* UserDefaults_Arguments.swift */,
17991796
5BDC3F3B1BCC5DCB00ED97BB /* NSLocale.swift */,
18001797
5BD70FB11D3D4CDC003B9BF8 /* Locale.swift */,
18011798
);
@@ -2194,7 +2191,6 @@
21942191
61E0117E1C1B55B9000037DD /* Timer.swift in Sources */,
21952192
EADE0BCD1BD15E0000C49C64 /* XMLParser.swift in Sources */,
21962193
5BDC3FD01BCF17E600ED97BB /* NSCFSet.swift in Sources */,
2197-
153E95162012A29900F250BE /* UserDefaults_Arguments.swift in Sources */,
21982194
5B1FD9DE1D6D16580080E83C /* TaskRegistry.swift in Sources */,
21992195
EADE0B931BD15DFF00C49C64 /* NSComparisonPredicate.swift in Sources */,
22002196
5B1FD9DC1D6D16580080E83C /* URLSessionDelegate.swift in Sources */,

Foundation/UserDefaults.swift

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,54 @@ extension UserDefaults {
408408
public static let argumentDomain: String = "NSArgumentDomain"
409409
public static let registrationDomain: String = "NSRegistrationDomain"
410410
}
411+
412+
// MARK: -
413+
// MARK: Parsing arguments.
414+
415+
fileprivate let propertyListPrefixes: Set<Character> = [ "{", "[", "(", "<", "\"" ]
416+
417+
private extension UserDefaults {
418+
static func _parseArguments(_ arguments: [String]) -> [String: Any] {
419+
var result: [String: Any] = [:]
420+
421+
let count = arguments.count
422+
423+
var index = 0
424+
while index < count - 1 { // We're looking for pairs, so stop at the second-to-last argument.
425+
let current = arguments[index]
426+
let next = arguments[index + 1]
427+
if current.hasPrefix("-") && !next.hasPrefix("-") {
428+
// Match what Darwin does, which is to check whether the first argument is one of the characters that make up a NeXTStep-style or XML property list: open brace, open parens, open bracket, open angle bracket, or double quote. If it is, attempt parsing it as a plist; otherwise, just use the argument value as a String.
429+
430+
let keySubstring = current[current.index(after: current.startIndex)...]
431+
if !keySubstring.isEmpty {
432+
let key = String(keySubstring)
433+
let value = next.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
434+
435+
var parsed = false
436+
if let prefix = value.first, propertyListPrefixes.contains(prefix) {
437+
if let data = value.data(using: .utf8),
438+
let plist = try? PropertyListSerialization.propertyList(from: data, format: nil) {
439+
440+
// If we can parse that argument as a plist, use the parsed value.
441+
parsed = true
442+
result[key] = plist
443+
444+
}
445+
}
446+
447+
if !parsed {
448+
result[key] = value
449+
}
450+
}
451+
452+
index += 1 // Skip both the key and the value on this loop.
453+
}
454+
455+
index += 1
456+
}
457+
458+
return result
459+
}
460+
}
461+

Foundation/UserDefaults_Arguments.swift

Lines changed: 0 additions & 57 deletions
This file was deleted.

build.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,6 @@
446446
'Foundation/URLSession/libcurl/libcurlHelpers.swift',
447447
'Foundation/URLSession/http/HTTPURLProtocol.swift',
448448
'Foundation/UserDefaults.swift',
449-
'Foundation/UserDefaults_Arguments.swift',
450449
'Foundation/NSUUID.swift',
451450
'Foundation/NSValue.swift',
452451
'Foundation/XMLDocument.swift',

0 commit comments

Comments
 (0)