Skip to content

Commit 855aeb7

Browse files
authored
Merge pull request #14 from kyleishie/master
Added .none the StringEncodingStrategy
2 parents f0fbfe1 + d66c6e5 commit 855aeb7

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

Sources/XMLCoding/Encoder/XMLEncoder.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ open class XMLEncoder {
6464

6565
/// Encoded the `String` as a CData-encoded string.
6666
case cdata
67+
68+
/// Do NOT encode the `String`.
69+
case none
6770
}
6871

6972
/// The strategy to use for encoding `Data` values.
@@ -164,6 +167,7 @@ open class XMLEncoder {
164167
return result
165168
}
166169
}
170+
167171

168172
/// The strategy to use for encoding attributes on a node.
169173
public enum AttributeEncodingStrategy {

Sources/XMLCoding/XMLStackParser.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ internal class _XMLElement {
9595
throw EncodingError.invalidValue(object, EncodingError.Context(codingPath: [], debugDescription: "Top-level encoded as non-root XML fragment."))
9696
}
9797

98-
return element.toXMLString(with: header, withCDATA: options.stringEncodingStrategy != .deferredToString).data(using: .utf8, allowLossyConversion: true)!
98+
return element.toXMLString(with: header, withCDATA: options.stringEncodingStrategy == .cdata, ignoreEscaping: options.stringEncodingStrategy == .none).data(using: .utf8, allowLossyConversion: true)!
9999
}
100100

101101
fileprivate static func createElement(parentElement: _XMLElement?, key: String, object: [String: Container]) {
@@ -200,13 +200,13 @@ internal class _XMLElement {
200200

201201
func toXMLString(with header: XMLHeader? = nil, withCDATA cdata: Bool, ignoreEscaping: Bool = false) -> String {
202202
if let header = header, let headerXML = header.toXML() {
203-
return headerXML + _toXMLString(withCDATA: cdata)
203+
return headerXML + _toXMLString(withCDATA: cdata, ignoreEscaping: ignoreEscaping)
204204
} else {
205-
return _toXMLString(withCDATA: cdata)
205+
return _toXMLString(withCDATA: cdata, ignoreEscaping: ignoreEscaping)
206206
}
207207
}
208208

209-
fileprivate func _toXMLString(indented level: Int = 0, withCDATA cdata: Bool, ignoreEscaping: Bool = false) -> String {
209+
fileprivate func _toXMLString(indented level: Int = 0, withCDATA cdata: Bool, ignoreEscaping: Bool) -> String {
210210
var string = String(repeating: " ", count: level * 4)
211211
string += "<\(key)"
212212

@@ -227,7 +227,7 @@ internal class _XMLElement {
227227

228228
for childElement in children {
229229
for child in childElement.value {
230-
string += child._toXMLString(indented: level + 1, withCDATA: cdata)
230+
string += child._toXMLString(indented: level + 1, withCDATA: cdata, ignoreEscaping: ignoreEscaping)
231231
string += "\n"
232232
}
233233
}

0 commit comments

Comments
 (0)