'Truncate a string after a certain number of chars.'

def _text_chars(self, length, truncate, text, truncate_len):

    s_len = 0
    end_index = None
    for (i, char) in enumerate(text):
        if unicodedata.combining(char):
            continue
        s_len += 1
        if ((end_index is None) and (s_len > truncate_len)):
            end_index = i
        if (s_len > length):
            return self.add_truncation_text(text[:(end_index or 0)], truncate)
    return text
