Skip to content

Instantly share code, notes, and snippets.

@ptman
Created November 12, 2015 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptman/07026d2b10937b297d9c to your computer and use it in GitHub Desktop.
Save ptman/07026d2b10937b297d9c to your computer and use it in GitHub Desktop.
Complement for go stringer
import "strings"
func ParseType(s string) Type {
return parseType(0, s)
}
func parseType(i int, s string) Type {
j := strings.Index(_Type_name[i:], s)
if j == -1 {
return -1
}
k := 0
for k = range _Type_index {
if int(_Type_index[k]) == j+1 {
break
}
}
if k >= len(_Type_index)-1 {
return -1
}
if int(_Type_index[k+1]) != j+i+len(s) {
return parseType(i+1, s)
}
return Type(k)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment