Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement troutcase/spongecase/alternating case #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 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
import random

if len(sys.argv) > 1 and len(sys.argv[1].strip()):
text = sys.argv[1]
Expand All @@ -26,14 +27,36 @@ def upcase(m):
return m.group().upper()
return always_uppercase_re.sub(upcase, text)

# Props to Noah Krim <[email protected]> for this
# This is copied from https://github.com/nkrim/spongemock/blob/master/src/spongemock.py
def spongemock(text, diversity_bias=0.5, random_seed=None):
# Error handling
if diversity_bias < 0 or diversity_bias > 1:
raise ValueError('diversity_bias must be between the inclusive range [0,1]')
# Seed the random number generator
random.seed(random_seed)
# Mock the text
out = ''
last_was_upper = True
swap_chance = 0.5
for c in text:
if c.isalpha():
if random.random() < swap_chance:
last_was_upper = not last_was_upper
swap_chance = 0.5
c = c.upper() if last_was_upper else c.lower()
swap_chance += (1-swap_chance)*diversity_bias
out += c
return out

variations = {
'lower': escape(text.lower(), {'"': '&quot;', '\n': '&#10;'} ),
'upper': escape(text.upper(), {'"': '&quot;', '\n': '&#10;'} ),
'title': escape(titlecase_plus(text), {'"': '&quot;', '\n': '&#10;'} ),
'camel': escape(titlecase_plus(text), {'"': '&quot;', '\n': '&#10;'} ).replace(' ', ''),
'kebab': escape(text.lower(), {'"': '&quot;', '\n': '&#10;'} ).replace(' ', '-').replace('_', '-'),
'snake': escape(text.lower(), {'"': '&quot;', '\n': '&#10;'} ).replace(' ', '_').replace('-', '_')

'snake': escape(text.lower(), {'"': '&quot;', '\n': '&#10;'} ).replace(' ', '_').replace('-', '_'),
'trout': escape(spongemock(text), {'"': '&quot;', '\n': '&#10;'} ),
}

print """<?xml version="1.0"?>
Expand Down Expand Up @@ -68,5 +91,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
Binary file modified icons.acorn
Binary file not shown.
Binary file added troutcase.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.