Skip to content

Commit d66c6e5

Browse files
committed
Added .none the StringEncodingStrategy
Updated _XMLElement.createRootElement to set ignoreEscaping parameter in call to element.toXMLString Updated toXMLString to pass along ignoreEscaping to _toXMLString Removed default value for ignoreEscaping in _toXMLString
1 parent ba3439e commit d66c6e5

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
@@ -91,7 +91,7 @@ internal class _XMLElement {
9191
throw EncodingError.invalidValue(object, EncodingError.Context(codingPath: [], debugDescription: "Top-level encoded as non-root XML fragment."))
9292
}
9393

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

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

197197
func toXMLString(with header: XMLHeader? = nil, withCDATA cdata: Bool, ignoreEscaping: Bool = false) -> String {
198198
if let header = header, let headerXML = header.toXML() {
199-
return headerXML + _toXMLString(withCDATA: cdata)
199+
return headerXML + _toXMLString(withCDATA: cdata, ignoreEscaping: ignoreEscaping)
200200
} else {
201-
return _toXMLString(withCDATA: cdata)
201+
return _toXMLString(withCDATA: cdata, ignoreEscaping: ignoreEscaping)
202202
}
203203
}
204204

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

@@ -223,7 +223,7 @@ internal class _XMLElement {
223223

224224
for childElement in children {
225225
for child in childElement.value {
226-
string += child._toXMLString(indented: level + 1, withCDATA: cdata)
226+
string += child._toXMLString(indented: level + 1, withCDATA: cdata, ignoreEscaping: ignoreEscaping)
227227
string += "\n"
228228
}
229229
}

0 commit comments

Comments
 (0)