<commit_before>
Pattern = require './Pattern'

# A bunch of utility methods
#
class Utils

    @REGEX_LEFT_TRIM_BY_CHAR:   {}
    @REGEX_RIGHT_TRIM_BY_CHAR:  {}
    @REGEX_SPACES:              /\s+/g
    @REGEX_DIGITS:              /^\d+$/
    @REGEX_OCTAL:               /[^0-7]/gi
    @REGEX_HEXADECIMAL:         /[^a-f0-9]/gi

    # Precompiled date pattern
    @PATTERN_DATE:              new Pattern '^'+
            '(?<year>[0-9][0-9][0-9][0-9])'+
            '-(?<month>[0-9][0-9]?)'+
            '-(?<day>[0-9][0-9]?)'+
            '(?:(?:[Tt]|[ \t]+)'+
            '(?<hour>[0-9][0-9]?)'+
            ':(?<minute>[0-9][0-9])'+
            ':(?<second>[0-9][0-9])'+
            '(?:\.(?<fraction>[0-9]*))?'+
            '(?:[ \t]*(?<tz>Z|(?<tz_sign>[-+])(?<tz_hour>[0-9][0-9]?)'+
            '(?::(?<tz_minute>[0-9][0-9]))?))?)?'+
            '$', 'i'

    # Local timezone offset in ms
    @LOCAL_TIMEZONE_OFFSET:     new Date().getTimezoneOffset() * 60 * 1000

    # Trims the given string on both sides
    #
    # @param [String] str The string to trim
    # @param [String] _char The character to use for trimming (default: '\\s')
    #
    # @return [String] A trimmed string
    #
    @trim: (str, _char = '\\s') ->
        return str.trim()
        regexLeft = @REGEX_LEFT_TRIM_BY_CHAR[_char]
        unless regexLeft?
            @REGEX_LEFT_TRIM_BY_CHAR[_char] = regexLeft = new RegExp '^'+_char+''+_char+'*'
        regexLeft.lastIndex = 0
        regexRight = @REGEX_RIGHT_TRIM_BY_CHAR[_char]
        unless regexRight?
            @REGEX_RIGHT_TRIM_BY_CHAR[_char] = regexRight = new RegExp _char+''+_char+'*$'
        regexRight.lastIndex = 0
        return str.replace(regexLeft, '').replace(regexRight, '')


    # Trims the given string on the left side
    #
    # @param [String] str The string to trim
    # @param [String] _char The character to use for trimming (default: '\\s')
    #
    # @return [String] A trimmed string
    #
    @ltrim: (str, _char = '\\s') ->
        regexLeft = @REGEX_LEFT_TRIM_BY_CHAR[_char]
        unless regexLeft?
            @REGEX_LEFT_TRIM_BY_CHAR[_char] = regexLeft = new RegExp '^'+_char+''+_char+'*'
        regexLeft.lastIndex = 0
        return str.replace(regexLeft, '')


    # Trims the given string on the right side
    #
    # @param [String] str The string to trim
    # @param [String] _char The character to use for trimming (default: '\\s')
    #
    # @return [String] A trimmed string
    #
    @rtrim: (str, _char = '\\s') ->
        regexRight = @REGEX_RIGHT_TRIM_BY_CHAR[_char]
        unless regexRight?
            @REGEX_RIGHT_TRIM_BY_CHAR[_char] = regexRight = new RegExp _char+''+_char+'*$'
        regexRight.lastIndex = 0
        return str.replace(regexRight, '')


    # Checks if the given value is empty (null, undefined, empty string, string '0')
    #
    # @param [Object] value The value to check
    #
    # @return [Boolean] true if the value is empty
    #
    @isEmpty: (value) ->
        return not(value) or value is '' or value is '0' or (value instanceof Array and value.length is 0) or (value instanceof Object and (k for own k of value).length is 0)


    # Counts the number of occurences of subString inside string<commit_msg>Simplify source by adding Utils.isEmptyObject method<commit_after>
Pattern = require './Pattern'

