Skip to content

Commit fbb3262

Browse files
committed
Split out URLQueryItem from URLComponents.swift
- struct URLQueryItem => URLQueryItem.swift
1 parent a4807da commit fbb3262

File tree

4 files changed

+107
-93
lines changed

4 files changed

+107
-93
lines changed

Diff for: Foundation.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@
406406
B96C10F625BA1EFD00985A32 /* NSURLComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = B96C10F525BA1EFD00985A32 /* NSURLComponents.swift */; };
407407
B96C110025BA20A600985A32 /* NSURLQueryItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B96C10FF25BA20A600985A32 /* NSURLQueryItem.swift */; };
408408
B96C110A25BA215800985A32 /* URLResourceKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = B96C110925BA215800985A32 /* URLResourceKey.swift */; };
409+
B96C112525BA2CE700985A32 /* URLQueryItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B96C112425BA2CE700985A32 /* URLQueryItem.swift */; };
409410
B983E32C23F0C69600D9C402 /* Docs in Resources */ = {isa = PBXBuildFile; fileRef = B983E32B23F0C69600D9C402 /* Docs */; };
410411
B983E32E23F0C6E200D9C402 /* CONTRIBUTING.md in Resources */ = {isa = PBXBuildFile; fileRef = B983E32D23F0C6E200D9C402 /* CONTRIBUTING.md */; };
411412
B98E33DD2136AA740044EBE9 /* TestFileWithZeros.txt in Resources */ = {isa = PBXBuildFile; fileRef = B98E33DC2136AA740044EBE9 /* TestFileWithZeros.txt */; };
@@ -1114,6 +1115,7 @@
11141115
B96C10F525BA1EFD00985A32 /* NSURLComponents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSURLComponents.swift; sourceTree = "<group>"; };
11151116
B96C10FF25BA20A600985A32 /* NSURLQueryItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSURLQueryItem.swift; sourceTree = "<group>"; };
11161117
B96C110925BA215800985A32 /* URLResourceKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLResourceKey.swift; sourceTree = "<group>"; };
1118+
B96C112425BA2CE700985A32 /* URLQueryItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLQueryItem.swift; sourceTree = "<group>"; };
11171119
B983E32B23F0C69600D9C402 /* Docs */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Docs; sourceTree = "<group>"; };
11181120
B983E32D23F0C6E200D9C402 /* CONTRIBUTING.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = CONTRIBUTING.md; sourceTree = "<group>"; };
11191121
B98E33DC2136AA740044EBE9 /* TestFileWithZeros.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = TestFileWithZeros.txt; sourceTree = "<group>"; };
@@ -2171,6 +2173,7 @@
21712173
5BECBA3B1D1CAF8800B39B1F /* Unit.swift */,
21722174
5B23AB8C1CE63228000DB898 /* URL.swift */,
21732175
5BCCA8D81CE6697F0059B963 /* URLComponents.swift */,
2176+
B96C112425BA2CE700985A32 /* URLQueryItem.swift */,
21742177
B96C110925BA215800985A32 /* URLResourceKey.swift */,
21752178
EADE0B871BD15DFF00C49C64 /* UserDefaults.swift */,
21762179
6EB768271D18C12C00D4B719 /* UUID.swift */,
@@ -2960,6 +2963,7 @@
29602963
1513A8432044893F00539722 /* FileManager+XDG.swift in Sources */,
29612964
91B668A52252B3E7001487A1 /* FileManager+Win32.swift in Sources */,
29622965
5BCD03821D3EE35C00E3FF9B /* TimeZone.swift in Sources */,
2966+
B96C112525BA2CE700985A32 /* URLQueryItem.swift in Sources */,
29632967
5BC1B9AC21F275D500524D8C /* NSData+DataProtocol.swift in Sources */,
29642968
5B4092121D1B30B40022B067 /* ExtraStringAPIs.swift in Sources */,
29652969
5BC46D541D05D6D900005853 /* DateInterval.swift in Sources */,

Diff for: Sources/Foundation/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ add_library(Foundation
132132
Unit.swift
133133
URL.swift
134134
URLComponents.swift
135+
URLQueryItem.swift
135136
URLResourceKey.swift
136137
UserDefaults.swift
137138
UUID.swift)

Diff for: Sources/Foundation/URLComponents.swift

