diff --git a/changecase.py b/changecase.py index 8393e92..ecc9e27 100644 --- a/changecase.py +++ b/changecase.py @@ -4,6 +4,7 @@ import re, sys from xml.sax.saxutils import escape from titlecase import titlecase +from itertools import cycle if len(sys.argv) > 1 and len(sys.argv[1].strip()): text = sys.argv[1] @@ -26,14 +27,18 @@ def upcase(m): return m.group().upper() return always_uppercase_re.sub(upcase, text) +def alternate_case(text): + funcs = cycle([str.upper, str.lower]) + return ''.join(next(funcs)(c) for c in text) + variations = { 'lower': escape(text.lower(), {'"': '"', '\n': ' '} ), 'upper': escape(text.upper(), {'"': '"', '\n': ' '} ), 'title': escape(titlecase_plus(text), {'"': '"', '\n': ' '} ), 'camel': escape(titlecase_plus(text), {'"': '"', '\n': ' '} ).replace(' ', ''), 'kebab': escape(text.lower(), {'"': '"', '\n': ' '} ).replace(' ', '-').replace('_', '-'), - 'snake': escape(text.lower(), {'"': '"', '\n': ' '} ).replace(' ', '_').replace('-', '_') - + 'snake': escape(text.lower(), {'"': '"', '\n': ' '} ).replace(' ', '_').replace('-', '_'), + 'trout': escape(alternate_case(text), {'"': '"', '\n': ' '} ), } print """ @@ -68,5 +73,10 @@ def upcase(m): snake_case snakecase.png + + "%(trout)s" + tRoUtCaSe + troutcase.png + """ % variations