Created
September 23, 2016 02:37
-
-
Save kaneshin/b26aa5055279829ef868c7c196214cfc 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
// goodName reports whether the function name is a valid identifier. | |
func goodName(name string) bool { | |
if name == "" { | |
return false | |
} | |
for i, r := range name { | |
switch { | |
case r == '_': | |
case i == 0 && !unicode.IsLetter(r): | |
return false | |
case !unicode.IsLetter(r) && !unicode.IsDigit(r): | |
return false | |
} | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment