diff --git a/types/resolve.go b/types/resolve.go index 7ec14e065..cf4025c85 100644 --- a/types/resolve.go +++ b/types/resolve.go @@ -3,6 +3,7 @@ package types import ( "errors" "fmt" + "regexp" "strconv" "strings" @@ -570,6 +571,13 @@ func ParseFunction(s string) (f []string, r []string, err error) { return } +var ( + rxconst = regexp.MustCompile(`\bconst\b`) + rxvolatile = regexp.MustCompile(`\bvolatile\b`) + rxUUrestrict = regexp.MustCompile(`\b__restrict\b`) + rxrestrict = regexp.MustCompile(`\brestrict\b`) +) + // CleanCType - remove from C type not Go type func CleanCType(s string) (out string) { out = s @@ -583,10 +591,10 @@ func CleanCType(s string) (out string) { out = strings.Replace(out, "( *)", "(*)", -1) // Remove any whitespace or attributes that are not relevant to Go. - out = strings.Replace(out, "const", "", -1) - out = strings.Replace(out, "volatile", "", -1) - out = strings.Replace(out, "__restrict", "", -1) - out = strings.Replace(out, "restrict", "", -1) + out = rxconst.ReplaceAllLiteralString(out, "") + out = rxvolatile.ReplaceAllLiteralString(out, "") + out = rxUUrestrict.ReplaceAllLiteralString(out, "") + out = rxrestrict.ReplaceAllLiteralString(out, "") out = strings.Replace(out, "\t", "", -1) out = strings.Replace(out, "\n", "", -1) out = strings.Replace(out, "\r", "", -1)