# A bunch of utility methods
#
class Utils

    @REGEX_LEFT_TRIM_BY_CHAR:   {}
    @REGEX_RIGHT_TRIM_BY_CHAR:  {}
    @REGEX_SPACES:              /\s+/g
    @REGEX_DIGITS:              /^\d+$/
    @REGEX_OCTAL:               /[^0-7]/gi
    @REGEX_HEXADECIMAL:         /[^a-f0-9]/gi

    # Precompiled date pattern
    @PATTERN_DATE:              new Pattern '^'+
            '(?<year>[0-9][0-9][0-9][0-9])'+
            '-(?<month>[0-9][0-9]?)'+
            '-(?<day>[0-9][0-9]?)'+
            '(?:(?:[Tt]|[ \t]+)'+
            '(?<hour>[0-9][0-9]?)'+
            ':(?<minute>[0-9][0-9])'+
            ':(?<second>[0-9][0-9])'+
            '(?:\.(?<fraction>[0-9]*))?'+
            '(?:[ \t]*(?<tz>Z|(?<tz_sign>[-+])(?<tz_hour>[0-9][0-9]?)'+
            '(?::(?<tz_minute>[0-9][0-9]))?))?)?'+
            '$', 'i'

    # Local timezone offset in ms
    @LOCAL_TIMEZONE_OFFSET:     new Date().getTimezoneOffset() * 60 * 1000

    # Trims the given string on both sides
    #
    # @param [String] str The string to trim
    # @param [String] _char The character to use for trimming (default: '\\s')
    #
    # @return [String] A trimmed string
    #
    @trim: (str, _char = '\\s') ->
        return str.trim()
        regexLeft = @REGEX_LEFT_TRIM_BY_CHAR[_char]
        unless regexLeft?
            @REGEX_LEFT_TRIM_BY_CHAR[_char] = regexLeft = new RegExp '^'+_char+''+_char+'*'
        regexLeft.lastIndex = 0
        regexRight = @REGEX_RIGHT_TRIM_BY_CHAR[_char]
        unless regexRight?
            @REGEX_RIGHT_TRIM_BY_CHAR[_char] = regexRight = new RegExp _char+''+_char+'*$'
        regexRight.lastIndex = 0
        return str.replace(regexLeft, '').replace(regexRight, '')


    # Trims the given string on the left side
    #
    # @param [String] str The string to trim
    # @param [String] _char The character to use for trimming (default: '\\s')
    #
    # @return [String] A trimmed string
    #
    @ltrim: (str, _char = '\\s') ->
        regexLeft = @REGEX_LEFT_TRIM_BY_CHAR[_char]
        unless regexLeft?
            @REGEX_LEFT_TRIM_BY_CHAR[_char] = regexLeft = new RegExp '^'+_char+''+_char+'*'
        regexLeft.lastIndex = 0
        return str.replace(regexLeft, '')


    # Trims the given string on the right side
    #
    # @param [String] str The string to trim
    # @param [String] _char The character to use for trimming (default: '\\s')
    #
    # @return [String] A trimmed string
    #
    @rtrim: (str, _char = '\\s') ->
        regexRight = @REGEX_RIGHT_TRIM_BY_CHAR[_char]
        unless regexRight?
            @REGEX_RIGHT_TRIM_BY_CHAR[_char] = regexRight = new RegExp _char+''+_char+'*$'
        regexRight.lastIndex = 0
        return str.replace(regexRight, '')


    # Checks if the given value is empty (null, undefined, empty string, string '0', empty Array, empty Object)
    #
    # @param [Object] value The value to check
    #
    # @return [Boolean] true if the value is empty
    #
    @isEmpty: (value) ->
        return not(value) or value is '' or value is '0' or (value instanceof Array and value.length is 0) or @isEmptyObject(value)

    # Checks if the given value is an empty object
    #
    # @param [Object] value The value to check
    #
    # @return [Boolean] true if the value is empty and is an object
    #
    @isEmptyObject: (value) ->
        return value instanceof Object and (k for own k of value).length is 0

    # Counts the number of occurences of subString inside string
{'fraction_non_alphanumeric': 0.15876288659793814, 'fraction_numerical': 0.016494845360824743, 'mean_word_length': 2.3338242513500247, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 34, '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': '2435965', 'n_tokens_mistral': 2438, 'n_tokens_neox': 2333, 'n_words': 590}