Skip to content

Commit

Permalink
implement troutcase/spongecase/alternating case
Browse files Browse the repository at this point in the history
  • Loading branch information
apoxa committed Nov 27, 2020
1 parent 64eb341 commit 4495451
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions changecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 """<?xml version="1.0"?>
Expand Down Expand Up @@ -68,5 +73,10 @@ def upcase(m):
<subtitle>snake_case</subtitle>
<icon>snakecase.png</icon>
</item>
<item arg="%(trout)s">
<title>"%(trout)s"</title>
<subtitle>tRoUtCaSe</subtitle>
<icon>troutcase.png</icon>
</item>
</items>""" % variations

0 comments on commit 4495451

Please sign in to comment.