Skip to content

Support PHP variable prefixes #29

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

Open
wants to merge 1 commit 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
24 changes: 12 additions & 12 deletions case_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,47 @@


def to_snake_case(text, detectAcronyms, acronyms):
words, case, sep = case_parse.parseVariable(text, detectAcronyms, acronyms)
return '_'.join([w.lower() for w in words])
words, case, sep, prefix = case_parse.parseVariable(text, detectAcronyms, acronyms)
return prefix+'_'.join([w.lower() for w in words])


def to_pascal_case(text, detectAcronyms, acronyms):
words, case, sep = case_parse.parseVariable(text, detectAcronyms, acronyms)
return ''.join(words)
words, case, sep, prefix = case_parse.parseVariable(text, detectAcronyms, acronyms)
return prefix+''.join(words)


def to_camel_case(text, detectAcronyms, acronyms):
words, case, sep = case_parse.parseVariable(text, detectAcronyms, acronyms)
words, case, sep, prefix = case_parse.parseVariable(text, detectAcronyms, acronyms)
words[0] = words[0].lower()
return ''.join(words)
return prefix+''.join(words)


def to_dot_case(text, detectAcronyms, acronyms):
words, case, sep = case_parse.parseVariable(text, detectAcronyms, acronyms)
words, case, sep, prefix = case_parse.parseVariable(text, detectAcronyms, acronyms)
return '.'.join([w.lower() for w in words])


def to_dash_case(text, detectAcronyms, acronyms):
words, case, sep = case_parse.parseVariable(text, detectAcronyms, acronyms)
words, case, sep, prefix = case_parse.parseVariable(text, detectAcronyms, acronyms)
return '-'.join([w.lower() for w in words])


def to_slash(text, detectAcronyms, acronyms):
words, case, sep = case_parse.parseVariable(text, detectAcronyms, acronyms, True)
words, case, sep, prefix = case_parse.parseVariable(text, detectAcronyms, acronyms, True)
return '/'.join(words)

def to_backslash(text, detectAcronyms, acronyms):
words, case, sep = case_parse.parseVariable(text, detectAcronyms, acronyms, True)
words, case, sep, prefix = case_parse.parseVariable(text, detectAcronyms, acronyms, True)
return '\\'.join(words)


def to_separate_words(text, detectAcronyms, acronyms):
words, case, sep = case_parse.parseVariable(text, detectAcronyms, acronyms, True)
words, case, sep, prefix = case_parse.parseVariable(text, detectAcronyms, acronyms, True)
return ' '.join(words)


def toggle_case(text, detectAcronyms, acronyms):
words, case, sep = case_parse.parseVariable(text, detectAcronyms, acronyms)
words, case, sep, prefix = case_parse.parseVariable(text, detectAcronyms, acronyms)
if case == 'pascal' and not sep:
return to_snake_case(text, detectAcronyms, acronyms)
elif case == 'lower' and sep == '_':
Expand Down
8 changes: 7 additions & 1 deletion case_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ def parseVariable(var, detectAcronyms=True, acronyms=[], preserveCase=False):
words = []
hasSep = False

# check for starting variable identifier of $
variablePrefix = ''
if var[0:1] == "$":
variablePrefix = "$"
var = var[1:]

# Index of current character. Initially 1 because we don't want to check
# if the 0th character is a boundary.
i = 1
Expand Down Expand Up @@ -239,4 +245,4 @@ def checkAcronym(s, i):
else:
words[i] = words[i].capitalize()

return words, caseType, hasSep
return words, caseType, hasSep, variablePrefix