Skip to content

Commit d34ce02

Browse files
committed
Safety for numeric identifiers and identifiers starting with numbers
1 parent e552134 commit d34ce02

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

json-to-go.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ function jsonToGo(json, typename)
9999

100100
function format(str)
101101
{
102+
if (str.match(/^\d+$/))
103+
str = "Number" + str;
104+
else if (str.charAt(0).match(/\d/))
105+
{
106+
var numbers = {'0': "Zero_", '1': "One_", '2': "Two_", '3': "Three_",
107+
'4': "Four_", '5': "Five_", '6': "Six_", '7': "Seven_",
108+
'8': "Eight_", '9': "Nine_"};
109+
str = numbers[str.charAt(0)] + str.substr(1);
110+
}
102111
return toProperCase(str).replace(/\s|_/g, "");
103112
}
104113

0 commit comments

Comments
 (0)