<commit_before>import re
from pprint import pprint

from django.template.defaulttags import register

from utils.classes import GitVersion


@register.simple_tag
def git_ver():
    '''
    Retrieve and return the latest git commit hash ID and date
    Use in template:  {% git_ver %}
    '''
    git_version = GitVersion()
    return git_version.version


@register.filter
def get_type(value):
    return type(value).__name__


@register.filter
def get_item(dictionary, key):
    return dictionary.get(key)


@register.filter
def get_obj_attr(obj, attr):
    return getattr(obj, attr)


@register.filter
def zfill(s, len):
    s = str(s)
    return s.zfill(len)


@register.filter
def num_zfill(s, len):
    s = str(s)
    if s.isdigit():
        return s.zfill(len)
    else:
        return s


@register.filter
def transp_decimals(text):
    separa_zeros = re.compile("^(.*\,[^0]*)(0*)$")
    reg = separa_zeros.search(text)
    if reg:
        zeros = reg.group(2)
        if zeros:
            inicio = reg.group(1)
            if inicio[-1] == ',':
                inicio = inicio[:-1]
                zeros = ','+zeros
            return ''.join([
                inicio,
                '<span style="opacity: 0.7; position: static; z-index: -1;">',
                zeros,
                '</span>'])
    return text


@register.filter
def word_slice(text, slice):

    def adjust_cut(text, valor, limit=1):
        val = valor
        while text[val-1] != ' ' and val > 1:
            val -= 1
        if val <= limit:
            val = valor
        while text[val] == ' ' and val < len(text):
            val += 1
        return val

    if text == '':<commit_msg>tentando resolver bug de string index<commit_after>import re
from pprint import pprint

from django.template.defaulttags import register

from utils.classes import GitVersion


@register.simple_tag
def git_ver():
    '''
    Retrieve and return the latest git commit hash ID and date
    Use in template:  {% git_ver %}
    '''
    git_version = GitVersion()
    return git_version.version


@register.filter
def get_type(value):
    return type(value).__name__


@register.filter
def get_item(dictionary, key):
    return dictionary.get(key)


@register.filter
def get_obj_attr(obj, attr):
    return getattr(obj, attr)


@register.filter
def zfill(s, len):
    s = str(s)
    return s.zfill(len)


@register.filter
def num_zfill(s, len):
    s = str(s)
    if s.isdigit():
        return s.zfill(len)
    else:
        return s


@register.filter
def transp_decimals(text):
    separa_zeros = re.compile("^(.*\,[^0]*)(0*)$")
    reg = separa_zeros.search(text)
    if reg:
        zeros = reg.group(2)
        if zeros:
            inicio = reg.group(1)
            if inicio[-1] == ',':
                inicio = inicio[:-1]
                zeros = ','+zeros
            return ''.join([
                inicio,
                '<span style="opacity: 0.7; position: static; z-index: -1;">',
                zeros,
                '</span>'])
    return text


@register.filter
def word_slice(text, slice):

    def adjust_cut(text, valor, limit=1):
        val = valor
        while val > 1 and text[val-1] != ' ':
            val -= 1
        if val <= limit:
            val = valor
        while val < len(text) and text[val] == ' ':
            val += 1
        return val

    if text == '':
{'fraction_non_alphanumeric': 0.12811387900355872, 'fraction_numerical': 0.00830367734282325, 'mean_word_length': 2.0775547445255476, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '4396353', 'n_tokens_mistral': 1134, 'n_tokens_neox': 1081, 'n_words': 291}