From 29c33661361e38e021528799cd4315f00bb64410 Mon Sep 17 00:00:00 2001 From: Thomas Skaflem Date: Wed, 26 Feb 2014 11:30:20 +0100 Subject: [PATCH] Improves the upcase_first_letter() function --- CHANGES | 7 +++++++ stringhelpers/__init__.py | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 3ea3d52..9c98f19 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,13 @@ stringhelpers Changelog ======================= +Version 1.2 +----------- +Improves the `upcase_first_letter` function. +- Any non-alphanumeric chars and spaces will now not be treated as the first letter, + which stopped the search after the first letter that should be capitalized. + + Version 1.1 ----------- Fixes small typos. diff --git a/stringhelpers/__init__.py b/stringhelpers/__init__.py index 8e47eb3..bd21095 100644 --- a/stringhelpers/__init__.py +++ b/stringhelpers/__init__.py @@ -8,7 +8,7 @@ :license: MIT, see LICENSE for more details. """ -__version__ = '1.1' +__version__ = '1.2' import re import os @@ -39,7 +39,9 @@ def upcase_first_letter(string): :param :string: string to capitalize first letter of. """ - return string[0].upper() + string[1:] + alpha = re.compile(r"[^\W\s\d]", re.UNICODE) + letter = alpha.search(string).group() + return string.replace(letter, letter.upper(), 1) def reverse(string):