Skip to content

Commit

Permalink
Optimise valid array by lowering str first
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Vincent committed Apr 27, 2011
1 parent c2a6d67 commit eba330f
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions sanitise.py
Expand Up @@ -16,7 +16,7 @@ def removeAccents(str):
nkfd_form = unicodedata.normalize('NFKD', str)
return "".join([c for c in nkfd_form if not unicodedata.combining(c)])

def regex(str):
def regexSanitise(str):
"""Perform detailed substitutions using regex."""

# List of (pattern, replacement) tuples
Expand All @@ -36,15 +36,13 @@ def regex(str):

def sanitise(str):
"""Perform substitutions and return the string."""

str = str.lower()
str = removeAccents(str)
str = regex(str)
str = regexSanitise(str)

# Permit only letters, digits, dash (seperator) and dot (file extension)
valid = string.ascii_letters + string.digits + "-."
str = "".join([chr for chr in str if chr in valid])

return str.lower()
valid = string.ascii_lowercase + string.digits + "-."
return "".join([chr for chr in str if chr in valid])

def parseArguments():
"""Parse the command-line arguments."""
Expand Down

0 comments on commit eba330f

Please sign in to comment.