Skip to content

Instantly share code, notes, and snippets.

@kaneshin
Created September 23, 2016 02:37
Show Gist options
  • Save kaneshin/b26aa5055279829ef868c7c196214cfc to your computer and use it in GitHub Desktop.
Save kaneshin/b26aa5055279829ef868c7c196214cfc to your computer and use it in GitHub Desktop.
// 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