Beispiel #1
0
def m_len(target):
    """
    Provides length checking for strings with MXP patterns, and falls
    back to normal len for other objects.
    """
    # Would create circular import if in module root.
    from evennia.utils.ansi import ANSI_PARSER
    if inherits_from(target, basestring):
        return len(ANSI_PARSER.strip_mxp(target))
    return len(target)
Beispiel #2
0
def m_len(target):
    """
    Provides length checking for strings with MXP patterns, and falls
    back to normal len for other objects.
    """
    # Would create circular import if in module root.
    from evennia.utils.ansi import ANSI_PARSER
    if inherits_from(target, basestring):
        return len(ANSI_PARSER.strip_mxp(target))
    return len(target)
Beispiel #3
0
def sanitize_string(text=None, length=None, strip_ansi=False, strip_mxp=True, strip_newlines=True, strip_indents=True):
    if not text:
        return ''
    text = text.strip()
    if strip_mxp:
        text = ANSI_PARSER.strip_mxp(text)
    if strip_ansi:
        text = ANSIString(text).clean()
    if strip_newlines:
        for bad_char in ['\n', '%r', '%R', '|/']:
            text = text.replace(bad_char, '')
    if strip_indents:
        for bad_char in ['\t', '%t', '%T', '|-']:
            text = text.replace(bad_char, '')
    if length:
        text = text[:length]
    return text
Beispiel #4
0
def m_len(target):
    """
    Provides length checking for strings with MXP patterns, and falls
    back to normal len for other objects.

    Args:
        target (string): A string with potential MXP components
            to search.

    Returns:
        length (int): The length of `target`, ignoring MXP components.

    """
    # Would create circular import if in module root.
    from evennia.utils.ansi import ANSI_PARSER
    if inherits_from(target, basestring):
        return len(ANSI_PARSER.strip_mxp(target))
    return len(target)
Beispiel #5
0
def sanitize_string(input=None, length=None, strip_ansi=False, strip_mxp=True, strip_newlines=True, strip_indents=True):
    if not input:
        return ''
    input = input.strip()
    if strip_mxp:
        input = ANSI_PARSER.strip_mxp(input)
    if strip_ansi:
        input = ANSIString(input).clean()
        input = unicode(input)
    if strip_newlines:
        for bad_char in ['\n', '%r', '%R', '{/']:
            input = input.replace(bad_char, '')
    if strip_indents:
        for bad_char in ['\t', '%t', '%T', '{-']:
            input = input.replace(bad_char, '')
    if length:
        input = input[:length]
    return unicode(input)