<commit_before>//
//  String+XQueryComponents.swift
//  iAsync_network
//
//  Created by <NAME> on 13.10.14.
//  Copyright © 2014 EmbeddedSources. All rights reserved.
//

import Foundation

import iAsync_utils

public extension String {

    func stringByDecodingURLQueryComponents() -> String? {

        return stringByRemovingPercentEncoding
    }

    func stringByEncodingURLQueryComponents() -> String {

        //old one variant - " <>#%'\";?:@&=+$/,{}|\\^~[]`-*!()"
        let charactersToBeEscaped = ":/?&=;+!@#$()',*" as CFStringRef
        let charactersToLeaveUnescaped = "[]." as CFStringRef

        let str = self as NSString

        let result = CFURLCreateStringByAddingPercentEscapes(
            kCFAllocatorDefault,
            str as CFString,
            charactersToLeaveUnescaped,
            charactersToBeEscaped,
            CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)) as NSString

        return result as String
    }

    func dictionaryFromQueryComponents() -> [String:[String]] {

        var result = [String:[String]]()

        for keyValuePairString in componentsSeparatedByString("&") {

            let keyValuePairArray = keyValuePairString.componentsSeparatedByString("=") as [String]

            // Verify that there is at least one key, and at least one value.  Ignore extra = signs
            if keyValuePairArray.count < 2 {
                continue
            }

            let decodedKey = keyValuePairArray[0]
            guard let key = decodedKey.stringByDecodingURLQueryComponents() else {

                iAsync_utils_logger.logError("can not decode key: \(decodedKey)", context: #function)
                continue
            }

            let decodedVal = keyValuePairArray[1]
            guard let value = decodedVal.stringByDecodingURLQueryComponents() else {
<commit_msg>remove reprecations<commit_after>//
//  String+XQueryComponents.swift
//  iAsync_network
//
//  Created by <NAME> on 13.10.14.
//  Copyright © 2014 EmbeddedSources. All rights reserved.
//

import Foundation

import iAsync_utils

public extension String {

    func stringByDecodingURLQueryComponents() -> String? {

        return stringByRemovingPercentEncoding
    }

    func stringByEncodingURLQueryComponents() -> String {

        let result = stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())
        return result ?? self
    }

    func dictionaryFromQueryComponents() -> [String:[String]] {

        var result = [String:[String]]()

        for keyValuePairString in componentsSeparatedByString("&") {

            let keyValuePairArray = keyValuePairString.componentsSeparatedByString("=") as [String]

            // Verify that there is at least one key, and at least one value.  Ignore extra = signs
            if keyValuePairArray.count < 2 {
                continue
            }

            let decodedKey = keyValuePairArray[0]
            guard let key = decodedKey.stringByDecodingURLQueryComponents() else {

                iAsync_utils_logger.logError("can not decode key: \(decodedKey)", context: #function)
                continue
            }

            let decodedVal = keyValuePairArray[1]
            guard let value = decodedVal.stringByDecodingURLQueryComponents() else {

{'fraction_non_alphanumeric': 0.0916214587100663, 'fraction_numerical': 0.0081374321880651, 'mean_word_length': 2.564983888292159, 'pattern_counts': {'":': 1, '<': 8, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '7314383', 'n_tokens_mistral': 924, 'n_tokens_neox': 847, 'n_words': 217}