diff --git a/changecase.py b/changecase.py index 8393e92..ef1c416 100644 --- a/changecase.py +++ b/changecase.py @@ -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] @@ -26,14 +27,36 @@ def upcase(m): return m.group().upper() return always_uppercase_re.sub(upcase, text) +# Props to Noah Krim 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(), {'"': '"', '\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(spongemock(text), {'"': '"', '\n': ' '} ), } print """ @@ -68,5 +91,10 @@ def upcase(m): snake_case snakecase.png + + %(trout)s + TroUTcAsE + troutcase.png + """ % variations diff --git a/icons.acorn b/icons.acorn index 26e92f8..27e4b0c 100644 Binary files a/icons.acorn and b/icons.acorn differ diff --git a/troutcase.png b/troutcase.png new file mode 100644 index 0000000..038ca06 Binary files /dev/null and b/troutcase.png differ