Ticket #5426: uncapfirst.diff

File uncapfirst.diff, 1.6 KB (added by Petr Marhoun <petr.marhoun@…>, 17 years ago)
  • django/template/defaultfilters.py

    === modified file 'django/template/defaultfilters.py'
     
    172172    return truncate_html_words(value, length)
    173173truncatewords_html = stringfilter(truncatewords_html)
    174174
     175def uncapfirst(value):
     176    "Uncapitalizes the first character of the value"
     177    if len(value) > 1:
     178        if value[1].islower():
     179            return value[0].lower() + value[1:]
     180        else:
     181            return value
     182    else:
     183        return value.lower()
     184uncapfirst = stringfilter(uncapfirst)
     185
    175186def upper(value):
    176187    "Converts a string into all uppercase"
    177188    return value.upper()
     
    649660register.filter(title)
    650661register.filter(truncatewords)
    651662register.filter(truncatewords_html)
     663register.filter(uncapfirst)
    652664register.filter(unordered_list)
    653665register.filter(upper)
    654666register.filter(urlencode)
  • django/utils/text.py

    === modified file 'django/utils/text.py'
     
    88capfirst = lambda x: x and force_unicode(x)[0].upper() + force_unicode(x)[1:]
    99capfirst = allow_lazy(capfirst, unicode)
    1010
     11# Uncapitalizes the first letter of a string.
     12def uncapfirst(x):
     13    x = force_unicode(x)
     14    if len(x) > 1:
     15        if x[1].islower():
     16            return x[0].lower() + x[1:]
     17        else:
     18            return x
     19    else:
     20        return x.lower()
     21uncapfirst = allow_lazy(uncapfirst, unicode)
     22
    1123def wrap(text, width):
    1224    """
    1325    A word-wrap function that preserves existing line breaks and most spaces in
Back to Top