Created
May 25, 2014 20:44
-
-
Save flaviut/3aec4e853582c69499c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import strutils | |
proc mangle*(name: string): string = | |
result = "" | |
case name[0] | |
of Letters: | |
result.add(name[0].toLower) | |
of Digits: | |
result.add("N" & name[0]) | |
else: | |
result = "HEX" & toHex(ord(name[0]), 2) | |
for i in 1..(name.len-1): | |
let c = name[i] | |
case c | |
of 'A'..'Z': | |
add(result, c.toLower) | |
of '_': | |
discard | |
of 'a'..'z', '0'..'9': | |
add(result, c) | |
else: | |
add(result, "HEX" & toHex(ord(c), 2)) | |
proc mangleField(name: string): string = | |
result = mangle(name) | |
if name[0] in 'a'..'z': | |
result[0] = name[0].toUpper | |
echo mangleField("A") | |
echo mangleField("a") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment