Created
November 12, 2015 12:25
-
-
Save ptman/07026d2b10937b297d9c to your computer and use it in GitHub Desktop.
Complement for go stringer
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 "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