Skip to content

Commit 0b6479b

Browse files
committed
Merge pull request #43 from ken0nek/master
Improve control flow and some fix
2 parents 720a9de + ec6e09b commit 0b6479b

File tree

1 file changed

+37
-49
lines changed

1 file changed

+37
-49
lines changed

Foundation/NSXMLParser.swift

Lines changed: 37 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -73,48 +73,40 @@ internal func _NSXMLParserExternalEntityWithURL(interface: _CFXMLInterface, urlS
7373

7474
switch policy {
7575
case .ResolveExternalEntitiesSameOriginOnly:
76-
if let url = parser._url {
77-
if a == nil {
78-
a = NSURL(string: String(urlStr))
76+
guard let url = parser._url else { break }
77+
78+
if a == nil {
79+
a = NSURL(string: String(urlStr))
80+
}
81+
82+
guard let aUrl = a else { break }
83+
84+
var matches: Bool
85+
if let aHost = aUrl.host, host = url.host {
86+
matches = host == aHost
87+
} else {
88+
return nil
89+
}
90+
91+
if matches {
92+
if let aPort = aUrl.port, port = url.port {
93+
matches = port == aPort
94+
} else {
95+
return nil
7996
}
80-
if let aUrl = a {
81-
var matches: Bool
82-
if let aHost = aUrl.host {
83-
if let host = url.host {
84-
matches = host == aHost
85-
} else {
86-
matches = false
87-
}
88-
} else {
89-
matches = false
90-
}
91-
if matches {
92-
if let aPort = aUrl.port {
93-
if let port = url.port {
94-
matches = port == aPort
95-
} else {
96-
matches = false
97-
}
98-
} else {
99-
matches = false
100-
}
101-
}
102-
if matches {
103-
if let aScheme = aUrl.scheme {
104-
if let scheme = url.scheme {
105-
matches = scheme == aScheme
106-
} else {
107-
matches = false
108-
}
109-
} else {
110-
matches = false
111-
}
112-
}
113-
if !matches {
114-
return nil
115-
}
97+
}
98+
99+
if matches {
100+
if let aScheme = aUrl.scheme, scheme = url.scheme {
101+
matches = scheme == aScheme
102+
} else {
103+
return nil
116104
}
117105
}
106+
107+
if !matches {
108+
return nil
109+
}
118110
break
119111
case .ResolveExternalEntitiesAlways:
120112
break
@@ -262,18 +254,14 @@ internal func _NSXMLParserStartElementNs(ctx: _CFXMLInterface, localname: Unsafe
262254
asAttrNamespaceNameString = "xmlns"
263255
}
264256
let namespaceValueString = namespaces[idx + 1] == nil ? UTF8STRING(namespaces[idx + 1]) : ""
265-
if (reportNamespaces) {
266-
if let k = namespaceNameString {
267-
if let v = namespaceValueString {
268-
nsDict[k] = v
269-
}
257+
if reportNamespaces {
258+
if let k = namespaceNameString, v = namespaceValueString {
259+
nsDict[k] = v
270260
}
271261
}
272262
if !reportQNameURI {
273-
if let k = asAttrNamespaceNameString {
274-
if let v = namespaceValueString {
275-
attrDict[k] = v
276-
}
263+
if let k = asAttrNamespaceNameString, v = namespaceValueString {
264+
attrDict[k] = v
277265
}
278266
}
279267
}
@@ -335,7 +323,7 @@ internal func _NSXMLParserEndElementNs(ctx: _CFXMLInterface , localname: UnsafeP
335323

336324

337325
if let delegate = parser.delegate {
338-
if (reportQNameURI) {
326+
if reportQNameURI {
339327
// When reporting namespace info, the delegate parameters are not passed in nil
340328
delegate.parser(parser, didEndElement: localnameString!, namespaceURI: namespaceURIString == nil ? "" : namespaceURIString, qualifiedName: qualifiedNameString == nil ? "" : qualifiedNameString)
341329
} else {

0 commit comments

Comments
 (0)