File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5151# Maps a string such as 'The Beatles' to 'the-beatles'.
5252def toNeat (s ):
5353 s = s .lower ().replace ("&" ,"and" )
54- s = re .sub (r"[()\[\],.'\"\\\?\#/\!\$\:]" , "" , s )
55- s = re .sub (r"[ \*\_]" , "-" , s )
54+
55+ # Put spaces between and remove blank characters.
56+ blankCharsPad = r"()\[\],.\\\?\#/\!\$\:"
57+ blankCharsNoPad = r"'\""
58+ s = re .sub (r"([" + blankCharsPad + r"])([^ ])" , "\\ 1 \\ 2" , s )
59+ s = re .sub ("[" + blankCharsPad + blankCharsNoPad + "]" , "" , s )
60+
61+ # Replace spaces with a single dash.
62+ s = re .sub (r"[ \*\_]+" , "-" , s )
5663 s = re .sub ("-+" , "-" , s )
57- search = re .search ("[^0-9a-z\-\=]" , s )
64+ s = re .sub ("^-*" , "" , s )
65+ s = re .sub ("-*$" , "" , s )
66+
67+ # Ensure the string is only alphanumeric with dashes.
68+ search = re .search ("[^0-9a-z\-]" , s )
5869 if search :
5970 print ("Error: Unrecognized character in '" + s + "'" )
6071 sys .exit (- 42 )
You can’t perform that action at this time.
0 commit comments