<commit_before>/**
 * Hex
 *
 * Utility class to convert Hex strings to ByteArray or String types.
 * Copyright (c) 2007 <NAME>
 *
 * See LICENSE.txt for full license information.
 */
package org.mangui.hls.utils {
    import flash.utils.ByteArray;

    public class Hex {
        /**
         * Generates byte-array from given hexadecimal string
         *
         * Supports straight and colon-laced hex (that means 23:03:0e:f0, but *NOT* 23:3:e:f0)
         * The first nibble (hex digit) may be omitted.
         * Any whitespace characters are ignored.
         */
        public static function toArray(hex : String) : ByteArray {
            hex = hex.replace(/^0x|\s|:/gm, '');
            var a : ByteArray = new ByteArray;
            if ((hex.length & 1) == 1) hex = "0" + hex;
            for (var i : uint = 0; i < hex.length; i += 2) {
                a[i / 2] = parseInt(hex.substr(i, 2), 16);
            }
            return a;
        }

        /**
         * Generates lowercase hexadecimal string from given byte-array
         */
        public static function fromArray(array : ByteArray, colons : Boolean = false) : String {
            var s : String = "";
            for (var i : uint = 0; i < array.length; i++) {
                s += ("0" + array[i].toString(16)).substr(-2, 2);
                if (colons) {
                    if (i < array.length - 1) s += ":";
                }
            }
            return s;
        }
    }
}<commit_msg>optimize loop<commit_after>/**
 * Hex
 *
 * Utility class to convert Hex strings to ByteArray or String types.
 * Copyright (c) 2007 <NAME>
 *
 * See LICENSE.txt for full license information.
 */
package org.mangui.hls.utils {
    import flash.utils.ByteArray;

    public class Hex {
        /**
         * Generates byte-array from given hexadecimal string
         *
         * Supports straight and colon-laced hex (that means 23:03:0e:f0, but *NOT* 23:3:e:f0)
         * The first nibble (hex digit) may be omitted.
         * Any whitespace characters are ignored.
         */
        public static function toArray(hex : String) : ByteArray {
            hex = hex.replace(/^0x|\s|:/gm, '');
            var a : ByteArray = new ByteArray;
            var len : uint = hex.length;
            if ((len & 1) == 1) hex = "0" + hex;
            for (var i : uint = 0; i < len; i += 2) {
                a[i / 2] = parseInt(hex.substr(i, 2), 16);
            }
            return a;
        }

        /**
         * Generates lowercase hexadecimal string from given byte-array
         */
        public static function fromArray(array : ByteArray, colons : Boolean = false) : String {
            var s : String = "";
            var len : uint = array.length;
            for (var i : uint = 0; i < len; i++) {
                s += ("0" + array[i].toString(16)).substr(-2, 2);
                if (colons) {
                    if (i < len - 1) s += ":";
                }
            }
            return s;
        }
    }
}
{'fraction_non_alphanumeric': 0.12566489361702127, 'fraction_numerical': 0.020611702127659573, 'mean_word_length': 1.5328282828282829, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 5, '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': '904756', 'n_tokens_mistral': 951, 'n_tokens_neox': 879, 'n_words': 281}