summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/text.py10
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()