1
# Copyright 2007 Javier Kohen
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License version 2 as
5
# published by the Free Software Foundation
7
# $Id: titlecase.py 4330 2008-09-14 03:19:26Z piman $
12
"""Returns whether the given character is a word boundary."""
13
category = unicodedata.category(char)
14
# If it's a space separator or punctuation
15
return 'Zs' == category or 'Sk' == category or 'P' == category[0]
18
"""Title-case a string using a less destructive method than str.title."""
19
new_string = string[0].capitalize()
21
for i in xrange(1, len(string)):
23
# Special case apostrophe in the middle of a word.
24
if u"'" == s and string[i-1].isalpha(): cap = False
25
elif iswbound(s): cap = True
26
elif cap and s.isalpha():
33
def title(string, locale="utf-8"):
34
"""Title-case a string using a less destructive method than str.title."""
35
if not string: return u""
36
# if the string is all uppercase, lowercase it - Erich/Javier
37
# Lots of Japanese songs use entirely upper-case English titles,
38
# so I don't like this change... - JoeW
39
#if string == string.upper(): string = string.lower()
40
if not isinstance(string, unicode):
41
string = string.decode(locale)