-93
Original file line numberDiff line numberDiff line change
@@ -318,59 +318,6 @@ extension URLComponents : CustomStringConvertible, CustomDebugStringConvertible,
318318
}
319319
}
320320

321-
/// A single name-value pair, for use with `URLComponents`.
322-
public struct URLQueryItem : ReferenceConvertible, Hashable, Equatable {
323-
public typealias ReferenceType = NSURLQueryItem
324-
325-
fileprivate var _queryItem : NSURLQueryItem
326-
327-
public init(name: String, value: String?) {
328-
_queryItem = NSURLQueryItem(name: name, value: value)
329-
}
330-
331-
fileprivate init(reference: NSURLQueryItem) { _queryItem = reference.copy() as! NSURLQueryItem }
332-
fileprivate var reference : NSURLQueryItem { return _queryItem }
333-
334-
public var name: String {
335-
get { return _queryItem.name }
336-
set { _queryItem = NSURLQueryItem(name: newValue, value: value) }
337-
}
338-
339-
public var value: String? {
340-
get { return _queryItem.value }
341-
set { _queryItem = NSURLQueryItem(name: name, value: newValue) }
342-
}
343-
344-
public func hash(into hasher: inout Hasher) {
345-
hasher.combine(_queryItem)
346-
}
347-
348-
public static func ==(lhs: URLQueryItem, rhs: URLQueryItem) -> Bool {
349-
return lhs._queryItem.isEqual(rhs._queryItem)
350-
}
351-
}
352-
353-
extension URLQueryItem : CustomStringConvertible, CustomDebugStringConvertible, CustomReflectable {
354-
public var description: String {
355-
if let v = value {
356-
return "\(name)=\(v)"
357-
} else {
358-
return name
359-
}
360-
}
361-
362-
public var debugDescription: String {
363-
return self.description
364-
}
365-
366-
public var customMirror: Mirror {
367-
var c: [(label: String?, value: Any)] = []
368-
c.append((label: "name", value: name))
369-
c.append((label: "value", value: value as Any))
370-
return Mirror(self, children: c, displayStyle: .struct)
371-
}
372-
}
373-
374321
extension NSURLComponents : _SwiftBridgeable {
375322
typealias SwiftType = URLComponents
376323
internal var _swiftObject: SwiftType { return URLComponents(reference: self) }
@@ -381,16 +328,6 @@ extension URLComponents : _NSBridgeable {
381328
internal var _nsObject: NSType { return _handle._copiedReference() }
382329
}
383330

384-
extension NSURLQueryItem : _SwiftBridgeable {
385-
typealias SwiftType = URLQueryItem
386-
internal var _swiftObject: SwiftType { return URLQueryItem(reference: self) }
387-
}
388-
389-
extension URLQueryItem : _NSBridgeable {
390-
typealias NSType = NSURLQueryItem
391-
internal var _nsObject: NSType { return _queryItem }
392-
}
393-
394331
extension URLComponents : _ObjectiveCBridgeable {
395332
public typealias _ObjectType = NSURLComponents
396333

@@ -421,36 +358,6 @@ extension URLComponents : _ObjectiveCBridgeable {
421358
}
422359
}
423360

424-
extension URLQueryItem : _ObjectiveCBridgeable {
425-
public typealias _ObjectType = NSURLQueryItem
426-
427-
public static func _getObjectiveCType() -> Any.Type {
428-
return NSURLQueryItem.self
429-
}
430-
431-
@_semantics("convertToObjectiveC")
432-
public func _bridgeToObjectiveC() -> NSURLQueryItem {
433-
return _queryItem
434-
}
435-
436-
public static func _forceBridgeFromObjectiveC(_ x: NSURLQueryItem, result: inout URLQueryItem?) {
437-
if !_conditionallyBridgeFromObjectiveC(x, result: &result) {
438-
fatalError("Unable to bridge \(_ObjectType.self) to \(self)")
439-
}
440-
}
441-
442-
public static func _conditionallyBridgeFromObjectiveC(_ x: NSURLQueryItem, result: inout URLQueryItem?) -> Bool {
443-
result = URLQueryItem(reference: x)
444-
return true
445-
}
446-
447-
public static func _unconditionallyBridgeFromObjectiveC(_ source: NSURLQueryItem?) -> URLQueryItem {
448-
var result: URLQueryItem? = nil
449-
_forceBridgeFromObjectiveC(source!, result: &result)
450-
return result!
451-
}
452-
}
453-
454361
extension URLComponents : Codable {
455362
private enum CodingKeys : Int, CodingKey {
456363
case scheme

Diff for: Sources/Foundation/URLQueryItem.swift

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// This source file is part of the Swift.org open source project
2+
//
3+
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
4+
// Licensed under Apache License v2.0 with Runtime Library Exception
5+
//
6+
// See https://swift.org/LICENSE.txt for license information
7+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
8+
//
9+
10+
11+
/// A single name-value pair, for use with `URLComponents`.
12+
public struct URLQueryItem: ReferenceConvertible, Hashable, Equatable {
13+
public typealias ReferenceType = NSURLQueryItem
14+
15+
fileprivate var _queryItem: NSURLQueryItem
16+
17+
public init(name: String, value: String?) {
18+
_queryItem = NSURLQueryItem(name: name, value: value)
19+
}
20+
21+
fileprivate init(reference: NSURLQueryItem) { _queryItem = reference.copy() as! NSURLQueryItem }
22+
fileprivate var reference: NSURLQueryItem { return _queryItem }
23+
24+
public var name: String {
25+
get { return _queryItem.name }
26+
set { _queryItem = NSURLQueryItem(name: newValue, value: value) }
27+
}
28+
29+
public var value: String? {
30+
get { return _queryItem.value }
31+
set { _queryItem = NSURLQueryItem(name: name, value: newValue) }
32+
}
33+
34+
public func hash(into hasher: inout Hasher) {
35+
hasher.combine(_queryItem)
36+
}
37+
38+
public static func ==(lhs: URLQueryItem, rhs: URLQueryItem) -> Bool {
39+
return lhs._queryItem.isEqual(rhs._queryItem)
40+
}
41+
}
42+
43+
extension URLQueryItem: CustomStringConvertible, CustomDebugStringConvertible, CustomReflectable {
44+
public var description: String {
45+
if let v = value {
46+
return "\(name)=\(v)"
47+
} else {
48+
return name
49+
}
50+
}
51+
52+
public var debugDescription: String {
53+
return self.description
54+
}
55+
56+
public var customMirror: Mirror {
57+
var c: [(label: String?, value: Any)] = []
58+
c.append((label: "name", value: name))
59+
c.append((label: "value", value: value as Any))
60+
return Mirror(self, children: c, displayStyle: .struct)
61+
}
62+
}
63+
64+
extension URLQueryItem: _NSBridgeable {
65+
typealias NSType = NSURLQueryItem
66+
internal var _nsObject: NSType { return _queryItem }
67+
}
68+
69+
extension URLQueryItem: _ObjectiveCBridgeable {
70+
public typealias _ObjectType = NSURLQueryItem
71+
72+
public static func _getObjectiveCType() -> Any.Type {
73+
return NSURLQueryItem.self
74+
}
75+
76+
@_semantics("convertToObjectiveC")
77+
public func _bridgeToObjectiveC() -> NSURLQueryItem {
78+
return _queryItem
79+
}
80+
81+
public static func _forceBridgeFromObjectiveC(_ x: NSURLQueryItem, result: inout URLQueryItem?) {
82+
if !_conditionallyBridgeFromObjectiveC(x, result: &result) {
83+
fatalError("Unable to bridge \(_ObjectType.self) to \(self)")
84+
}
85+
}
86+
87+
public static func _conditionallyBridgeFromObjectiveC(_ x: NSURLQueryItem, result: inout URLQueryItem?) -> Bool {
88+
result = URLQueryItem(reference: x)
89+
return true
90+
}
91+
92+
public static func _unconditionallyBridgeFromObjectiveC(_ source: NSURLQueryItem?) -> URLQueryItem {
93+
var result: URLQueryItem? = nil
94+
_forceBridgeFromObjectiveC(source!, result: &result)
95+
return result!
96+
}
97+
}
98+
99+
extension NSURLQueryItem: _SwiftBridgeable {
100+
typealias SwiftType = URLQueryItem
101+
internal var _swiftObject: SwiftType { return URLQueryItem(reference: self) }
102+
}

0 commit comments

Comments
 (0)