<commit_before>//  Created by <NAME> on 07/06/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

extension MomUserInfo: XMLConvertible {

    public var xml: String {
        var output = ""
        output += " <userInfo>\n"
        for entry in entries {
            output += entry.xml
            output += "\n"
        }
        output += " </userInfo>"

        return output
    }

}

extension MomUserInfoEntry: XMLConvertible {

    public var xml: String {
        return "<element key=\"\(key)\" value=\"\(value)\"/>"
    }

}<commit_msg>XML escape value in user info entry when converting to xml<commit_after>//  Created by <NAME> on 07/06/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

extension MomUserInfo: XMLConvertible {

    public var xml: String {
        var output = ""
        output += " <userInfo>\n"
        for entry in entries {
            output += entry.xml
            output += "\n"
        }
        output += " </userInfo>"

        return output
    }

}

extension MomUserInfoEntry: XMLConvertible {

    public var xml: String {
        return "<element key=\"\(key)\" value=\"\(value.xmlSimpleEscape)\"/>"
    }

}


extension String {

    private typealias SimpleToFromRepalceList = [(fromSubString: String, toSubString: String)]
    private static let xmlUnescapeMapList : SimpleToFromRepalceList = [
        ("&amp;",  "&"),
        ("&quot;", "\""),
        ("&#x27;", "'"),
        ("&#39;",  "'"),
        ("&#x92;", "'"),
        ("&#x96;", "-"),
        ("&gt;",   ">"),
        ("&lt;",   "<")]
    private static let xmlEscapeMapList : SimpleToFromRepalceList = [
        ("&",  "&amp;"),
        ("\"", "&quot;"),
        ("'",  "&#x27;"),
        (">",  "&gt;"),
        ("<",  "&lt;")]

    private func simpleReplace(_ mapList: SimpleToFromRepalceList ) -> String {
        var string = self
        for (fromStr, toStr) in mapList {
            let separatedList = string.components(separatedBy: fromStr)
            if separatedList.count > 1 {
                string = separatedList.joined(separator: toStr)
            }
        }
        return string
    }

    var xmlSimpleUnescape: String {
        return self.simpleReplace(String.xmlUnescapeMapList)
    }

    var xmlSimpleEscape: String {
        return self.simpleReplace(String.xmlEscapeMapList)
    }
}
{'fraction_non_alphanumeric': 0.15365239294710328, 'fraction_numerical': 0.014693534844668345, 'mean_word_length': 2.066924066924067, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5387005', 'n_tokens_mistral': 752, 'n_tokens_neox': 704, 'n_words': 176}