<commit_before><?php
/**
 *  XML encode/decode
 */
namespace Converter\Xml;

/**
 * XML decode
 *
 * @param string $text input string
 *
 * @return array
 */
function decode(string $text)
{
    $xml   = simplexml_load_string($text, 'SimpleXMLElement', LIBXML_NOCDATA);
    $array = json_decode(json_encode($xml), true);
    foreach ($array as $key => $value) {
        if ((string)(int)$value === $value) {
            $array[$key] = (int)$value;
        }
    }
    return $array;
}

/**
 * XML encode
 *
 * @param array $arr input array
 *
 * @return string
 */
function encode(array $arr)
{
    $array_to_xml = function ($data, &$xml_data) use (&$array_to_xml) {
        foreach ($data as $key => $value) {
            if (is_array($value)) {
                if (is_numeric($key)) {
                    $key = 'item'.$key; //dealing with <0/>..<n/> issues
                }
                $subnode = $xml_data->addChild($key);
                $array_to_xml($value, $subnode);
            } else {
                if (is_numeric($key)) {
                    $key = 'item'.$key; //dealing with <0/>..<n/> issues
                }
                $xml_data->addChild("$key", $value);
            }
        }
    };
    $xml_data = new \SimpleXMLElement(
        '<?xml version="1.0" encoding="UTF-8"?><data></data>'
    );
    $array_to_xml($arr, $xml_data);
    return $xml_data->asXML();
}<commit_msg>second attempt<commit_after><?php
/**
 *  XML encode/decode
 */
namespace Converter\Xml;

/**
 * XML decode
 *
 * @param string $text input string
 *
 * @return array
 */
function decode(string $text)
{
    $xml   = simplexml_load_string($text, 'SimpleXMLElement', LIBXML_NOCDATA);
    $array = json_decode(json_encode($xml), true);
    foreach ($array as $key => $value) {
        if ((string)(int)$value === $value) {
            $array[$key] = (int)$value;
        }
    }
    return $array;
}

/**
 * XML encode
 *
 * @param array $arr input array
 *
 * @return string
 */
function encode(array $arr)
{
    $array_to_xml = function ($data, &$xml_data) use (&$array_to_xml) {
        foreach ($data as $key => $value) {
            if (is_array($value)) {
                $subnode = $xml_data->addChild($key);
                $array_to_xml($value, $subnode);
            } else {
                $xml_data->addChild("$key", $value);
            }
        }
    };
    $xml_data = new \SimpleXMLElement(
        '<?xml version="1.0" encoding="UTF-8"?><data></data>'
    );
    $array_to_xml($arr, $xml_data);
    return $xml_data->asXML();
}
{'fraction_non_alphanumeric': 0.17589320769532785, 'fraction_numerical': 0.0031409501374165686, 'mean_word_length': 2.145679012345679, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 2, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 28}, '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': '873547', 'n_tokens_mistral': 852, 'n_tokens_neox': 838, 'n_words': 173}