diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-12-26 13:46:15 +0100 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-12-26 14:03:50 +0100 |
| commit | 8f04f53dd847896f49a9bc367bb7269984ebdb6e (patch) | |
| tree | 9ff9f1ee72a51cf4796eab081b81c9db7194c661 /django/utils/text.py | |
| parent | 4e7aa573ec3b9c8e0784db9013dbc31b6c3eaac5 (diff) | |
Removed a few gratuitous lambdas.
Diffstat (limited to 'django/utils/text.py')
| -rw-r--r-- | django/utils/text.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/django/utils/text.py b/django/utils/text.py index f44a364f5f..f52050cccc 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -17,6 +17,7 @@ if six.PY2: # people rely on it being here. from django.utils.encoding import force_unicode # NOQA + # Capitalizes the first letter of a string. capfirst = lambda x: x and force_text(x)[0].upper() + force_text(x)[1:] capfirst = allow_lazy(capfirst, six.text_type) @@ -25,6 +26,7 @@ capfirst = allow_lazy(capfirst, six.text_type) re_words = re.compile(r'<.*?>|((?:\w[-\w]*|&.*?;)+)', re.U | re.S) re_tag = re.compile(r'<(/)?([^ ]+?)(?:(\s*/)| .*?)?>', re.S) re_newlines = re.compile(r'\r\n|\r') # Used in normalize_newlines +re_camel_case = re.compile(r'(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))') def wrap(text, width): @@ -420,3 +422,11 @@ def slugify(value): value = re.sub('[^\w\s-]', '', value).strip().lower() return mark_safe(re.sub('[-\s]+', '-', value)) slugify = allow_lazy(slugify, six.text_type) + + +def camel_case_to_spaces(value): + """ + Splits CamelCase and converts to lower case. Also strips leading and + trailing whitespace. + """ + return re_camel_case.sub(r' \1', value).strip().lower() |
