id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
3,900
go-openapi/swag
util.go
ToGoName
func ToGoName(name string) string { in := split(name) out := make([]string, 0, len(in)) for _, w := range in { uw := upper(w) mod := int(math.Min(float64(len(uw)), 2)) if !isInitialism(uw) && !isInitialism(uw[:len(uw)-mod]) { uw = Camelize(w) } out = append(out, uw) } result := strings.Join(out, "") if len(result) > 0 { if !unicode.IsUpper([]rune(result)[0]) { result = "X" + result } } return result }
go
func ToGoName(name string) string { in := split(name) out := make([]string, 0, len(in)) for _, w := range in { uw := upper(w) mod := int(math.Min(float64(len(uw)), 2)) if !isInitialism(uw) && !isInitialism(uw[:len(uw)-mod]) { uw = Camelize(w) } out = append(out, uw) } result := strings.Join(out, "") if len(result) > 0 { if !unicode.IsUpper([]rune(result)[0]) { result = "X" + result } } return result }
[ "func", "ToGoName", "(", "name", "string", ")", "string", "{", "in", ":=", "split", "(", "name", ")", "\n", "out", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "in", ")", ")", "\n\n", "for", "_", ",", "w", ":=", "range", "in", "{", "uw", ":=", "upper", "(", "w", ")", "\n", "mod", ":=", "int", "(", "math", ".", "Min", "(", "float64", "(", "len", "(", "uw", ")", ")", ",", "2", ")", ")", "\n", "if", "!", "isInitialism", "(", "uw", ")", "&&", "!", "isInitialism", "(", "uw", "[", ":", "len", "(", "uw", ")", "-", "mod", "]", ")", "{", "uw", "=", "Camelize", "(", "w", ")", "\n", "}", "\n", "out", "=", "append", "(", "out", ",", "uw", ")", "\n", "}", "\n\n", "result", ":=", "strings", ".", "Join", "(", "out", ",", "\"", "\"", ")", "\n", "if", "len", "(", "result", ")", ">", "0", "{", "if", "!", "unicode", ".", "IsUpper", "(", "[", "]", "rune", "(", "result", ")", "[", "0", "]", ")", "{", "result", "=", "\"", "\"", "+", "result", "\n", "}", "\n", "}", "\n", "return", "result", "\n", "}" ]
// ToGoName translates a swagger name which can be underscored or camel cased to a name that golint likes
[ "ToGoName", "translates", "a", "swagger", "name", "which", "can", "be", "underscored", "or", "camel", "cased", "to", "a", "name", "that", "golint", "likes" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/util.go#L321-L341
3,901
go-openapi/swag
util.go
ContainsStrings
func ContainsStrings(coll []string, item string) bool { for _, a := range coll { if a == item { return true } } return false }
go
func ContainsStrings(coll []string, item string) bool { for _, a := range coll { if a == item { return true } } return false }
[ "func", "ContainsStrings", "(", "coll", "[", "]", "string", ",", "item", "string", ")", "bool", "{", "for", "_", ",", "a", ":=", "range", "coll", "{", "if", "a", "==", "item", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// ContainsStrings searches a slice of strings for a case-sensitive match
[ "ContainsStrings", "searches", "a", "slice", "of", "strings", "for", "a", "case", "-", "sensitive", "match" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/util.go#L344-L351
3,902
go-openapi/swag
util.go
ContainsStringsCI
func ContainsStringsCI(coll []string, item string) bool { for _, a := range coll { if strings.EqualFold(a, item) { return true } } return false }
go
func ContainsStringsCI(coll []string, item string) bool { for _, a := range coll { if strings.EqualFold(a, item) { return true } } return false }
[ "func", "ContainsStringsCI", "(", "coll", "[", "]", "string", ",", "item", "string", ")", "bool", "{", "for", "_", ",", "a", ":=", "range", "coll", "{", "if", "strings", ".", "EqualFold", "(", "a", ",", "item", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// ContainsStringsCI searches a slice of strings for a case-insensitive match
[ "ContainsStringsCI", "searches", "a", "slice", "of", "strings", "for", "a", "case", "-", "insensitive", "match" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/util.go#L354-L361
3,903
go-openapi/swag
util.go
IsZero
func IsZero(data interface{}) bool { // check for things that have an IsZero method instead if vv, ok := data.(zeroable); ok { return vv.IsZero() } // continue with slightly more complex reflection v := reflect.ValueOf(data) switch v.Kind() { case reflect.String: return v.Len() == 0 case reflect.Bool: return !v.Bool() case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: return v.Int() == 0 case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: return v.Uint() == 0 case reflect.Float32, reflect.Float64: return v.Float() == 0 case reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice: return v.IsNil() case reflect.Struct, reflect.Array: return reflect.DeepEqual(data, reflect.Zero(v.Type()).Interface()) case reflect.Invalid: return true } return false }
go
func IsZero(data interface{}) bool { // check for things that have an IsZero method instead if vv, ok := data.(zeroable); ok { return vv.IsZero() } // continue with slightly more complex reflection v := reflect.ValueOf(data) switch v.Kind() { case reflect.String: return v.Len() == 0 case reflect.Bool: return !v.Bool() case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: return v.Int() == 0 case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: return v.Uint() == 0 case reflect.Float32, reflect.Float64: return v.Float() == 0 case reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice: return v.IsNil() case reflect.Struct, reflect.Array: return reflect.DeepEqual(data, reflect.Zero(v.Type()).Interface()) case reflect.Invalid: return true } return false }
[ "func", "IsZero", "(", "data", "interface", "{", "}", ")", "bool", "{", "// check for things that have an IsZero method instead", "if", "vv", ",", "ok", ":=", "data", ".", "(", "zeroable", ")", ";", "ok", "{", "return", "vv", ".", "IsZero", "(", ")", "\n", "}", "\n", "// continue with slightly more complex reflection", "v", ":=", "reflect", ".", "ValueOf", "(", "data", ")", "\n", "switch", "v", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "String", ":", "return", "v", ".", "Len", "(", ")", "==", "0", "\n", "case", "reflect", ".", "Bool", ":", "return", "!", "v", ".", "Bool", "(", ")", "\n", "case", "reflect", ".", "Int", ",", "reflect", ".", "Int8", ",", "reflect", ".", "Int16", ",", "reflect", ".", "Int32", ",", "reflect", ".", "Int64", ":", "return", "v", ".", "Int", "(", ")", "==", "0", "\n", "case", "reflect", ".", "Uint", ",", "reflect", ".", "Uint8", ",", "reflect", ".", "Uint16", ",", "reflect", ".", "Uint32", ",", "reflect", ".", "Uint64", ",", "reflect", ".", "Uintptr", ":", "return", "v", ".", "Uint", "(", ")", "==", "0", "\n", "case", "reflect", ".", "Float32", ",", "reflect", ".", "Float64", ":", "return", "v", ".", "Float", "(", ")", "==", "0", "\n", "case", "reflect", ".", "Interface", ",", "reflect", ".", "Map", ",", "reflect", ".", "Ptr", ",", "reflect", ".", "Slice", ":", "return", "v", ".", "IsNil", "(", ")", "\n", "case", "reflect", ".", "Struct", ",", "reflect", ".", "Array", ":", "return", "reflect", ".", "DeepEqual", "(", "data", ",", "reflect", ".", "Zero", "(", "v", ".", "Type", "(", ")", ")", ".", "Interface", "(", ")", ")", "\n", "case", "reflect", ".", "Invalid", ":", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// IsZero returns true when the value passed into the function is a zero value. // This allows for safer checking of interface values.
[ "IsZero", "returns", "true", "when", "the", "value", "passed", "into", "the", "function", "is", "a", "zero", "value", ".", "This", "allows", "for", "safer", "checking", "of", "interface", "values", "." ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/util.go#L369-L395
3,904
go-openapi/swag
util.go
AddInitialisms
func AddInitialisms(words ...string) { for _, word := range words { //commonInitialisms[upper(word)] = true commonInitialisms.add(upper(word)) } // sort again initialisms = commonInitialisms.sorted() }
go
func AddInitialisms(words ...string) { for _, word := range words { //commonInitialisms[upper(word)] = true commonInitialisms.add(upper(word)) } // sort again initialisms = commonInitialisms.sorted() }
[ "func", "AddInitialisms", "(", "words", "...", "string", ")", "{", "for", "_", ",", "word", ":=", "range", "words", "{", "//commonInitialisms[upper(word)] = true", "commonInitialisms", ".", "add", "(", "upper", "(", "word", ")", ")", "\n", "}", "\n", "// sort again", "initialisms", "=", "commonInitialisms", ".", "sorted", "(", ")", "\n", "}" ]
// AddInitialisms add additional initialisms
[ "AddInitialisms", "add", "additional", "initialisms" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/util.go#L398-L405
3,905
go-openapi/swag
net.go
SplitHostPort
func SplitHostPort(addr string) (host string, port int, err error) { h, p, err := net.SplitHostPort(addr) if err != nil { return "", -1, err } if p == "" { return "", -1, &net.AddrError{Err: "missing port in address", Addr: addr} } pi, err := strconv.Atoi(p) if err != nil { return "", -1, err } return h, pi, nil }
go
func SplitHostPort(addr string) (host string, port int, err error) { h, p, err := net.SplitHostPort(addr) if err != nil { return "", -1, err } if p == "" { return "", -1, &net.AddrError{Err: "missing port in address", Addr: addr} } pi, err := strconv.Atoi(p) if err != nil { return "", -1, err } return h, pi, nil }
[ "func", "SplitHostPort", "(", "addr", "string", ")", "(", "host", "string", ",", "port", "int", ",", "err", "error", ")", "{", "h", ",", "p", ",", "err", ":=", "net", ".", "SplitHostPort", "(", "addr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "-", "1", ",", "err", "\n", "}", "\n", "if", "p", "==", "\"", "\"", "{", "return", "\"", "\"", ",", "-", "1", ",", "&", "net", ".", "AddrError", "{", "Err", ":", "\"", "\"", ",", "Addr", ":", "addr", "}", "\n", "}", "\n\n", "pi", ",", "err", ":=", "strconv", ".", "Atoi", "(", "p", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "-", "1", ",", "err", "\n", "}", "\n", "return", "h", ",", "pi", ",", "nil", "\n", "}" ]
// SplitHostPort splits a network address into a host and a port. // The port is -1 when there is no port to be found
[ "SplitHostPort", "splits", "a", "network", "address", "into", "a", "host", "and", "a", "port", ".", "The", "port", "is", "-", "1", "when", "there", "is", "no", "port", "to", "be", "found" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/net.go#L24-L38
3,906
go-openapi/swag
path.go
FindInSearchPath
func FindInSearchPath(searchPath, pkg string) string { pathsList := filepath.SplitList(searchPath) for _, path := range pathsList { if evaluatedPath, err := filepath.EvalSymlinks(filepath.Join(path, "src", pkg)); err == nil { if _, err := os.Stat(evaluatedPath); err == nil { return evaluatedPath } } } return "" }
go
func FindInSearchPath(searchPath, pkg string) string { pathsList := filepath.SplitList(searchPath) for _, path := range pathsList { if evaluatedPath, err := filepath.EvalSymlinks(filepath.Join(path, "src", pkg)); err == nil { if _, err := os.Stat(evaluatedPath); err == nil { return evaluatedPath } } } return "" }
[ "func", "FindInSearchPath", "(", "searchPath", ",", "pkg", "string", ")", "string", "{", "pathsList", ":=", "filepath", ".", "SplitList", "(", "searchPath", ")", "\n", "for", "_", ",", "path", ":=", "range", "pathsList", "{", "if", "evaluatedPath", ",", "err", ":=", "filepath", ".", "EvalSymlinks", "(", "filepath", ".", "Join", "(", "path", ",", "\"", "\"", ",", "pkg", ")", ")", ";", "err", "==", "nil", "{", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "evaluatedPath", ")", ";", "err", "==", "nil", "{", "return", "evaluatedPath", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// FindInSearchPath finds a package in a provided lists of paths
[ "FindInSearchPath", "finds", "a", "package", "in", "a", "provided", "lists", "of", "paths" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/path.go#L30-L40
3,907
go-openapi/swag
path.go
FullGoSearchPath
func FullGoSearchPath() string { allPaths := os.Getenv(GOPATHKey) if allPaths == "" { allPaths = filepath.Join(os.Getenv("HOME"), "go") } if allPaths != "" { allPaths = strings.Join([]string{allPaths, runtime.GOROOT()}, ":") } else { allPaths = runtime.GOROOT() } return allPaths }
go
func FullGoSearchPath() string { allPaths := os.Getenv(GOPATHKey) if allPaths == "" { allPaths = filepath.Join(os.Getenv("HOME"), "go") } if allPaths != "" { allPaths = strings.Join([]string{allPaths, runtime.GOROOT()}, ":") } else { allPaths = runtime.GOROOT() } return allPaths }
[ "func", "FullGoSearchPath", "(", ")", "string", "{", "allPaths", ":=", "os", ".", "Getenv", "(", "GOPATHKey", ")", "\n", "if", "allPaths", "==", "\"", "\"", "{", "allPaths", "=", "filepath", ".", "Join", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "allPaths", "!=", "\"", "\"", "{", "allPaths", "=", "strings", ".", "Join", "(", "[", "]", "string", "{", "allPaths", ",", "runtime", ".", "GOROOT", "(", ")", "}", ",", "\"", "\"", ")", "\n", "}", "else", "{", "allPaths", "=", "runtime", ".", "GOROOT", "(", ")", "\n", "}", "\n", "return", "allPaths", "\n", "}" ]
// FullGoSearchPath gets the search paths for finding packages
[ "FullGoSearchPath", "gets", "the", "search", "paths", "for", "finding", "packages" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/path.go#L48-L59
3,908
go-openapi/swag
convert.go
ConvertBool
func ConvertBool(str string) (bool, error) { _, ok := evaluatesAsTrue[strings.ToLower(str)] return ok, nil }
go
func ConvertBool(str string) (bool, error) { _, ok := evaluatesAsTrue[strings.ToLower(str)] return ok, nil }
[ "func", "ConvertBool", "(", "str", "string", ")", "(", "bool", ",", "error", ")", "{", "_", ",", "ok", ":=", "evaluatesAsTrue", "[", "strings", ".", "ToLower", "(", "str", ")", "]", "\n", "return", "ok", ",", "nil", "\n", "}" ]
// ConvertBool turn a string into a boolean
[ "ConvertBool", "turn", "a", "string", "into", "a", "boolean" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert.go#L71-L74
3,909
go-openapi/swag
convert.go
ConvertFloat32
func ConvertFloat32(str string) (float32, error) { f, err := strconv.ParseFloat(str, 32) if err != nil { return 0, err } return float32(f), nil }
go
func ConvertFloat32(str string) (float32, error) { f, err := strconv.ParseFloat(str, 32) if err != nil { return 0, err } return float32(f), nil }
[ "func", "ConvertFloat32", "(", "str", "string", ")", "(", "float32", ",", "error", ")", "{", "f", ",", "err", ":=", "strconv", ".", "ParseFloat", "(", "str", ",", "32", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "float32", "(", "f", ")", ",", "nil", "\n", "}" ]
// ConvertFloat32 turn a string into a float32
[ "ConvertFloat32", "turn", "a", "string", "into", "a", "float32" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert.go#L77-L83
3,910
go-openapi/swag
convert.go
ConvertInt8
func ConvertInt8(str string) (int8, error) { i, err := strconv.ParseInt(str, 10, 8) if err != nil { return 0, err } return int8(i), nil }
go
func ConvertInt8(str string) (int8, error) { i, err := strconv.ParseInt(str, 10, 8) if err != nil { return 0, err } return int8(i), nil }
[ "func", "ConvertInt8", "(", "str", "string", ")", "(", "int8", ",", "error", ")", "{", "i", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "str", ",", "10", ",", "8", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "int8", "(", "i", ")", ",", "nil", "\n", "}" ]
// ConvertInt8 turn a string into int8 boolean
[ "ConvertInt8", "turn", "a", "string", "into", "int8", "boolean" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert.go#L91-L97
3,911
go-openapi/swag
convert.go
ConvertInt16
func ConvertInt16(str string) (int16, error) { i, err := strconv.ParseInt(str, 10, 16) if err != nil { return 0, err } return int16(i), nil }
go
func ConvertInt16(str string) (int16, error) { i, err := strconv.ParseInt(str, 10, 16) if err != nil { return 0, err } return int16(i), nil }
[ "func", "ConvertInt16", "(", "str", "string", ")", "(", "int16", ",", "error", ")", "{", "i", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "str", ",", "10", ",", "16", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "int16", "(", "i", ")", ",", "nil", "\n", "}" ]
// ConvertInt16 turn a string into a int16
[ "ConvertInt16", "turn", "a", "string", "into", "a", "int16" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert.go#L100-L106
3,912
go-openapi/swag
convert.go
ConvertInt32
func ConvertInt32(str string) (int32, error) { i, err := strconv.ParseInt(str, 10, 32) if err != nil { return 0, err } return int32(i), nil }
go
func ConvertInt32(str string) (int32, error) { i, err := strconv.ParseInt(str, 10, 32) if err != nil { return 0, err } return int32(i), nil }
[ "func", "ConvertInt32", "(", "str", "string", ")", "(", "int32", ",", "error", ")", "{", "i", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "str", ",", "10", ",", "32", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "int32", "(", "i", ")", ",", "nil", "\n", "}" ]
// ConvertInt32 turn a string into a int32
[ "ConvertInt32", "turn", "a", "string", "into", "a", "int32" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert.go#L109-L115
3,913
go-openapi/swag
convert.go
ConvertUint8
func ConvertUint8(str string) (uint8, error) { i, err := strconv.ParseUint(str, 10, 8) if err != nil { return 0, err } return uint8(i), nil }
go
func ConvertUint8(str string) (uint8, error) { i, err := strconv.ParseUint(str, 10, 8) if err != nil { return 0, err } return uint8(i), nil }
[ "func", "ConvertUint8", "(", "str", "string", ")", "(", "uint8", ",", "error", ")", "{", "i", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "str", ",", "10", ",", "8", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "uint8", "(", "i", ")", ",", "nil", "\n", "}" ]
// ConvertUint8 turn a string into a uint8
[ "ConvertUint8", "turn", "a", "string", "into", "a", "uint8" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert.go#L123-L129
3,914
go-openapi/swag
convert.go
ConvertUint16
func ConvertUint16(str string) (uint16, error) { i, err := strconv.ParseUint(str, 10, 16) if err != nil { return 0, err } return uint16(i), nil }
go
func ConvertUint16(str string) (uint16, error) { i, err := strconv.ParseUint(str, 10, 16) if err != nil { return 0, err } return uint16(i), nil }
[ "func", "ConvertUint16", "(", "str", "string", ")", "(", "uint16", ",", "error", ")", "{", "i", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "str", ",", "10", ",", "16", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "uint16", "(", "i", ")", ",", "nil", "\n", "}" ]
// ConvertUint16 turn a string into a uint16
[ "ConvertUint16", "turn", "a", "string", "into", "a", "uint16" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert.go#L132-L138
3,915
go-openapi/swag
convert.go
ConvertUint32
func ConvertUint32(str string) (uint32, error) { i, err := strconv.ParseUint(str, 10, 32) if err != nil { return 0, err } return uint32(i), nil }
go
func ConvertUint32(str string) (uint32, error) { i, err := strconv.ParseUint(str, 10, 32) if err != nil { return 0, err } return uint32(i), nil }
[ "func", "ConvertUint32", "(", "str", "string", ")", "(", "uint32", ",", "error", ")", "{", "i", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "str", ",", "10", ",", "32", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "uint32", "(", "i", ")", ",", "nil", "\n", "}" ]
// ConvertUint32 turn a string into a uint32
[ "ConvertUint32", "turn", "a", "string", "into", "a", "uint32" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert.go#L141-L147
3,916
go-openapi/swag
json.go
WriteJSON
func WriteJSON(data interface{}) ([]byte, error) { if d, ok := data.(ejMarshaler); ok { jw := new(jwriter.Writer) d.MarshalEasyJSON(jw) return jw.BuildBytes() } if d, ok := data.(json.Marshaler); ok { return d.MarshalJSON() } return json.Marshal(data) }
go
func WriteJSON(data interface{}) ([]byte, error) { if d, ok := data.(ejMarshaler); ok { jw := new(jwriter.Writer) d.MarshalEasyJSON(jw) return jw.BuildBytes() } if d, ok := data.(json.Marshaler); ok { return d.MarshalJSON() } return json.Marshal(data) }
[ "func", "WriteJSON", "(", "data", "interface", "{", "}", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "d", ",", "ok", ":=", "data", ".", "(", "ejMarshaler", ")", ";", "ok", "{", "jw", ":=", "new", "(", "jwriter", ".", "Writer", ")", "\n", "d", ".", "MarshalEasyJSON", "(", "jw", ")", "\n", "return", "jw", ".", "BuildBytes", "(", ")", "\n", "}", "\n", "if", "d", ",", "ok", ":=", "data", ".", "(", "json", ".", "Marshaler", ")", ";", "ok", "{", "return", "d", ".", "MarshalJSON", "(", ")", "\n", "}", "\n", "return", "json", ".", "Marshal", "(", "data", ")", "\n", "}" ]
// WriteJSON writes json data, prefers finding an appropriate interface to short-circuit the marshaller // so it takes the fastest option available.
[ "WriteJSON", "writes", "json", "data", "prefers", "finding", "an", "appropriate", "interface", "to", "short", "-", "circuit", "the", "marshaller", "so", "it", "takes", "the", "fastest", "option", "available", "." ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/json.go#L56-L66
3,917
go-openapi/swag
json.go
ReadJSON
func ReadJSON(data []byte, value interface{}) error { trimmedData := bytes.Trim(data, "\x00") if d, ok := value.(ejUnmarshaler); ok { jl := &jlexer.Lexer{Data: trimmedData} d.UnmarshalEasyJSON(jl) return jl.Error() } if d, ok := value.(json.Unmarshaler); ok { return d.UnmarshalJSON(trimmedData) } return json.Unmarshal(trimmedData, value) }
go
func ReadJSON(data []byte, value interface{}) error { trimmedData := bytes.Trim(data, "\x00") if d, ok := value.(ejUnmarshaler); ok { jl := &jlexer.Lexer{Data: trimmedData} d.UnmarshalEasyJSON(jl) return jl.Error() } if d, ok := value.(json.Unmarshaler); ok { return d.UnmarshalJSON(trimmedData) } return json.Unmarshal(trimmedData, value) }
[ "func", "ReadJSON", "(", "data", "[", "]", "byte", ",", "value", "interface", "{", "}", ")", "error", "{", "trimmedData", ":=", "bytes", ".", "Trim", "(", "data", ",", "\"", "\\x00", "\"", ")", "\n", "if", "d", ",", "ok", ":=", "value", ".", "(", "ejUnmarshaler", ")", ";", "ok", "{", "jl", ":=", "&", "jlexer", ".", "Lexer", "{", "Data", ":", "trimmedData", "}", "\n", "d", ".", "UnmarshalEasyJSON", "(", "jl", ")", "\n", "return", "jl", ".", "Error", "(", ")", "\n", "}", "\n", "if", "d", ",", "ok", ":=", "value", ".", "(", "json", ".", "Unmarshaler", ")", ";", "ok", "{", "return", "d", ".", "UnmarshalJSON", "(", "trimmedData", ")", "\n", "}", "\n", "return", "json", ".", "Unmarshal", "(", "trimmedData", ",", "value", ")", "\n", "}" ]
// ReadJSON reads json data, prefers finding an appropriate interface to short-circuit the unmarshaller // so it takes the fastes option available
[ "ReadJSON", "reads", "json", "data", "prefers", "finding", "an", "appropriate", "interface", "to", "short", "-", "circuit", "the", "unmarshaller", "so", "it", "takes", "the", "fastes", "option", "available" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/json.go#L70-L81
3,918
go-openapi/swag
json.go
DynamicJSONToStruct
func DynamicJSONToStruct(data interface{}, target interface{}) error { // TODO: convert straight to a json typed map (mergo + iterate?) b, err := WriteJSON(data) if err != nil { return err } return ReadJSON(b, target) }
go
func DynamicJSONToStruct(data interface{}, target interface{}) error { // TODO: convert straight to a json typed map (mergo + iterate?) b, err := WriteJSON(data) if err != nil { return err } return ReadJSON(b, target) }
[ "func", "DynamicJSONToStruct", "(", "data", "interface", "{", "}", ",", "target", "interface", "{", "}", ")", "error", "{", "// TODO: convert straight to a json typed map (mergo + iterate?)", "b", ",", "err", ":=", "WriteJSON", "(", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "ReadJSON", "(", "b", ",", "target", ")", "\n", "}" ]
// DynamicJSONToStruct converts an untyped json structure into a struct
[ "DynamicJSONToStruct", "converts", "an", "untyped", "json", "structure", "into", "a", "struct" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/json.go#L84-L91
3,919
go-openapi/swag
json.go
ConcatJSON
func ConcatJSON(blobs ...[]byte) []byte { if len(blobs) == 0 { return nil } last := len(blobs) - 1 for blobs[last] == nil || bytes.Equal(blobs[last], nullJSON) { // strips trailing null objects last = last - 1 if last < 0 { // there was nothing but "null"s or nil... return nil } } if last == 0 { return blobs[0] } var opening, closing byte var idx, a int buf := bytes.NewBuffer(nil) for i, b := range blobs[:last+1] { if b == nil || bytes.Equal(b, nullJSON) { // a null object is in the list: skip it continue } if len(b) > 0 && opening == 0 { // is this an array or an object? opening, closing = b[0], closers[b[0]] } if opening != '{' && opening != '[' { continue // don't know how to concatenate non container objects } if len(b) < 3 { // yep empty but also the last one, so closing this thing if i == last && a > 0 { if err := buf.WriteByte(closing); err != nil { log.Println(err) } } continue } idx = 0 if a > 0 { // we need to join with a comma for everything beyond the first non-empty item if err := buf.WriteByte(comma); err != nil { log.Println(err) } idx = 1 // this is not the first or the last so we want to drop the leading bracket } if i != last { // not the last one, strip brackets if _, err := buf.Write(b[idx : len(b)-1]); err != nil { log.Println(err) } } else { // last one, strip only the leading bracket if _, err := buf.Write(b[idx:]); err != nil { log.Println(err) } } a++ } // somehow it ended up being empty, so provide a default value if buf.Len() == 0 { if err := buf.WriteByte(opening); err != nil { log.Println(err) } if err := buf.WriteByte(closing); err != nil { log.Println(err) } } return buf.Bytes() }
go
func ConcatJSON(blobs ...[]byte) []byte { if len(blobs) == 0 { return nil } last := len(blobs) - 1 for blobs[last] == nil || bytes.Equal(blobs[last], nullJSON) { // strips trailing null objects last = last - 1 if last < 0 { // there was nothing but "null"s or nil... return nil } } if last == 0 { return blobs[0] } var opening, closing byte var idx, a int buf := bytes.NewBuffer(nil) for i, b := range blobs[:last+1] { if b == nil || bytes.Equal(b, nullJSON) { // a null object is in the list: skip it continue } if len(b) > 0 && opening == 0 { // is this an array or an object? opening, closing = b[0], closers[b[0]] } if opening != '{' && opening != '[' { continue // don't know how to concatenate non container objects } if len(b) < 3 { // yep empty but also the last one, so closing this thing if i == last && a > 0 { if err := buf.WriteByte(closing); err != nil { log.Println(err) } } continue } idx = 0 if a > 0 { // we need to join with a comma for everything beyond the first non-empty item if err := buf.WriteByte(comma); err != nil { log.Println(err) } idx = 1 // this is not the first or the last so we want to drop the leading bracket } if i != last { // not the last one, strip brackets if _, err := buf.Write(b[idx : len(b)-1]); err != nil { log.Println(err) } } else { // last one, strip only the leading bracket if _, err := buf.Write(b[idx:]); err != nil { log.Println(err) } } a++ } // somehow it ended up being empty, so provide a default value if buf.Len() == 0 { if err := buf.WriteByte(opening); err != nil { log.Println(err) } if err := buf.WriteByte(closing); err != nil { log.Println(err) } } return buf.Bytes() }
[ "func", "ConcatJSON", "(", "blobs", "...", "[", "]", "byte", ")", "[", "]", "byte", "{", "if", "len", "(", "blobs", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "last", ":=", "len", "(", "blobs", ")", "-", "1", "\n", "for", "blobs", "[", "last", "]", "==", "nil", "||", "bytes", ".", "Equal", "(", "blobs", "[", "last", "]", ",", "nullJSON", ")", "{", "// strips trailing null objects", "last", "=", "last", "-", "1", "\n", "if", "last", "<", "0", "{", "// there was nothing but \"null\"s or nil...", "return", "nil", "\n", "}", "\n", "}", "\n", "if", "last", "==", "0", "{", "return", "blobs", "[", "0", "]", "\n", "}", "\n\n", "var", "opening", ",", "closing", "byte", "\n", "var", "idx", ",", "a", "int", "\n", "buf", ":=", "bytes", ".", "NewBuffer", "(", "nil", ")", "\n\n", "for", "i", ",", "b", ":=", "range", "blobs", "[", ":", "last", "+", "1", "]", "{", "if", "b", "==", "nil", "||", "bytes", ".", "Equal", "(", "b", ",", "nullJSON", ")", "{", "// a null object is in the list: skip it", "continue", "\n", "}", "\n", "if", "len", "(", "b", ")", ">", "0", "&&", "opening", "==", "0", "{", "// is this an array or an object?", "opening", ",", "closing", "=", "b", "[", "0", "]", ",", "closers", "[", "b", "[", "0", "]", "]", "\n", "}", "\n\n", "if", "opening", "!=", "'{'", "&&", "opening", "!=", "'['", "{", "continue", "// don't know how to concatenate non container objects", "\n", "}", "\n\n", "if", "len", "(", "b", ")", "<", "3", "{", "// yep empty but also the last one, so closing this thing", "if", "i", "==", "last", "&&", "a", ">", "0", "{", "if", "err", ":=", "buf", ".", "WriteByte", "(", "closing", ")", ";", "err", "!=", "nil", "{", "log", ".", "Println", "(", "err", ")", "\n", "}", "\n", "}", "\n", "continue", "\n", "}", "\n\n", "idx", "=", "0", "\n", "if", "a", ">", "0", "{", "// we need to join with a comma for everything beyond the first non-empty item", "if", "err", ":=", "buf", ".", "WriteByte", "(", "comma", ")", ";", "err", "!=", "nil", "{", "log", ".", "Println", "(", "err", ")", "\n", "}", "\n", "idx", "=", "1", "// this is not the first or the last so we want to drop the leading bracket", "\n", "}", "\n\n", "if", "i", "!=", "last", "{", "// not the last one, strip brackets", "if", "_", ",", "err", ":=", "buf", ".", "Write", "(", "b", "[", "idx", ":", "len", "(", "b", ")", "-", "1", "]", ")", ";", "err", "!=", "nil", "{", "log", ".", "Println", "(", "err", ")", "\n", "}", "\n", "}", "else", "{", "// last one, strip only the leading bracket", "if", "_", ",", "err", ":=", "buf", ".", "Write", "(", "b", "[", "idx", ":", "]", ")", ";", "err", "!=", "nil", "{", "log", ".", "Println", "(", "err", ")", "\n", "}", "\n", "}", "\n", "a", "++", "\n", "}", "\n", "// somehow it ended up being empty, so provide a default value", "if", "buf", ".", "Len", "(", ")", "==", "0", "{", "if", "err", ":=", "buf", ".", "WriteByte", "(", "opening", ")", ";", "err", "!=", "nil", "{", "log", ".", "Println", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "buf", ".", "WriteByte", "(", "closing", ")", ";", "err", "!=", "nil", "{", "log", ".", "Println", "(", "err", ")", "\n", "}", "\n", "}", "\n", "return", "buf", ".", "Bytes", "(", ")", "\n", "}" ]
// ConcatJSON concatenates multiple json objects efficiently
[ "ConcatJSON", "concatenates", "multiple", "json", "objects", "efficiently" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/json.go#L94-L167
3,920
go-openapi/swag
json.go
ToDynamicJSON
func ToDynamicJSON(data interface{}) interface{} { // TODO: convert straight to a json typed map (mergo + iterate?) b, err := json.Marshal(data) if err != nil { log.Println(err) } var res interface{} if err := json.Unmarshal(b, &res); err != nil { log.Println(err) } return res }
go
func ToDynamicJSON(data interface{}) interface{} { // TODO: convert straight to a json typed map (mergo + iterate?) b, err := json.Marshal(data) if err != nil { log.Println(err) } var res interface{} if err := json.Unmarshal(b, &res); err != nil { log.Println(err) } return res }
[ "func", "ToDynamicJSON", "(", "data", "interface", "{", "}", ")", "interface", "{", "}", "{", "// TODO: convert straight to a json typed map (mergo + iterate?)", "b", ",", "err", ":=", "json", ".", "Marshal", "(", "data", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Println", "(", "err", ")", "\n", "}", "\n", "var", "res", "interface", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "b", ",", "&", "res", ")", ";", "err", "!=", "nil", "{", "log", ".", "Println", "(", "err", ")", "\n", "}", "\n", "return", "res", "\n", "}" ]
// ToDynamicJSON turns an object into a properly JSON typed structure
[ "ToDynamicJSON", "turns", "an", "object", "into", "a", "properly", "JSON", "typed", "structure" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/json.go#L170-L181
3,921
go-openapi/swag
json.go
FromDynamicJSON
func FromDynamicJSON(data, target interface{}) error { b, err := json.Marshal(data) if err != nil { log.Println(err) } return json.Unmarshal(b, target) }
go
func FromDynamicJSON(data, target interface{}) error { b, err := json.Marshal(data) if err != nil { log.Println(err) } return json.Unmarshal(b, target) }
[ "func", "FromDynamicJSON", "(", "data", ",", "target", "interface", "{", "}", ")", "error", "{", "b", ",", "err", ":=", "json", ".", "Marshal", "(", "data", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Println", "(", "err", ")", "\n", "}", "\n", "return", "json", ".", "Unmarshal", "(", "b", ",", "target", ")", "\n", "}" ]
// FromDynamicJSON turns an object into a properly JSON typed structure
[ "FromDynamicJSON", "turns", "an", "object", "into", "a", "properly", "JSON", "typed", "structure" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/json.go#L184-L190
3,922
go-openapi/swag
json.go
NewNameProvider
func NewNameProvider() *NameProvider { return &NameProvider{ lock: &sync.Mutex{}, index: make(map[reflect.Type]nameIndex), } }
go
func NewNameProvider() *NameProvider { return &NameProvider{ lock: &sync.Mutex{}, index: make(map[reflect.Type]nameIndex), } }
[ "func", "NewNameProvider", "(", ")", "*", "NameProvider", "{", "return", "&", "NameProvider", "{", "lock", ":", "&", "sync", ".", "Mutex", "{", "}", ",", "index", ":", "make", "(", "map", "[", "reflect", ".", "Type", "]", "nameIndex", ")", ",", "}", "\n", "}" ]
// NewNameProvider creates a new name provider
[ "NewNameProvider", "creates", "a", "new", "name", "provider" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/json.go#L206-L211
3,923
go-openapi/swag
json.go
GetJSONNames
func (n *NameProvider) GetJSONNames(subject interface{}) []string { n.lock.Lock() defer n.lock.Unlock() tpe := reflect.Indirect(reflect.ValueOf(subject)).Type() names, ok := n.index[tpe] if !ok { names = n.makeNameIndex(tpe) } res := make([]string, 0, len(names.jsonNames)) for k := range names.jsonNames { res = append(res, k) } return res }
go
func (n *NameProvider) GetJSONNames(subject interface{}) []string { n.lock.Lock() defer n.lock.Unlock() tpe := reflect.Indirect(reflect.ValueOf(subject)).Type() names, ok := n.index[tpe] if !ok { names = n.makeNameIndex(tpe) } res := make([]string, 0, len(names.jsonNames)) for k := range names.jsonNames { res = append(res, k) } return res }
[ "func", "(", "n", "*", "NameProvider", ")", "GetJSONNames", "(", "subject", "interface", "{", "}", ")", "[", "]", "string", "{", "n", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "n", ".", "lock", ".", "Unlock", "(", ")", "\n", "tpe", ":=", "reflect", ".", "Indirect", "(", "reflect", ".", "ValueOf", "(", "subject", ")", ")", ".", "Type", "(", ")", "\n", "names", ",", "ok", ":=", "n", ".", "index", "[", "tpe", "]", "\n", "if", "!", "ok", "{", "names", "=", "n", ".", "makeNameIndex", "(", "tpe", ")", "\n", "}", "\n\n", "res", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "names", ".", "jsonNames", ")", ")", "\n", "for", "k", ":=", "range", "names", ".", "jsonNames", "{", "res", "=", "append", "(", "res", ",", "k", ")", "\n", "}", "\n", "return", "res", "\n", "}" ]
// GetJSONNames gets all the json property names for a type
[ "GetJSONNames", "gets", "all", "the", "json", "property", "names", "for", "a", "type" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/json.go#L256-L270
3,924
go-openapi/swag
json.go
GetJSONName
func (n *NameProvider) GetJSONName(subject interface{}, name string) (string, bool) { tpe := reflect.Indirect(reflect.ValueOf(subject)).Type() return n.GetJSONNameForType(tpe, name) }
go
func (n *NameProvider) GetJSONName(subject interface{}, name string) (string, bool) { tpe := reflect.Indirect(reflect.ValueOf(subject)).Type() return n.GetJSONNameForType(tpe, name) }
[ "func", "(", "n", "*", "NameProvider", ")", "GetJSONName", "(", "subject", "interface", "{", "}", ",", "name", "string", ")", "(", "string", ",", "bool", ")", "{", "tpe", ":=", "reflect", ".", "Indirect", "(", "reflect", ".", "ValueOf", "(", "subject", ")", ")", ".", "Type", "(", ")", "\n", "return", "n", ".", "GetJSONNameForType", "(", "tpe", ",", "name", ")", "\n", "}" ]
// GetJSONName gets the json name for a go property name
[ "GetJSONName", "gets", "the", "json", "name", "for", "a", "go", "property", "name" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/json.go#L273-L276
3,925
go-openapi/swag
json.go
GetJSONNameForType
func (n *NameProvider) GetJSONNameForType(tpe reflect.Type, name string) (string, bool) { n.lock.Lock() defer n.lock.Unlock() names, ok := n.index[tpe] if !ok { names = n.makeNameIndex(tpe) } nme, ok := names.goNames[name] return nme, ok }
go
func (n *NameProvider) GetJSONNameForType(tpe reflect.Type, name string) (string, bool) { n.lock.Lock() defer n.lock.Unlock() names, ok := n.index[tpe] if !ok { names = n.makeNameIndex(tpe) } nme, ok := names.goNames[name] return nme, ok }
[ "func", "(", "n", "*", "NameProvider", ")", "GetJSONNameForType", "(", "tpe", "reflect", ".", "Type", ",", "name", "string", ")", "(", "string", ",", "bool", ")", "{", "n", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "n", ".", "lock", ".", "Unlock", "(", ")", "\n", "names", ",", "ok", ":=", "n", ".", "index", "[", "tpe", "]", "\n", "if", "!", "ok", "{", "names", "=", "n", ".", "makeNameIndex", "(", "tpe", ")", "\n", "}", "\n", "nme", ",", "ok", ":=", "names", ".", "goNames", "[", "name", "]", "\n", "return", "nme", ",", "ok", "\n", "}" ]
// GetJSONNameForType gets the json name for a go property name on a given type
[ "GetJSONNameForType", "gets", "the", "json", "name", "for", "a", "go", "property", "name", "on", "a", "given", "type" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/json.go#L279-L288
3,926
go-openapi/swag
json.go
GetGoName
func (n *NameProvider) GetGoName(subject interface{}, name string) (string, bool) { tpe := reflect.Indirect(reflect.ValueOf(subject)).Type() return n.GetGoNameForType(tpe, name) }
go
func (n *NameProvider) GetGoName(subject interface{}, name string) (string, bool) { tpe := reflect.Indirect(reflect.ValueOf(subject)).Type() return n.GetGoNameForType(tpe, name) }
[ "func", "(", "n", "*", "NameProvider", ")", "GetGoName", "(", "subject", "interface", "{", "}", ",", "name", "string", ")", "(", "string", ",", "bool", ")", "{", "tpe", ":=", "reflect", ".", "Indirect", "(", "reflect", ".", "ValueOf", "(", "subject", ")", ")", ".", "Type", "(", ")", "\n", "return", "n", ".", "GetGoNameForType", "(", "tpe", ",", "name", ")", "\n", "}" ]
// GetGoName gets the go name for a json property name
[ "GetGoName", "gets", "the", "go", "name", "for", "a", "json", "property", "name" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/json.go#L297-L300
3,927
go-openapi/swag
yaml.go
YAMLMatcher
func YAMLMatcher(path string) bool { ext := filepath.Ext(path) return ext == ".yaml" || ext == ".yml" }
go
func YAMLMatcher(path string) bool { ext := filepath.Ext(path) return ext == ".yaml" || ext == ".yml" }
[ "func", "YAMLMatcher", "(", "path", "string", ")", "bool", "{", "ext", ":=", "filepath", ".", "Ext", "(", "path", ")", "\n", "return", "ext", "==", "\"", "\"", "||", "ext", "==", "\"", "\"", "\n", "}" ]
// YAMLMatcher matches yaml
[ "YAMLMatcher", "matches", "yaml" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/yaml.go#L29-L32
3,928
go-openapi/swag
yaml.go
YAMLToJSON
func YAMLToJSON(data interface{}) (json.RawMessage, error) { jm, err := transformData(data) if err != nil { return nil, err } b, err := WriteJSON(jm) return json.RawMessage(b), err }
go
func YAMLToJSON(data interface{}) (json.RawMessage, error) { jm, err := transformData(data) if err != nil { return nil, err } b, err := WriteJSON(jm) return json.RawMessage(b), err }
[ "func", "YAMLToJSON", "(", "data", "interface", "{", "}", ")", "(", "json", ".", "RawMessage", ",", "error", ")", "{", "jm", ",", "err", ":=", "transformData", "(", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "b", ",", "err", ":=", "WriteJSON", "(", "jm", ")", "\n", "return", "json", ".", "RawMessage", "(", "b", ")", ",", "err", "\n", "}" ]
// YAMLToJSON converts YAML unmarshaled data into json compatible data
[ "YAMLToJSON", "converts", "YAML", "unmarshaled", "data", "into", "json", "compatible", "data" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/yaml.go#L35-L42
3,929
go-openapi/swag
yaml.go
BytesToYAMLDoc
func BytesToYAMLDoc(data []byte) (interface{}, error) { var canary map[interface{}]interface{} // validate this is an object and not a different type if err := yaml.Unmarshal(data, &canary); err != nil { return nil, err } var document yaml.MapSlice // preserve order that is present in the document if err := yaml.Unmarshal(data, &document); err != nil { return nil, err } return document, nil }
go
func BytesToYAMLDoc(data []byte) (interface{}, error) { var canary map[interface{}]interface{} // validate this is an object and not a different type if err := yaml.Unmarshal(data, &canary); err != nil { return nil, err } var document yaml.MapSlice // preserve order that is present in the document if err := yaml.Unmarshal(data, &document); err != nil { return nil, err } return document, nil }
[ "func", "BytesToYAMLDoc", "(", "data", "[", "]", "byte", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "var", "canary", "map", "[", "interface", "{", "}", "]", "interface", "{", "}", "// validate this is an object and not a different type", "\n", "if", "err", ":=", "yaml", ".", "Unmarshal", "(", "data", ",", "&", "canary", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "document", "yaml", ".", "MapSlice", "// preserve order that is present in the document", "\n", "if", "err", ":=", "yaml", ".", "Unmarshal", "(", "data", ",", "&", "document", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "document", ",", "nil", "\n", "}" ]
// BytesToYAMLDoc converts a byte slice into a YAML document
[ "BytesToYAMLDoc", "converts", "a", "byte", "slice", "into", "a", "YAML", "document" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/yaml.go#L45-L56
3,930
go-openapi/swag
yaml.go
MarshalJSON
func (s JSONMapSlice) MarshalJSON() ([]byte, error) { w := &jwriter.Writer{Flags: jwriter.NilMapAsEmpty | jwriter.NilSliceAsEmpty} s.MarshalEasyJSON(w) return w.BuildBytes() }
go
func (s JSONMapSlice) MarshalJSON() ([]byte, error) { w := &jwriter.Writer{Flags: jwriter.NilMapAsEmpty | jwriter.NilSliceAsEmpty} s.MarshalEasyJSON(w) return w.BuildBytes() }
[ "func", "(", "s", "JSONMapSlice", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "w", ":=", "&", "jwriter", ".", "Writer", "{", "Flags", ":", "jwriter", ".", "NilMapAsEmpty", "|", "jwriter", ".", "NilSliceAsEmpty", "}", "\n", "s", ".", "MarshalEasyJSON", "(", "w", ")", "\n", "return", "w", ".", "BuildBytes", "(", ")", "\n", "}" ]
// MarshalJSON renders a JSONMapSlice as JSON
[ "MarshalJSON", "renders", "a", "JSONMapSlice", "as", "JSON" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/yaml.go#L62-L66
3,931
go-openapi/swag
yaml.go
MarshalEasyJSON
func (s JSONMapSlice) MarshalEasyJSON(w *jwriter.Writer) { w.RawByte('{') ln := len(s) last := ln - 1 for i := 0; i < ln; i++ { s[i].MarshalEasyJSON(w) if i != last { // last item w.RawByte(',') } } w.RawByte('}') }
go
func (s JSONMapSlice) MarshalEasyJSON(w *jwriter.Writer) { w.RawByte('{') ln := len(s) last := ln - 1 for i := 0; i < ln; i++ { s[i].MarshalEasyJSON(w) if i != last { // last item w.RawByte(',') } } w.RawByte('}') }
[ "func", "(", "s", "JSONMapSlice", ")", "MarshalEasyJSON", "(", "w", "*", "jwriter", ".", "Writer", ")", "{", "w", ".", "RawByte", "(", "'{'", ")", "\n\n", "ln", ":=", "len", "(", "s", ")", "\n", "last", ":=", "ln", "-", "1", "\n", "for", "i", ":=", "0", ";", "i", "<", "ln", ";", "i", "++", "{", "s", "[", "i", "]", ".", "MarshalEasyJSON", "(", "w", ")", "\n", "if", "i", "!=", "last", "{", "// last item", "w", ".", "RawByte", "(", "','", ")", "\n", "}", "\n", "}", "\n\n", "w", ".", "RawByte", "(", "'}'", ")", "\n", "}" ]
// MarshalEasyJSON renders a JSONMapSlice as JSON, using easyJSON
[ "MarshalEasyJSON", "renders", "a", "JSONMapSlice", "as", "JSON", "using", "easyJSON" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/yaml.go#L69-L82
3,932
go-openapi/swag
yaml.go
UnmarshalEasyJSON
func (s *JSONMapSlice) UnmarshalEasyJSON(in *jlexer.Lexer) { if in.IsNull() { in.Skip() return } var result JSONMapSlice in.Delim('{') for !in.IsDelim('}') { var mi JSONMapItem mi.UnmarshalEasyJSON(in) result = append(result, mi) } *s = result }
go
func (s *JSONMapSlice) UnmarshalEasyJSON(in *jlexer.Lexer) { if in.IsNull() { in.Skip() return } var result JSONMapSlice in.Delim('{') for !in.IsDelim('}') { var mi JSONMapItem mi.UnmarshalEasyJSON(in) result = append(result, mi) } *s = result }
[ "func", "(", "s", "*", "JSONMapSlice", ")", "UnmarshalEasyJSON", "(", "in", "*", "jlexer", ".", "Lexer", ")", "{", "if", "in", ".", "IsNull", "(", ")", "{", "in", ".", "Skip", "(", ")", "\n", "return", "\n", "}", "\n\n", "var", "result", "JSONMapSlice", "\n", "in", ".", "Delim", "(", "'{'", ")", "\n", "for", "!", "in", ".", "IsDelim", "(", "'}'", ")", "{", "var", "mi", "JSONMapItem", "\n", "mi", ".", "UnmarshalEasyJSON", "(", "in", ")", "\n", "result", "=", "append", "(", "result", ",", "mi", ")", "\n", "}", "\n", "*", "s", "=", "result", "\n", "}" ]
// UnmarshalEasyJSON makes a JSONMapSlice from JSON, using easyJSON
[ "UnmarshalEasyJSON", "makes", "a", "JSONMapSlice", "from", "JSON", "using", "easyJSON" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/yaml.go#L92-L106
3,933
go-openapi/swag
yaml.go
MarshalEasyJSON
func (s JSONMapItem) MarshalEasyJSON(w *jwriter.Writer) { w.String(s.Key) w.RawByte(':') w.Raw(WriteJSON(s.Value)) }
go
func (s JSONMapItem) MarshalEasyJSON(w *jwriter.Writer) { w.String(s.Key) w.RawByte(':') w.Raw(WriteJSON(s.Value)) }
[ "func", "(", "s", "JSONMapItem", ")", "MarshalEasyJSON", "(", "w", "*", "jwriter", ".", "Writer", ")", "{", "w", ".", "String", "(", "s", ".", "Key", ")", "\n", "w", ".", "RawByte", "(", "':'", ")", "\n", "w", ".", "Raw", "(", "WriteJSON", "(", "s", ".", "Value", ")", ")", "\n", "}" ]
// MarshalEasyJSON renders a JSONMapItem as JSON, using easyJSON
[ "MarshalEasyJSON", "renders", "a", "JSONMapItem", "as", "JSON", "using", "easyJSON" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/yaml.go#L122-L126
3,934
go-openapi/swag
yaml.go
UnmarshalJSON
func (s *JSONMapItem) UnmarshalJSON(data []byte) error { l := jlexer.Lexer{Data: data} s.UnmarshalEasyJSON(&l) return l.Error() }
go
func (s *JSONMapItem) UnmarshalJSON(data []byte) error { l := jlexer.Lexer{Data: data} s.UnmarshalEasyJSON(&l) return l.Error() }
[ "func", "(", "s", "*", "JSONMapItem", ")", "UnmarshalJSON", "(", "data", "[", "]", "byte", ")", "error", "{", "l", ":=", "jlexer", ".", "Lexer", "{", "Data", ":", "data", "}", "\n", "s", ".", "UnmarshalEasyJSON", "(", "&", "l", ")", "\n", "return", "l", ".", "Error", "(", ")", "\n", "}" ]
// UnmarshalJSON makes a JSONMapItem from JSON
[ "UnmarshalJSON", "makes", "a", "JSONMapItem", "from", "JSON" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/yaml.go#L129-L133
3,935
go-openapi/swag
yaml.go
UnmarshalEasyJSON
func (s *JSONMapItem) UnmarshalEasyJSON(in *jlexer.Lexer) { key := in.UnsafeString() in.WantColon() value := in.Interface() in.WantComma() s.Key = key s.Value = value }
go
func (s *JSONMapItem) UnmarshalEasyJSON(in *jlexer.Lexer) { key := in.UnsafeString() in.WantColon() value := in.Interface() in.WantComma() s.Key = key s.Value = value }
[ "func", "(", "s", "*", "JSONMapItem", ")", "UnmarshalEasyJSON", "(", "in", "*", "jlexer", ".", "Lexer", ")", "{", "key", ":=", "in", ".", "UnsafeString", "(", ")", "\n", "in", ".", "WantColon", "(", ")", "\n", "value", ":=", "in", ".", "Interface", "(", ")", "\n", "in", ".", "WantComma", "(", ")", "\n", "s", ".", "Key", "=", "key", "\n", "s", ".", "Value", "=", "value", "\n", "}" ]
// UnmarshalEasyJSON makes a JSONMapItem from JSON, using easyJSON
[ "UnmarshalEasyJSON", "makes", "a", "JSONMapItem", "from", "JSON", "using", "easyJSON" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/yaml.go#L136-L143
3,936
go-openapi/swag
yaml.go
YAMLDoc
func YAMLDoc(path string) (json.RawMessage, error) { yamlDoc, err := YAMLData(path) if err != nil { return nil, err } data, err := YAMLToJSON(yamlDoc) if err != nil { return nil, err } return data, nil }
go
func YAMLDoc(path string) (json.RawMessage, error) { yamlDoc, err := YAMLData(path) if err != nil { return nil, err } data, err := YAMLToJSON(yamlDoc) if err != nil { return nil, err } return data, nil }
[ "func", "YAMLDoc", "(", "path", "string", ")", "(", "json", ".", "RawMessage", ",", "error", ")", "{", "yamlDoc", ",", "err", ":=", "YAMLData", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "data", ",", "err", ":=", "YAMLToJSON", "(", "yamlDoc", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "data", ",", "nil", "\n", "}" ]
// YAMLDoc loads a yaml document from either http or a file and converts it to json
[ "YAMLDoc", "loads", "a", "yaml", "document", "from", "either", "http", "or", "a", "file", "and", "converts", "it", "to", "json" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/yaml.go#L205-L217
3,937
go-openapi/swag
yaml.go
YAMLData
func YAMLData(path string) (interface{}, error) { data, err := LoadFromFileOrHTTP(path) if err != nil { return nil, err } return BytesToYAMLDoc(data) }
go
func YAMLData(path string) (interface{}, error) { data, err := LoadFromFileOrHTTP(path) if err != nil { return nil, err } return BytesToYAMLDoc(data) }
[ "func", "YAMLData", "(", "path", "string", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "data", ",", "err", ":=", "LoadFromFileOrHTTP", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "BytesToYAMLDoc", "(", "data", ")", "\n", "}" ]
// YAMLData loads a yaml document from either http or a file
[ "YAMLData", "loads", "a", "yaml", "document", "from", "either", "http", "or", "a", "file" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/yaml.go#L220-L227
3,938
go-openapi/swag
loading.go
LoadFromFileOrHTTP
func LoadFromFileOrHTTP(path string) ([]byte, error) { return LoadStrategy(path, ioutil.ReadFile, loadHTTPBytes(LoadHTTPTimeout))(path) }
go
func LoadFromFileOrHTTP(path string) ([]byte, error) { return LoadStrategy(path, ioutil.ReadFile, loadHTTPBytes(LoadHTTPTimeout))(path) }
[ "func", "LoadFromFileOrHTTP", "(", "path", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "LoadStrategy", "(", "path", ",", "ioutil", ".", "ReadFile", ",", "loadHTTPBytes", "(", "LoadHTTPTimeout", ")", ")", "(", "path", ")", "\n", "}" ]
// LoadFromFileOrHTTP loads the bytes from a file or a remote http server based on the path passed in
[ "LoadFromFileOrHTTP", "loads", "the", "bytes", "from", "a", "file", "or", "a", "remote", "http", "server", "based", "on", "the", "path", "passed", "in" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/loading.go#L31-L33
3,939
go-openapi/swag
loading.go
LoadFromFileOrHTTPWithTimeout
func LoadFromFileOrHTTPWithTimeout(path string, timeout time.Duration) ([]byte, error) { return LoadStrategy(path, ioutil.ReadFile, loadHTTPBytes(timeout))(path) }
go
func LoadFromFileOrHTTPWithTimeout(path string, timeout time.Duration) ([]byte, error) { return LoadStrategy(path, ioutil.ReadFile, loadHTTPBytes(timeout))(path) }
[ "func", "LoadFromFileOrHTTPWithTimeout", "(", "path", "string", ",", "timeout", "time", ".", "Duration", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "LoadStrategy", "(", "path", ",", "ioutil", ".", "ReadFile", ",", "loadHTTPBytes", "(", "timeout", ")", ")", "(", "path", ")", "\n", "}" ]
// LoadFromFileOrHTTPWithTimeout loads the bytes from a file or a remote http server based on the path passed in // timeout arg allows for per request overriding of the request timeout
[ "LoadFromFileOrHTTPWithTimeout", "loads", "the", "bytes", "from", "a", "file", "or", "a", "remote", "http", "server", "based", "on", "the", "path", "passed", "in", "timeout", "arg", "allows", "for", "per", "request", "overriding", "of", "the", "request", "timeout" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/loading.go#L37-L39
3,940
go-openapi/swag
loading.go
LoadStrategy
func LoadStrategy(path string, local, remote func(string) ([]byte, error)) func(string) ([]byte, error) { if strings.HasPrefix(path, "http") { return remote } return func(pth string) ([]byte, error) { upth, err := pathUnescape(pth) if err != nil { return nil, err } return local(filepath.FromSlash(upth)) } }
go
func LoadStrategy(path string, local, remote func(string) ([]byte, error)) func(string) ([]byte, error) { if strings.HasPrefix(path, "http") { return remote } return func(pth string) ([]byte, error) { upth, err := pathUnescape(pth) if err != nil { return nil, err } return local(filepath.FromSlash(upth)) } }
[ "func", "LoadStrategy", "(", "path", "string", ",", "local", ",", "remote", "func", "(", "string", ")", "(", "[", "]", "byte", ",", "error", ")", ")", "func", "(", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "strings", ".", "HasPrefix", "(", "path", ",", "\"", "\"", ")", "{", "return", "remote", "\n", "}", "\n", "return", "func", "(", "pth", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "upth", ",", "err", ":=", "pathUnescape", "(", "pth", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "local", "(", "filepath", ".", "FromSlash", "(", "upth", ")", ")", "\n", "}", "\n", "}" ]
// LoadStrategy returns a loader function for a given path or uri
[ "LoadStrategy", "returns", "a", "loader", "function", "for", "a", "given", "path", "or", "uri" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/loading.go#L42-L53
3,941
go-openapi/swag
convert_types.go
Int32Slice
func Int32Slice(src []int32) []*int32 { dst := make([]*int32, len(src)) for i := 0; i < len(src); i++ { dst[i] = &(src[i]) } return dst }
go
func Int32Slice(src []int32) []*int32 { dst := make([]*int32, len(src)) for i := 0; i < len(src); i++ { dst[i] = &(src[i]) } return dst }
[ "func", "Int32Slice", "(", "src", "[", "]", "int32", ")", "[", "]", "*", "int32", "{", "dst", ":=", "make", "(", "[", "]", "*", "int32", ",", "len", "(", "src", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "src", ")", ";", "i", "++", "{", "dst", "[", "i", "]", "=", "&", "(", "src", "[", "i", "]", ")", "\n", "}", "\n", "return", "dst", "\n", "}" ]
// Int32Slice converts a slice of int64 values into a slice of // int32 pointers
[ "Int32Slice", "converts", "a", "slice", "of", "int64", "values", "into", "a", "slice", "of", "int32", "pointers" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert_types.go#L200-L206
3,942
go-openapi/swag
convert_types.go
Int32ValueSlice
func Int32ValueSlice(src []*int32) []int32 { dst := make([]int32, len(src)) for i := 0; i < len(src); i++ { if src[i] != nil { dst[i] = *(src[i]) } } return dst }
go
func Int32ValueSlice(src []*int32) []int32 { dst := make([]int32, len(src)) for i := 0; i < len(src); i++ { if src[i] != nil { dst[i] = *(src[i]) } } return dst }
[ "func", "Int32ValueSlice", "(", "src", "[", "]", "*", "int32", ")", "[", "]", "int32", "{", "dst", ":=", "make", "(", "[", "]", "int32", ",", "len", "(", "src", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "src", ")", ";", "i", "++", "{", "if", "src", "[", "i", "]", "!=", "nil", "{", "dst", "[", "i", "]", "=", "*", "(", "src", "[", "i", "]", ")", "\n", "}", "\n", "}", "\n", "return", "dst", "\n", "}" ]
// Int32ValueSlice converts a slice of int32 pointers into a slice of // int32 values
[ "Int32ValueSlice", "converts", "a", "slice", "of", "int32", "pointers", "into", "a", "slice", "of", "int32", "values" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert_types.go#L210-L218
3,943
go-openapi/swag
convert_types.go
Int32Map
func Int32Map(src map[string]int32) map[string]*int32 { dst := make(map[string]*int32) for k, val := range src { v := val dst[k] = &v } return dst }
go
func Int32Map(src map[string]int32) map[string]*int32 { dst := make(map[string]*int32) for k, val := range src { v := val dst[k] = &v } return dst }
[ "func", "Int32Map", "(", "src", "map", "[", "string", "]", "int32", ")", "map", "[", "string", "]", "*", "int32", "{", "dst", ":=", "make", "(", "map", "[", "string", "]", "*", "int32", ")", "\n", "for", "k", ",", "val", ":=", "range", "src", "{", "v", ":=", "val", "\n", "dst", "[", "k", "]", "=", "&", "v", "\n", "}", "\n", "return", "dst", "\n", "}" ]
// Int32Map converts a string map of int32 values into a string // map of int32 pointers
[ "Int32Map", "converts", "a", "string", "map", "of", "int32", "values", "into", "a", "string", "map", "of", "int32", "pointers" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert_types.go#L222-L229
3,944
go-openapi/swag
convert_types.go
Int32ValueMap
func Int32ValueMap(src map[string]*int32) map[string]int32 { dst := make(map[string]int32) for k, val := range src { if val != nil { dst[k] = *val } } return dst }
go
func Int32ValueMap(src map[string]*int32) map[string]int32 { dst := make(map[string]int32) for k, val := range src { if val != nil { dst[k] = *val } } return dst }
[ "func", "Int32ValueMap", "(", "src", "map", "[", "string", "]", "*", "int32", ")", "map", "[", "string", "]", "int32", "{", "dst", ":=", "make", "(", "map", "[", "string", "]", "int32", ")", "\n", "for", "k", ",", "val", ":=", "range", "src", "{", "if", "val", "!=", "nil", "{", "dst", "[", "k", "]", "=", "*", "val", "\n", "}", "\n", "}", "\n", "return", "dst", "\n", "}" ]
// Int32ValueMap converts a string map of int32 pointers into a string // map of int32 values
[ "Int32ValueMap", "converts", "a", "string", "map", "of", "int32", "pointers", "into", "a", "string", "map", "of", "int32", "values" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert_types.go#L233-L241
3,945
go-openapi/swag
convert_types.go
UintSlice
func UintSlice(src []uint) []*uint { dst := make([]*uint, len(src)) for i := 0; i < len(src); i++ { dst[i] = &(src[i]) } return dst }
go
func UintSlice(src []uint) []*uint { dst := make([]*uint, len(src)) for i := 0; i < len(src); i++ { dst[i] = &(src[i]) } return dst }
[ "func", "UintSlice", "(", "src", "[", "]", "uint", ")", "[", "]", "*", "uint", "{", "dst", ":=", "make", "(", "[", "]", "*", "uint", ",", "len", "(", "src", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "src", ")", ";", "i", "++", "{", "dst", "[", "i", "]", "=", "&", "(", "src", "[", "i", "]", ")", "\n", "}", "\n", "return", "dst", "\n", "}" ]
// UintSlice converts a slice of uint values uinto a slice of // uint pouinters
[ "UintSlice", "converts", "a", "slice", "of", "uint", "values", "uinto", "a", "slice", "of", "uint", "pouinters" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert_types.go#L318-L324
3,946
go-openapi/swag
convert_types.go
UintValueSlice
func UintValueSlice(src []*uint) []uint { dst := make([]uint, len(src)) for i := 0; i < len(src); i++ { if src[i] != nil { dst[i] = *(src[i]) } } return dst }
go
func UintValueSlice(src []*uint) []uint { dst := make([]uint, len(src)) for i := 0; i < len(src); i++ { if src[i] != nil { dst[i] = *(src[i]) } } return dst }
[ "func", "UintValueSlice", "(", "src", "[", "]", "*", "uint", ")", "[", "]", "uint", "{", "dst", ":=", "make", "(", "[", "]", "uint", ",", "len", "(", "src", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "src", ")", ";", "i", "++", "{", "if", "src", "[", "i", "]", "!=", "nil", "{", "dst", "[", "i", "]", "=", "*", "(", "src", "[", "i", "]", ")", "\n", "}", "\n", "}", "\n", "return", "dst", "\n", "}" ]
// UintValueSlice converts a slice of uint pouinters uinto a slice of // uint values
[ "UintValueSlice", "converts", "a", "slice", "of", "uint", "pouinters", "uinto", "a", "slice", "of", "uint", "values" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert_types.go#L328-L336
3,947
go-openapi/swag
convert_types.go
UintMap
func UintMap(src map[string]uint) map[string]*uint { dst := make(map[string]*uint) for k, val := range src { v := val dst[k] = &v } return dst }
go
func UintMap(src map[string]uint) map[string]*uint { dst := make(map[string]*uint) for k, val := range src { v := val dst[k] = &v } return dst }
[ "func", "UintMap", "(", "src", "map", "[", "string", "]", "uint", ")", "map", "[", "string", "]", "*", "uint", "{", "dst", ":=", "make", "(", "map", "[", "string", "]", "*", "uint", ")", "\n", "for", "k", ",", "val", ":=", "range", "src", "{", "v", ":=", "val", "\n", "dst", "[", "k", "]", "=", "&", "v", "\n", "}", "\n", "return", "dst", "\n", "}" ]
// UintMap converts a string map of uint values uinto a string // map of uint pouinters
[ "UintMap", "converts", "a", "string", "map", "of", "uint", "values", "uinto", "a", "string", "map", "of", "uint", "pouinters" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert_types.go#L340-L347
3,948
go-openapi/swag
convert_types.go
UintValueMap
func UintValueMap(src map[string]*uint) map[string]uint { dst := make(map[string]uint) for k, val := range src { if val != nil { dst[k] = *val } } return dst }
go
func UintValueMap(src map[string]*uint) map[string]uint { dst := make(map[string]uint) for k, val := range src { if val != nil { dst[k] = *val } } return dst }
[ "func", "UintValueMap", "(", "src", "map", "[", "string", "]", "*", "uint", ")", "map", "[", "string", "]", "uint", "{", "dst", ":=", "make", "(", "map", "[", "string", "]", "uint", ")", "\n", "for", "k", ",", "val", ":=", "range", "src", "{", "if", "val", "!=", "nil", "{", "dst", "[", "k", "]", "=", "*", "val", "\n", "}", "\n", "}", "\n", "return", "dst", "\n", "}" ]
// UintValueMap converts a string map of uint pouinters uinto a string // map of uint values
[ "UintValueMap", "converts", "a", "string", "map", "of", "uint", "pouinters", "uinto", "a", "string", "map", "of", "uint", "values" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert_types.go#L351-L359
3,949
go-openapi/swag
convert_types.go
Uint32Slice
func Uint32Slice(src []uint32) []*uint32 { dst := make([]*uint32, len(src)) for i := 0; i < len(src); i++ { dst[i] = &(src[i]) } return dst }
go
func Uint32Slice(src []uint32) []*uint32 { dst := make([]*uint32, len(src)) for i := 0; i < len(src); i++ { dst[i] = &(src[i]) } return dst }
[ "func", "Uint32Slice", "(", "src", "[", "]", "uint32", ")", "[", "]", "*", "uint32", "{", "dst", ":=", "make", "(", "[", "]", "*", "uint32", ",", "len", "(", "src", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "src", ")", ";", "i", "++", "{", "dst", "[", "i", "]", "=", "&", "(", "src", "[", "i", "]", ")", "\n", "}", "\n", "return", "dst", "\n", "}" ]
// Uint32Slice converts a slice of uint64 values uinto a slice of // uint32 pouinters
[ "Uint32Slice", "converts", "a", "slice", "of", "uint64", "values", "uinto", "a", "slice", "of", "uint32", "pouinters" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert_types.go#L377-L383
3,950
go-openapi/swag
convert_types.go
Uint32ValueSlice
func Uint32ValueSlice(src []*uint32) []uint32 { dst := make([]uint32, len(src)) for i := 0; i < len(src); i++ { if src[i] != nil { dst[i] = *(src[i]) } } return dst }
go
func Uint32ValueSlice(src []*uint32) []uint32 { dst := make([]uint32, len(src)) for i := 0; i < len(src); i++ { if src[i] != nil { dst[i] = *(src[i]) } } return dst }
[ "func", "Uint32ValueSlice", "(", "src", "[", "]", "*", "uint32", ")", "[", "]", "uint32", "{", "dst", ":=", "make", "(", "[", "]", "uint32", ",", "len", "(", "src", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "src", ")", ";", "i", "++", "{", "if", "src", "[", "i", "]", "!=", "nil", "{", "dst", "[", "i", "]", "=", "*", "(", "src", "[", "i", "]", ")", "\n", "}", "\n", "}", "\n", "return", "dst", "\n", "}" ]
// Uint32ValueSlice converts a slice of uint32 pouinters uinto a slice of // uint32 values
[ "Uint32ValueSlice", "converts", "a", "slice", "of", "uint32", "pouinters", "uinto", "a", "slice", "of", "uint32", "values" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert_types.go#L387-L395
3,951
go-openapi/swag
convert_types.go
Uint32Map
func Uint32Map(src map[string]uint32) map[string]*uint32 { dst := make(map[string]*uint32) for k, val := range src { v := val dst[k] = &v } return dst }
go
func Uint32Map(src map[string]uint32) map[string]*uint32 { dst := make(map[string]*uint32) for k, val := range src { v := val dst[k] = &v } return dst }
[ "func", "Uint32Map", "(", "src", "map", "[", "string", "]", "uint32", ")", "map", "[", "string", "]", "*", "uint32", "{", "dst", ":=", "make", "(", "map", "[", "string", "]", "*", "uint32", ")", "\n", "for", "k", ",", "val", ":=", "range", "src", "{", "v", ":=", "val", "\n", "dst", "[", "k", "]", "=", "&", "v", "\n", "}", "\n", "return", "dst", "\n", "}" ]
// Uint32Map converts a string map of uint32 values uinto a string // map of uint32 pouinters
[ "Uint32Map", "converts", "a", "string", "map", "of", "uint32", "values", "uinto", "a", "string", "map", "of", "uint32", "pouinters" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert_types.go#L399-L406
3,952
go-openapi/swag
convert_types.go
Uint32ValueMap
func Uint32ValueMap(src map[string]*uint32) map[string]uint32 { dst := make(map[string]uint32) for k, val := range src { if val != nil { dst[k] = *val } } return dst }
go
func Uint32ValueMap(src map[string]*uint32) map[string]uint32 { dst := make(map[string]uint32) for k, val := range src { if val != nil { dst[k] = *val } } return dst }
[ "func", "Uint32ValueMap", "(", "src", "map", "[", "string", "]", "*", "uint32", ")", "map", "[", "string", "]", "uint32", "{", "dst", ":=", "make", "(", "map", "[", "string", "]", "uint32", ")", "\n", "for", "k", ",", "val", ":=", "range", "src", "{", "if", "val", "!=", "nil", "{", "dst", "[", "k", "]", "=", "*", "val", "\n", "}", "\n", "}", "\n", "return", "dst", "\n", "}" ]
// Uint32ValueMap converts a string map of uint32 pouinters uinto a string // map of uint32 values
[ "Uint32ValueMap", "converts", "a", "string", "map", "of", "uint32", "pouinters", "uinto", "a", "string", "map", "of", "uint32", "values" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert_types.go#L410-L418
3,953
go-openapi/swag
convert_types.go
Uint64Slice
func Uint64Slice(src []uint64) []*uint64 { dst := make([]*uint64, len(src)) for i := 0; i < len(src); i++ { dst[i] = &(src[i]) } return dst }
go
func Uint64Slice(src []uint64) []*uint64 { dst := make([]*uint64, len(src)) for i := 0; i < len(src); i++ { dst[i] = &(src[i]) } return dst }
[ "func", "Uint64Slice", "(", "src", "[", "]", "uint64", ")", "[", "]", "*", "uint64", "{", "dst", ":=", "make", "(", "[", "]", "*", "uint64", ",", "len", "(", "src", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "src", ")", ";", "i", "++", "{", "dst", "[", "i", "]", "=", "&", "(", "src", "[", "i", "]", ")", "\n", "}", "\n", "return", "dst", "\n", "}" ]
// Uint64Slice converts a slice of uint64 values uinto a slice of // uint64 pouinters
[ "Uint64Slice", "converts", "a", "slice", "of", "uint64", "values", "uinto", "a", "slice", "of", "uint64", "pouinters" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert_types.go#L436-L442
3,954
go-openapi/swag
convert_types.go
Uint64ValueSlice
func Uint64ValueSlice(src []*uint64) []uint64 { dst := make([]uint64, len(src)) for i := 0; i < len(src); i++ { if src[i] != nil { dst[i] = *(src[i]) } } return dst }
go
func Uint64ValueSlice(src []*uint64) []uint64 { dst := make([]uint64, len(src)) for i := 0; i < len(src); i++ { if src[i] != nil { dst[i] = *(src[i]) } } return dst }
[ "func", "Uint64ValueSlice", "(", "src", "[", "]", "*", "uint64", ")", "[", "]", "uint64", "{", "dst", ":=", "make", "(", "[", "]", "uint64", ",", "len", "(", "src", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "src", ")", ";", "i", "++", "{", "if", "src", "[", "i", "]", "!=", "nil", "{", "dst", "[", "i", "]", "=", "*", "(", "src", "[", "i", "]", ")", "\n", "}", "\n", "}", "\n", "return", "dst", "\n", "}" ]
// Uint64ValueSlice converts a slice of uint64 pouinters uinto a slice of // uint64 values
[ "Uint64ValueSlice", "converts", "a", "slice", "of", "uint64", "pouinters", "uinto", "a", "slice", "of", "uint64", "values" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert_types.go#L446-L454
3,955
go-openapi/swag
convert_types.go
Uint64Map
func Uint64Map(src map[string]uint64) map[string]*uint64 { dst := make(map[string]*uint64) for k, val := range src { v := val dst[k] = &v } return dst }
go
func Uint64Map(src map[string]uint64) map[string]*uint64 { dst := make(map[string]*uint64) for k, val := range src { v := val dst[k] = &v } return dst }
[ "func", "Uint64Map", "(", "src", "map", "[", "string", "]", "uint64", ")", "map", "[", "string", "]", "*", "uint64", "{", "dst", ":=", "make", "(", "map", "[", "string", "]", "*", "uint64", ")", "\n", "for", "k", ",", "val", ":=", "range", "src", "{", "v", ":=", "val", "\n", "dst", "[", "k", "]", "=", "&", "v", "\n", "}", "\n", "return", "dst", "\n", "}" ]
// Uint64Map converts a string map of uint64 values uinto a string // map of uint64 pouinters
[ "Uint64Map", "converts", "a", "string", "map", "of", "uint64", "values", "uinto", "a", "string", "map", "of", "uint64", "pouinters" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert_types.go#L458-L465
3,956
go-openapi/swag
convert_types.go
Uint64ValueMap
func Uint64ValueMap(src map[string]*uint64) map[string]uint64 { dst := make(map[string]uint64) for k, val := range src { if val != nil { dst[k] = *val } } return dst }
go
func Uint64ValueMap(src map[string]*uint64) map[string]uint64 { dst := make(map[string]uint64) for k, val := range src { if val != nil { dst[k] = *val } } return dst }
[ "func", "Uint64ValueMap", "(", "src", "map", "[", "string", "]", "*", "uint64", ")", "map", "[", "string", "]", "uint64", "{", "dst", ":=", "make", "(", "map", "[", "string", "]", "uint64", ")", "\n", "for", "k", ",", "val", ":=", "range", "src", "{", "if", "val", "!=", "nil", "{", "dst", "[", "k", "]", "=", "*", "val", "\n", "}", "\n", "}", "\n", "return", "dst", "\n", "}" ]
// Uint64ValueMap converts a string map of uint64 pouinters uinto a string // map of uint64 values
[ "Uint64ValueMap", "converts", "a", "string", "map", "of", "uint64", "pouinters", "uinto", "a", "string", "map", "of", "uint64", "values" ]
b3e2804c8535ee0d1b89320afd98474d5b8e9e3b
https://github.com/go-openapi/swag/blob/b3e2804c8535ee0d1b89320afd98474d5b8e9e3b/convert_types.go#L469-L477
3,957
robfig/soy
soymsg/pomsg/msgid.go
pluralCase
func pluralCase(n *ast.MsgPluralNode, singular bool) ast.ParentNode { if singular { return n.Cases[0].Body } return n.Default }
go
func pluralCase(n *ast.MsgPluralNode, singular bool) ast.ParentNode { if singular { return n.Cases[0].Body } return n.Default }
[ "func", "pluralCase", "(", "n", "*", "ast", ".", "MsgPluralNode", ",", "singular", "bool", ")", "ast", ".", "ParentNode", "{", "if", "singular", "{", "return", "n", ".", "Cases", "[", "0", "]", ".", "Body", "\n", "}", "\n", "return", "n", ".", "Default", "\n", "}" ]
// pluralCase returns the singular or plural message body.
[ "pluralCase", "returns", "the", "singular", "or", "plural", "message", "body", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/soymsg/pomsg/msgid.go#L59-L64
3,958
robfig/soy
soymsg/pomsg/msgid.go
writeph
func writeph(buf *bytes.Buffer, child ast.Node) { switch child := child.(type) { case *ast.RawTextNode: buf.Write(child.Text) case *ast.MsgPlaceholderNode: buf.WriteString("{" + child.Name + "}") } }
go
func writeph(buf *bytes.Buffer, child ast.Node) { switch child := child.(type) { case *ast.RawTextNode: buf.Write(child.Text) case *ast.MsgPlaceholderNode: buf.WriteString("{" + child.Name + "}") } }
[ "func", "writeph", "(", "buf", "*", "bytes", ".", "Buffer", ",", "child", "ast", ".", "Node", ")", "{", "switch", "child", ":=", "child", ".", "(", "type", ")", "{", "case", "*", "ast", ".", "RawTextNode", ":", "buf", ".", "Write", "(", "child", ".", "Text", ")", "\n", "case", "*", "ast", ".", "MsgPlaceholderNode", ":", "buf", ".", "WriteString", "(", "\"", "\"", "+", "child", ".", "Name", "+", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// writeph writes the placeholder string for the given node to the given buffer.
[ "writeph", "writes", "the", "placeholder", "string", "for", "the", "given", "node", "to", "the", "given", "buffer", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/soymsg/pomsg/msgid.go#L67-L74
3,959
robfig/soy
ast/node.go
Placeholder
func (n *MsgNode) Placeholder(name string) *MsgPlaceholderNode { var q = n.Body.Children() for len(q) > 0 { var node Node node, q = q[0], q[1:] switch node := node.(type) { case *MsgPlaceholderNode: if node.Name == name { return node } default: if node, ok := node.(ParentNode); ok { q = append(q, node.Children()...) } } } return nil }
go
func (n *MsgNode) Placeholder(name string) *MsgPlaceholderNode { var q = n.Body.Children() for len(q) > 0 { var node Node node, q = q[0], q[1:] switch node := node.(type) { case *MsgPlaceholderNode: if node.Name == name { return node } default: if node, ok := node.(ParentNode); ok { q = append(q, node.Children()...) } } } return nil }
[ "func", "(", "n", "*", "MsgNode", ")", "Placeholder", "(", "name", "string", ")", "*", "MsgPlaceholderNode", "{", "var", "q", "=", "n", ".", "Body", ".", "Children", "(", ")", "\n", "for", "len", "(", "q", ")", ">", "0", "{", "var", "node", "Node", "\n", "node", ",", "q", "=", "q", "[", "0", "]", ",", "q", "[", "1", ":", "]", "\n", "switch", "node", ":=", "node", ".", "(", "type", ")", "{", "case", "*", "MsgPlaceholderNode", ":", "if", "node", ".", "Name", "==", "name", "{", "return", "node", "\n", "}", "\n", "default", ":", "if", "node", ",", "ok", ":=", "node", ".", "(", "ParentNode", ")", ";", "ok", "{", "q", "=", "append", "(", "q", ",", "node", ".", "Children", "(", ")", "...", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Placeholder returns a placeholder node with the given name within this // message node. It requires placeholder names to have been calculated.
[ "Placeholder", "returns", "a", "placeholder", "node", "with", "the", "given", "name", "within", "this", "message", "node", ".", "It", "requires", "placeholder", "names", "to", "have", "been", "calculated", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/ast/node.go#L324-L341
3,960
robfig/soy
soyhtml/exec.go
renderBlock
func (s *state) renderBlock(node ast.Node) []byte { var buf bytes.Buffer origWriter := s.wr s.wr = &buf s.walk(node) s.wr = origWriter return buf.Bytes() }
go
func (s *state) renderBlock(node ast.Node) []byte { var buf bytes.Buffer origWriter := s.wr s.wr = &buf s.walk(node) s.wr = origWriter return buf.Bytes() }
[ "func", "(", "s", "*", "state", ")", "renderBlock", "(", "node", "ast", ".", "Node", ")", "[", "]", "byte", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "origWriter", ":=", "s", ".", "wr", "\n", "s", ".", "wr", "=", "&", "buf", "\n", "s", ".", "walk", "(", "node", ")", "\n", "s", ".", "wr", "=", "origWriter", "\n", "return", "buf", ".", "Bytes", "(", ")", "\n", "}" ]
// renderBlock is a helper that renders the given node to a temporary output // buffer and returns that result. nothing is written to the main output.
[ "renderBlock", "is", "a", "helper", "that", "renders", "the", "given", "node", "to", "a", "temporary", "output", "buffer", "and", "returns", "that", "result", ".", "nothing", "is", "written", "to", "the", "main", "output", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/soyhtml/exec.go#L524-L531
3,961
robfig/soy
soyhtml/exec.go
isNullSafeAccess
func isNullSafeAccess(n ast.Node) bool { switch node := n.(type) { case *ast.DataRefIndexNode: return node.NullSafe case *ast.DataRefKeyNode: return node.NullSafe case *ast.DataRefExprNode: return node.NullSafe } panic("unexpected") }
go
func isNullSafeAccess(n ast.Node) bool { switch node := n.(type) { case *ast.DataRefIndexNode: return node.NullSafe case *ast.DataRefKeyNode: return node.NullSafe case *ast.DataRefExprNode: return node.NullSafe } panic("unexpected") }
[ "func", "isNullSafeAccess", "(", "n", "ast", ".", "Node", ")", "bool", "{", "switch", "node", ":=", "n", ".", "(", "type", ")", "{", "case", "*", "ast", ".", "DataRefIndexNode", ":", "return", "node", ".", "NullSafe", "\n", "case", "*", "ast", ".", "DataRefKeyNode", ":", "return", "node", ".", "NullSafe", "\n", "case", "*", "ast", ".", "DataRefExprNode", ":", "return", "node", ".", "NullSafe", "\n", "}", "\n", "panic", "(", "\"", "\"", ")", "\n", "}" ]
// isNullSafeAccess returns true if the data ref access node is a nullsafe // access.
[ "isNullSafeAccess", "returns", "true", "if", "the", "data", "ref", "access", "node", "is", "a", "nullsafe", "access", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/soyhtml/exec.go#L640-L650
3,962
robfig/soy
soyhtml/exec.go
eval2def
func (s *state) eval2def(n1, n2 ast.Node) (data.Value, data.Value) { return s.evaldef(n1), s.evaldef(n2) }
go
func (s *state) eval2def(n1, n2 ast.Node) (data.Value, data.Value) { return s.evaldef(n1), s.evaldef(n2) }
[ "func", "(", "s", "*", "state", ")", "eval2def", "(", "n1", ",", "n2", "ast", ".", "Node", ")", "(", "data", ".", "Value", ",", "data", ".", "Value", ")", "{", "return", "s", ".", "evaldef", "(", "n1", ")", ",", "s", ".", "evaldef", "(", "n2", ")", "\n", "}" ]
// eval2def is a helper for binary ops. it evaluates the two given nodes and // requires the result of each to not be Undefined.
[ "eval2def", "is", "a", "helper", "for", "binary", "ops", ".", "it", "evaluates", "the", "two", "given", "nodes", "and", "requires", "the", "result", "of", "each", "to", "not", "be", "Undefined", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/soyhtml/exec.go#L654-L656
3,963
robfig/soy
soyhtml/exec.go
htmlEscapeString
func htmlEscapeString(w io.Writer, str string) { last := 0 for i := 0; i < len(str); i++ { var html []byte switch str[i] { case '"': html = htmlQuot case '\'': html = htmlApos case '&': html = htmlAmp case '<': html = htmlLt case '>': html = htmlGt default: continue } io.WriteString(w, str[last:i]) w.Write(html) last = i + 1 } io.WriteString(w, str[last:]) }
go
func htmlEscapeString(w io.Writer, str string) { last := 0 for i := 0; i < len(str); i++ { var html []byte switch str[i] { case '"': html = htmlQuot case '\'': html = htmlApos case '&': html = htmlAmp case '<': html = htmlLt case '>': html = htmlGt default: continue } io.WriteString(w, str[last:i]) w.Write(html) last = i + 1 } io.WriteString(w, str[last:]) }
[ "func", "htmlEscapeString", "(", "w", "io", ".", "Writer", ",", "str", "string", ")", "{", "last", ":=", "0", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "str", ")", ";", "i", "++", "{", "var", "html", "[", "]", "byte", "\n", "switch", "str", "[", "i", "]", "{", "case", "'\"'", ":", "html", "=", "htmlQuot", "\n", "case", "'\\''", ":", "html", "=", "htmlApos", "\n", "case", "'&'", ":", "html", "=", "htmlAmp", "\n", "case", "'<'", ":", "html", "=", "htmlLt", "\n", "case", "'>'", ":", "html", "=", "htmlGt", "\n", "default", ":", "continue", "\n", "}", "\n", "io", ".", "WriteString", "(", "w", ",", "str", "[", "last", ":", "i", "]", ")", "\n", "w", ".", "Write", "(", "html", ")", "\n", "last", "=", "i", "+", "1", "\n", "}", "\n", "io", ".", "WriteString", "(", "w", ",", "str", "[", "last", ":", "]", ")", "\n", "}" ]
// htmlEscapeString is a modified veresion of the stdlib HTMLEscape routine // escapes a string without making copies.
[ "htmlEscapeString", "is", "a", "modified", "veresion", "of", "the", "stdlib", "HTMLEscape", "routine", "escapes", "a", "string", "without", "making", "copies", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/soyhtml/exec.go#L683-L706
3,964
robfig/soy
soyhtml/scope.go
push
func (s *scope) push() { *s = append(*s, scopeframe{make(data.Map), false}) }
go
func (s *scope) push() { *s = append(*s, scopeframe{make(data.Map), false}) }
[ "func", "(", "s", "*", "scope", ")", "push", "(", ")", "{", "*", "s", "=", "append", "(", "*", "s", ",", "scopeframe", "{", "make", "(", "data", ".", "Map", ")", ",", "false", "}", ")", "\n", "}" ]
// push creates a new scope
[ "push", "creates", "a", "new", "scope" ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/soyhtml/scope.go#L21-L23
3,965
robfig/soy
soyhtml/scope.go
set
func (s scope) set(k string, v data.Value) { s[len(s)-1].vars[k] = v }
go
func (s scope) set(k string, v data.Value) { s[len(s)-1].vars[k] = v }
[ "func", "(", "s", "scope", ")", "set", "(", "k", "string", ",", "v", "data", ".", "Value", ")", "{", "s", "[", "len", "(", "s", ")", "-", "1", "]", ".", "vars", "[", "k", "]", "=", "v", "\n", "}" ]
// set adds a new binding to the deepest scope
[ "set", "adds", "a", "new", "binding", "to", "the", "deepest", "scope" ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/soyhtml/scope.go#L31-L33
3,966
robfig/soy
soyhtml/scope.go
lookup
func (s scope) lookup(k string) data.Value { for i := range s { var elem = s[len(s)-i-1].vars if val, ok := elem[k]; ok { return val } } return data.Undefined{} }
go
func (s scope) lookup(k string) data.Value { for i := range s { var elem = s[len(s)-i-1].vars if val, ok := elem[k]; ok { return val } } return data.Undefined{} }
[ "func", "(", "s", "scope", ")", "lookup", "(", "k", "string", ")", "data", ".", "Value", "{", "for", "i", ":=", "range", "s", "{", "var", "elem", "=", "s", "[", "len", "(", "s", ")", "-", "i", "-", "1", "]", ".", "vars", "\n", "if", "val", ",", "ok", ":=", "elem", "[", "k", "]", ";", "ok", "{", "return", "val", "\n", "}", "\n", "}", "\n", "return", "data", ".", "Undefined", "{", "}", "\n", "}" ]
// lookup checks the variable scopes, deepest out, for the given key
[ "lookup", "checks", "the", "variable", "scopes", "deepest", "out", "for", "the", "given", "key" ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/soyhtml/scope.go#L36-L44
3,967
robfig/soy
soyhtml/scope.go
alldata
func (s scope) alldata() scope { for i := range s { var ri = len(s) - i - 1 if s[ri].entered { return s[:ri+1 : ri+1] } } panic("impossible") }
go
func (s scope) alldata() scope { for i := range s { var ri = len(s) - i - 1 if s[ri].entered { return s[:ri+1 : ri+1] } } panic("impossible") }
[ "func", "(", "s", "scope", ")", "alldata", "(", ")", "scope", "{", "for", "i", ":=", "range", "s", "{", "var", "ri", "=", "len", "(", "s", ")", "-", "i", "-", "1", "\n", "if", "s", "[", "ri", "]", ".", "entered", "{", "return", "s", "[", ":", "ri", "+", "1", ":", "ri", "+", "1", "]", "\n", "}", "\n", "}", "\n", "panic", "(", "\"", "\"", ")", "\n", "}" ]
// alldata returns a new scope for use when passing data="all" to a template.
[ "alldata", "returns", "a", "new", "scope", "for", "use", "when", "passing", "data", "=", "all", "to", "a", "template", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/soyhtml/scope.go#L47-L55
3,968
robfig/soy
soyhtml/scope.go
enter
func (s *scope) enter() { (*s)[len(*s)-1].entered = true s.push() }
go
func (s *scope) enter() { (*s)[len(*s)-1].entered = true s.push() }
[ "func", "(", "s", "*", "scope", ")", "enter", "(", ")", "{", "(", "*", "s", ")", "[", "len", "(", "*", "s", ")", "-", "1", "]", ".", "entered", "=", "true", "\n", "s", ".", "push", "(", ")", "\n", "}" ]
// enter records that this is the frame where we enter a template. // only the frames up to here will be passed in the next data="all"
[ "enter", "records", "that", "this", "is", "the", "frame", "where", "we", "enter", "a", "template", ".", "only", "the", "frames", "up", "to", "here", "will", "be", "passed", "in", "the", "next", "data", "=", "all" ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/soyhtml/scope.go#L59-L62
3,969
robfig/soy
parse/lexer.go
String
func (t itemType) String() string { for k, v := range builtinIdents { if v == t { return k } } for k, v := range arithmeticItemsBySymbol { if v == t { return k } } var r, ok = map[itemType]string{ itemEOF: "<eof>", itemEquals: "=", itemError: "<error>", itemText: "<text>", itemLeftDelim: "{", itemRightDelim: "}", itemRightDelimEnd: "/}", itemIdent: "<ident>", itemDollarIdent: "<$ident>", itemDotIdent: "<.ident>", itemQuestionDotIdent: "<?.ident>", itemDotIndex: "<.N>", itemQuestionDotIndex: "<?.N>", itemLeftBracket: "[", itemRightBracket: "]", itemQuestionKey: "?[", }[t] if ok { return r } return fmt.Sprintf("item(%d)", t) }
go
func (t itemType) String() string { for k, v := range builtinIdents { if v == t { return k } } for k, v := range arithmeticItemsBySymbol { if v == t { return k } } var r, ok = map[itemType]string{ itemEOF: "<eof>", itemEquals: "=", itemError: "<error>", itemText: "<text>", itemLeftDelim: "{", itemRightDelim: "}", itemRightDelimEnd: "/}", itemIdent: "<ident>", itemDollarIdent: "<$ident>", itemDotIdent: "<.ident>", itemQuestionDotIdent: "<?.ident>", itemDotIndex: "<.N>", itemQuestionDotIndex: "<?.N>", itemLeftBracket: "[", itemRightBracket: "]", itemQuestionKey: "?[", }[t] if ok { return r } return fmt.Sprintf("item(%d)", t) }
[ "func", "(", "t", "itemType", ")", "String", "(", ")", "string", "{", "for", "k", ",", "v", ":=", "range", "builtinIdents", "{", "if", "v", "==", "t", "{", "return", "k", "\n", "}", "\n", "}", "\n", "for", "k", ",", "v", ":=", "range", "arithmeticItemsBySymbol", "{", "if", "v", "==", "t", "{", "return", "k", "\n", "}", "\n", "}", "\n", "var", "r", ",", "ok", "=", "map", "[", "itemType", "]", "string", "{", "itemEOF", ":", "\"", "\"", ",", "itemEquals", ":", "\"", "\"", ",", "itemError", ":", "\"", "\"", ",", "itemText", ":", "\"", "\"", ",", "itemLeftDelim", ":", "\"", "\"", ",", "itemRightDelim", ":", "\"", "\"", ",", "itemRightDelimEnd", ":", "\"", "\"", ",", "itemIdent", ":", "\"", "\"", ",", "itemDollarIdent", ":", "\"", "\"", ",", "itemDotIdent", ":", "\"", "\"", ",", "itemQuestionDotIdent", ":", "\"", "\"", ",", "itemDotIndex", ":", "\"", "\"", ",", "itemQuestionDotIndex", ":", "\"", "\"", ",", "itemLeftBracket", ":", "\"", "\"", ",", "itemRightBracket", ":", "\"", "\"", ",", "itemQuestionKey", ":", "\"", "\"", ",", "}", "[", "t", "]", "\n", "if", "ok", "{", "return", "r", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "t", ")", "\n", "}" ]
// String converts the itemType into its source string. // It is fantastically inefficient and should only be used for error messages.
[ "String", "converts", "the", "itemType", "into", "its", "source", "string", ".", "It", "is", "fantastically", "inefficient", "and", "should", "only", "be", "used", "for", "error", "messages", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/lexer.go#L253-L286
3,970
robfig/soy
parse/lexer.go
lexExpr
func lexExpr(name, input string) *lexer { l := &lexer{ name: name, input: input, items: make(chan item), state: lexInsideTag, } go l.run() return l }
go
func lexExpr(name, input string) *lexer { l := &lexer{ name: name, input: input, items: make(chan item), state: lexInsideTag, } go l.run() return l }
[ "func", "lexExpr", "(", "name", ",", "input", "string", ")", "*", "lexer", "{", "l", ":=", "&", "lexer", "{", "name", ":", "name", ",", "input", ":", "input", ",", "items", ":", "make", "(", "chan", "item", ")", ",", "state", ":", "lexInsideTag", ",", "}", "\n", "go", "l", ".", "run", "(", ")", "\n", "return", "l", "\n", "}" ]
// lexExpr lexes a single expression.
[ "lexExpr", "lexes", "a", "single", "expression", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/lexer.go#L342-L351
3,971
robfig/soy
parse/lexer.go
lineNumber
func (l *lexer) lineNumber(pos ast.Pos) int { return 1 + strings.Count(l.input[:pos], "\n") }
go
func (l *lexer) lineNumber(pos ast.Pos) int { return 1 + strings.Count(l.input[:pos], "\n") }
[ "func", "(", "l", "*", "lexer", ")", "lineNumber", "(", "pos", "ast", ".", "Pos", ")", "int", "{", "return", "1", "+", "strings", ".", "Count", "(", "l", ".", "input", "[", ":", "pos", "]", ",", "\"", "\\n", "\"", ")", "\n", "}" ]
// lineNumber reports which line we're on. Doing it this way // means we don't have to worry about peek double counting.
[ "lineNumber", "reports", "which", "line", "we", "re", "on", ".", "Doing", "it", "this", "way", "means", "we", "don", "t", "have", "to", "worry", "about", "peek", "double", "counting", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/lexer.go#L419-L421
3,972
robfig/soy
parse/lexer.go
columnNumber
func (l *lexer) columnNumber(pos ast.Pos) int { n := strings.LastIndex(l.input[:pos], "\n") if n == -1 { n = 0 } return int(pos) - n }
go
func (l *lexer) columnNumber(pos ast.Pos) int { n := strings.LastIndex(l.input[:pos], "\n") if n == -1 { n = 0 } return int(pos) - n }
[ "func", "(", "l", "*", "lexer", ")", "columnNumber", "(", "pos", "ast", ".", "Pos", ")", "int", "{", "n", ":=", "strings", ".", "LastIndex", "(", "l", ".", "input", "[", ":", "pos", "]", ",", "\"", "\\n", "\"", ")", "\n", "if", "n", "==", "-", "1", "{", "n", "=", "0", "\n", "}", "\n", "return", "int", "(", "pos", ")", "-", "n", "\n", "}" ]
// columnNumber reports which column in the current line we're on.
[ "columnNumber", "reports", "which", "column", "in", "the", "current", "line", "we", "re", "on", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/lexer.go#L424-L430
3,973
robfig/soy
parse/lexer.go
lexLeftDelim
func lexLeftDelim(l *lexer) stateFn { l.next() // read the first { // check the next character to see if it's a double delimiter if r := l.next(); r == '{' { l.doubleDelim = true } else { l.backup() l.doubleDelim = false } l.emit(itemLeftDelim) return lexBeginTag }
go
func lexLeftDelim(l *lexer) stateFn { l.next() // read the first { // check the next character to see if it's a double delimiter if r := l.next(); r == '{' { l.doubleDelim = true } else { l.backup() l.doubleDelim = false } l.emit(itemLeftDelim) return lexBeginTag }
[ "func", "lexLeftDelim", "(", "l", "*", "lexer", ")", "stateFn", "{", "l", ".", "next", "(", ")", "// read the first {", "\n", "// check the next character to see if it's a double delimiter", "if", "r", ":=", "l", ".", "next", "(", ")", ";", "r", "==", "'{'", "{", "l", ".", "doubleDelim", "=", "true", "\n", "}", "else", "{", "l", ".", "backup", "(", ")", "\n", "l", ".", "doubleDelim", "=", "false", "\n", "}", "\n", "l", ".", "emit", "(", "itemLeftDelim", ")", "\n", "return", "lexBeginTag", "\n", "}" ]
// lexLeftDelim scans the left template tag delimiter // // If there are brace characters within a template tag, double braces must // be used, so we differentiate them to match double closing braces later. // Double braces are also optional for other cases.
[ "lexLeftDelim", "scans", "the", "left", "template", "tag", "delimiter", "If", "there", "are", "brace", "characters", "within", "a", "template", "tag", "double", "braces", "must", "be", "used", "so", "we", "differentiate", "them", "to", "match", "double", "closing", "braces", "later", ".", "Double", "braces", "are", "also", "optional", "for", "other", "cases", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/lexer.go#L511-L522
3,974
robfig/soy
parse/lexer.go
lexRightDelim
func lexRightDelim(l *lexer) stateFn { if l.doubleDelim && l.next() != '}' { return l.errorf("expected double closing braces in tag") } l.emit(itemRightDelim) return lexText }
go
func lexRightDelim(l *lexer) stateFn { if l.doubleDelim && l.next() != '}' { return l.errorf("expected double closing braces in tag") } l.emit(itemRightDelim) return lexText }
[ "func", "lexRightDelim", "(", "l", "*", "lexer", ")", "stateFn", "{", "if", "l", ".", "doubleDelim", "&&", "l", ".", "next", "(", ")", "!=", "'}'", "{", "return", "l", ".", "errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "l", ".", "emit", "(", "itemRightDelim", ")", "\n", "return", "lexText", "\n", "}" ]
// lexRightDelim scans the right template tag delimiter // } has already been read.
[ "lexRightDelim", "scans", "the", "right", "template", "tag", "delimiter", "}", "has", "already", "been", "read", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/lexer.go#L526-L532
3,975
robfig/soy
parse/lexer.go
lexInsideTag
func lexInsideTag(l *lexer) stateFn { switch r := l.next(); { case isSpaceEOL(r): l.ignore() case r == '/' && l.peek() == '}': return lexRightDelimEnd case r == '$', r == '.': l.backup() return lexIdent case r == '[': l.emit(itemLeftBracket) case r == ']': l.emit(itemRightBracket) case r == '?': // used by data refs and arithmetic switch l.next() { case '.': l.pos -= 2 return lexIdent case '[': l.emit(itemQuestionKey) case ':': l.emit(itemElvis) default: l.backup() l.emit(itemTernIf) } case r == '-': return lexNegative(l) case r == '}': return lexRightDelim case r >= '0' && r <= '9': l.backup() return lexNumber case r == '*', r == '/', r == '%', r == '+', r == ':', r == '(', r == ')': // the single-character symbols l.emit(arithmeticItemsBySymbol[string(r)]) case r == '>', r == '!', r == '<', r == '=' && l.peek() == '=': // 1 or 2 character symbols l.accept("*/%+-=!<>|&?:") sym := l.input[l.start:l.pos] item, ok := arithmeticItemsBySymbol[sym] if !ok { return l.errorf("unexpected symbol: %s", sym) } l.emit(item) case r == '"', r == '\'': return stringLexer(r) case r == '=': l.emit(itemEquals) case r == eof: return l.errorf("unclosed tag") case r == '|': l.emit(itemPipe) case isLetterOrUnderscore(r): l.backup() return lexIdent case r == ',': l.emit(itemComma) default: return l.errorf("unrecognized character in action: %#U", r) } return lexInsideTag }
go
func lexInsideTag(l *lexer) stateFn { switch r := l.next(); { case isSpaceEOL(r): l.ignore() case r == '/' && l.peek() == '}': return lexRightDelimEnd case r == '$', r == '.': l.backup() return lexIdent case r == '[': l.emit(itemLeftBracket) case r == ']': l.emit(itemRightBracket) case r == '?': // used by data refs and arithmetic switch l.next() { case '.': l.pos -= 2 return lexIdent case '[': l.emit(itemQuestionKey) case ':': l.emit(itemElvis) default: l.backup() l.emit(itemTernIf) } case r == '-': return lexNegative(l) case r == '}': return lexRightDelim case r >= '0' && r <= '9': l.backup() return lexNumber case r == '*', r == '/', r == '%', r == '+', r == ':', r == '(', r == ')': // the single-character symbols l.emit(arithmeticItemsBySymbol[string(r)]) case r == '>', r == '!', r == '<', r == '=' && l.peek() == '=': // 1 or 2 character symbols l.accept("*/%+-=!<>|&?:") sym := l.input[l.start:l.pos] item, ok := arithmeticItemsBySymbol[sym] if !ok { return l.errorf("unexpected symbol: %s", sym) } l.emit(item) case r == '"', r == '\'': return stringLexer(r) case r == '=': l.emit(itemEquals) case r == eof: return l.errorf("unclosed tag") case r == '|': l.emit(itemPipe) case isLetterOrUnderscore(r): l.backup() return lexIdent case r == ',': l.emit(itemComma) default: return l.errorf("unrecognized character in action: %#U", r) } return lexInsideTag }
[ "func", "lexInsideTag", "(", "l", "*", "lexer", ")", "stateFn", "{", "switch", "r", ":=", "l", ".", "next", "(", ")", ";", "{", "case", "isSpaceEOL", "(", "r", ")", ":", "l", ".", "ignore", "(", ")", "\n", "case", "r", "==", "'/'", "&&", "l", ".", "peek", "(", ")", "==", "'}'", ":", "return", "lexRightDelimEnd", "\n", "case", "r", "==", "'$'", ",", "r", "==", "'.'", ":", "l", ".", "backup", "(", ")", "\n", "return", "lexIdent", "\n", "case", "r", "==", "'['", ":", "l", ".", "emit", "(", "itemLeftBracket", ")", "\n", "case", "r", "==", "']'", ":", "l", ".", "emit", "(", "itemRightBracket", ")", "\n", "case", "r", "==", "'?'", ":", "// used by data refs and arithmetic", "switch", "l", ".", "next", "(", ")", "{", "case", "'.'", ":", "l", ".", "pos", "-=", "2", "\n", "return", "lexIdent", "\n", "case", "'['", ":", "l", ".", "emit", "(", "itemQuestionKey", ")", "\n", "case", "':'", ":", "l", ".", "emit", "(", "itemElvis", ")", "\n", "default", ":", "l", ".", "backup", "(", ")", "\n", "l", ".", "emit", "(", "itemTernIf", ")", "\n", "}", "\n", "case", "r", "==", "'-'", ":", "return", "lexNegative", "(", "l", ")", "\n", "case", "r", "==", "'}'", ":", "return", "lexRightDelim", "\n", "case", "r", ">=", "'0'", "&&", "r", "<=", "'9'", ":", "l", ".", "backup", "(", ")", "\n", "return", "lexNumber", "\n", "case", "r", "==", "'*'", ",", "r", "==", "'/'", ",", "r", "==", "'%'", ",", "r", "==", "'+'", ",", "r", "==", "':'", ",", "r", "==", "'('", ",", "r", "==", "')'", ":", "// the single-character symbols", "l", ".", "emit", "(", "arithmeticItemsBySymbol", "[", "string", "(", "r", ")", "]", ")", "\n", "case", "r", "==", "'>'", ",", "r", "==", "'!'", ",", "r", "==", "'<'", ",", "r", "==", "'='", "&&", "l", ".", "peek", "(", ")", "==", "'='", ":", "// 1 or 2 character symbols", "l", ".", "accept", "(", "\"", "\"", ")", "\n", "sym", ":=", "l", ".", "input", "[", "l", ".", "start", ":", "l", ".", "pos", "]", "\n", "item", ",", "ok", ":=", "arithmeticItemsBySymbol", "[", "sym", "]", "\n", "if", "!", "ok", "{", "return", "l", ".", "errorf", "(", "\"", "\"", ",", "sym", ")", "\n", "}", "\n", "l", ".", "emit", "(", "item", ")", "\n", "case", "r", "==", "'\"'", ",", "r", "==", "'\\''", ":", "return", "stringLexer", "(", "r", ")", "\n", "case", "r", "==", "'='", ":", "l", ".", "emit", "(", "itemEquals", ")", "\n", "case", "r", "==", "eof", ":", "return", "l", ".", "errorf", "(", "\"", "\"", ")", "\n", "case", "r", "==", "'|'", ":", "l", ".", "emit", "(", "itemPipe", ")", "\n", "case", "isLetterOrUnderscore", "(", "r", ")", ":", "l", ".", "backup", "(", ")", "\n", "return", "lexIdent", "\n", "case", "r", "==", "','", ":", "l", ".", "emit", "(", "itemComma", ")", "\n", "default", ":", "return", "l", ".", "errorf", "(", "\"", "\"", ",", "r", ")", "\n", "}", "\n\n", "return", "lexInsideTag", "\n", "}" ]
// lexInsideTag is called repeatedly to scan elements inside a template tag. // itemLeftDelim has just been emitted.
[ "lexInsideTag", "is", "called", "repeatedly", "to", "scan", "elements", "inside", "a", "template", "tag", ".", "itemLeftDelim", "has", "just", "been", "emitted", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/lexer.go#L557-L620
3,976
robfig/soy
parse/lexer.go
stringLexer
func stringLexer(quoteChar rune) stateFn { // the quote char has already been read. return func(l *lexer) stateFn { for { switch l.next() { case eof: l.errorf("unexpected eof while scanning string") case '\\': l.next() // skip escape sequences case quoteChar: l.emit(itemString) return lexInsideTag } } } }
go
func stringLexer(quoteChar rune) stateFn { // the quote char has already been read. return func(l *lexer) stateFn { for { switch l.next() { case eof: l.errorf("unexpected eof while scanning string") case '\\': l.next() // skip escape sequences case quoteChar: l.emit(itemString) return lexInsideTag } } } }
[ "func", "stringLexer", "(", "quoteChar", "rune", ")", "stateFn", "{", "// the quote char has already been read.", "return", "func", "(", "l", "*", "lexer", ")", "stateFn", "{", "for", "{", "switch", "l", ".", "next", "(", ")", "{", "case", "eof", ":", "l", ".", "errorf", "(", "\"", "\"", ")", "\n", "case", "'\\\\'", ":", "l", ".", "next", "(", ")", "// skip escape sequences", "\n", "case", "quoteChar", ":", "l", ".", "emit", "(", "itemString", ")", "\n", "return", "lexInsideTag", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// stringLexer returns a stateFn that lexes strings surrounded by the given quote character.
[ "stringLexer", "returns", "a", "stateFn", "that", "lexes", "strings", "surrounded", "by", "the", "given", "quote", "character", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/lexer.go#L763-L778
3,977
robfig/soy
parse/lexer.go
lexIdent
func lexIdent(l *lexer) stateFn { // the different idents start with different unique characters. // peel those off. var itemType = itemIdent switch l.next() { case '.': if isDigit(l.next()) { itemType = itemDotIndex } else { itemType = itemDotIdent } l.backup() case '$': itemType = itemDollarIdent case '/': itemType = itemCommandEnd case '\\': itemType = itemSpecialChar case '?': dot := l.next() if dot != '.' { l.errorf("unexpected beginning to ident: ?%v", dot) } if isDigit(l.next()) { itemType = itemQuestionDotIndex } else { itemType = itemQuestionDotIdent } l.backup() } // absorb the rest of the identifier for isAlphaNumeric(l.next()) { } l.backup() word := l.input[l.start:l.pos] // if it's a builtin, return that item type if itemType, ok := builtinIdents[word]; ok { l.emit(itemType) // {literal} and {css} have unusual lexing rules switch itemType { case itemLiteral: return lexLiteral case itemCss: return lexCss } return lexInsideTag } // if not a builtin, it shouldn't start with / or \ if itemType == itemCommandEnd || itemType == itemSpecialChar { var str = l.input[l.start:l.pos] l.pos = l.start return l.errorf("unrecognized identifier %q", str) } // else, use the type determined at the beginning. l.emit(itemType) return lexInsideTag }
go
func lexIdent(l *lexer) stateFn { // the different idents start with different unique characters. // peel those off. var itemType = itemIdent switch l.next() { case '.': if isDigit(l.next()) { itemType = itemDotIndex } else { itemType = itemDotIdent } l.backup() case '$': itemType = itemDollarIdent case '/': itemType = itemCommandEnd case '\\': itemType = itemSpecialChar case '?': dot := l.next() if dot != '.' { l.errorf("unexpected beginning to ident: ?%v", dot) } if isDigit(l.next()) { itemType = itemQuestionDotIndex } else { itemType = itemQuestionDotIdent } l.backup() } // absorb the rest of the identifier for isAlphaNumeric(l.next()) { } l.backup() word := l.input[l.start:l.pos] // if it's a builtin, return that item type if itemType, ok := builtinIdents[word]; ok { l.emit(itemType) // {literal} and {css} have unusual lexing rules switch itemType { case itemLiteral: return lexLiteral case itemCss: return lexCss } return lexInsideTag } // if not a builtin, it shouldn't start with / or \ if itemType == itemCommandEnd || itemType == itemSpecialChar { var str = l.input[l.start:l.pos] l.pos = l.start return l.errorf("unrecognized identifier %q", str) } // else, use the type determined at the beginning. l.emit(itemType) return lexInsideTag }
[ "func", "lexIdent", "(", "l", "*", "lexer", ")", "stateFn", "{", "// the different idents start with different unique characters.", "// peel those off.", "var", "itemType", "=", "itemIdent", "\n", "switch", "l", ".", "next", "(", ")", "{", "case", "'.'", ":", "if", "isDigit", "(", "l", ".", "next", "(", ")", ")", "{", "itemType", "=", "itemDotIndex", "\n", "}", "else", "{", "itemType", "=", "itemDotIdent", "\n", "}", "\n", "l", ".", "backup", "(", ")", "\n", "case", "'$'", ":", "itemType", "=", "itemDollarIdent", "\n", "case", "'/'", ":", "itemType", "=", "itemCommandEnd", "\n", "case", "'\\\\'", ":", "itemType", "=", "itemSpecialChar", "\n", "case", "'?'", ":", "dot", ":=", "l", ".", "next", "(", ")", "\n", "if", "dot", "!=", "'.'", "{", "l", ".", "errorf", "(", "\"", "\"", ",", "dot", ")", "\n", "}", "\n", "if", "isDigit", "(", "l", ".", "next", "(", ")", ")", "{", "itemType", "=", "itemQuestionDotIndex", "\n", "}", "else", "{", "itemType", "=", "itemQuestionDotIdent", "\n", "}", "\n", "l", ".", "backup", "(", ")", "\n", "}", "\n\n", "// absorb the rest of the identifier", "for", "isAlphaNumeric", "(", "l", ".", "next", "(", ")", ")", "{", "}", "\n", "l", ".", "backup", "(", ")", "\n", "word", ":=", "l", ".", "input", "[", "l", ".", "start", ":", "l", ".", "pos", "]", "\n\n", "// if it's a builtin, return that item type", "if", "itemType", ",", "ok", ":=", "builtinIdents", "[", "word", "]", ";", "ok", "{", "l", ".", "emit", "(", "itemType", ")", "\n", "// {literal} and {css} have unusual lexing rules", "switch", "itemType", "{", "case", "itemLiteral", ":", "return", "lexLiteral", "\n", "case", "itemCss", ":", "return", "lexCss", "\n", "}", "\n", "return", "lexInsideTag", "\n", "}", "\n", "// if not a builtin, it shouldn't start with / or \\", "if", "itemType", "==", "itemCommandEnd", "||", "itemType", "==", "itemSpecialChar", "{", "var", "str", "=", "l", ".", "input", "[", "l", ".", "start", ":", "l", ".", "pos", "]", "\n", "l", ".", "pos", "=", "l", ".", "start", "\n", "return", "l", ".", "errorf", "(", "\"", "\"", ",", "str", ")", "\n", "}", "\n\n", "// else, use the type determined at the beginning.", "l", ".", "emit", "(", "itemType", ")", "\n", "return", "lexInsideTag", "\n", "}" ]
// lexIdent recognizes the various kinds of identifiers
[ "lexIdent", "recognizes", "the", "various", "kinds", "of", "identifiers" ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/lexer.go#L781-L840
3,978
robfig/soy
parse/lexer.go
allSpaceWithNewline
func allSpaceWithNewline(str string) bool { var seenNewline = false for _, ch := range str { if !unicode.IsSpace(ch) { return false } if isEndOfLine(ch) { seenNewline = true } } return seenNewline }
go
func allSpaceWithNewline(str string) bool { var seenNewline = false for _, ch := range str { if !unicode.IsSpace(ch) { return false } if isEndOfLine(ch) { seenNewline = true } } return seenNewline }
[ "func", "allSpaceWithNewline", "(", "str", "string", ")", "bool", "{", "var", "seenNewline", "=", "false", "\n", "for", "_", ",", "ch", ":=", "range", "str", "{", "if", "!", "unicode", ".", "IsSpace", "(", "ch", ")", "{", "return", "false", "\n", "}", "\n", "if", "isEndOfLine", "(", "ch", ")", "{", "seenNewline", "=", "true", "\n", "}", "\n", "}", "\n", "return", "seenNewline", "\n", "}" ]
// allSpaceWithNewline returns true if the entire string consists of whitespace, // with at least one newline.
[ "allSpaceWithNewline", "returns", "true", "if", "the", "entire", "string", "consists", "of", "whitespace", "with", "at", "least", "one", "newline", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/lexer.go#L1024-L1035
3,979
robfig/soy
parse/parse.go
textOrTag
func (t *tree) textOrTag(token item, until []itemType) (node ast.Node, halt bool) { var seenComment = token.typ == itemComment for token.typ == itemComment { token = t.next() // skip any comments } // Two ways to end a list: // 1. We found the until token (e.g. EOF) if isOneOf(token.typ, until) { return nil, true } // 2. The until token is a command, e.g. {else} {/template} var token2 = t.next() if token.typ == itemLeftDelim && isOneOf(token2.typ, until) { return nil, true } t.backup() switch token.typ { case itemText: var text = token.val var next item for { next = t.next() if next.typ != itemText { break } text += next.val } t.backup() var textvalue = rawtext(text, seenComment, next.typ == itemComment) if len(textvalue) == 0 { return nil, false } return &ast.RawTextNode{token.pos, textvalue}, false case itemLeftDelim: return t.beginTag(), false case itemSoyDocStart: return t.parseSoyDoc(token), false default: t.unexpected(token, "input") } return nil, false }
go
func (t *tree) textOrTag(token item, until []itemType) (node ast.Node, halt bool) { var seenComment = token.typ == itemComment for token.typ == itemComment { token = t.next() // skip any comments } // Two ways to end a list: // 1. We found the until token (e.g. EOF) if isOneOf(token.typ, until) { return nil, true } // 2. The until token is a command, e.g. {else} {/template} var token2 = t.next() if token.typ == itemLeftDelim && isOneOf(token2.typ, until) { return nil, true } t.backup() switch token.typ { case itemText: var text = token.val var next item for { next = t.next() if next.typ != itemText { break } text += next.val } t.backup() var textvalue = rawtext(text, seenComment, next.typ == itemComment) if len(textvalue) == 0 { return nil, false } return &ast.RawTextNode{token.pos, textvalue}, false case itemLeftDelim: return t.beginTag(), false case itemSoyDocStart: return t.parseSoyDoc(token), false default: t.unexpected(token, "input") } return nil, false }
[ "func", "(", "t", "*", "tree", ")", "textOrTag", "(", "token", "item", ",", "until", "[", "]", "itemType", ")", "(", "node", "ast", ".", "Node", ",", "halt", "bool", ")", "{", "var", "seenComment", "=", "token", ".", "typ", "==", "itemComment", "\n", "for", "token", ".", "typ", "==", "itemComment", "{", "token", "=", "t", ".", "next", "(", ")", "// skip any comments", "\n", "}", "\n\n", "// Two ways to end a list:", "// 1. We found the until token (e.g. EOF)", "if", "isOneOf", "(", "token", ".", "typ", ",", "until", ")", "{", "return", "nil", ",", "true", "\n", "}", "\n\n", "// 2. The until token is a command, e.g. {else} {/template}", "var", "token2", "=", "t", ".", "next", "(", ")", "\n", "if", "token", ".", "typ", "==", "itemLeftDelim", "&&", "isOneOf", "(", "token2", ".", "typ", ",", "until", ")", "{", "return", "nil", ",", "true", "\n", "}", "\n\n", "t", ".", "backup", "(", ")", "\n", "switch", "token", ".", "typ", "{", "case", "itemText", ":", "var", "text", "=", "token", ".", "val", "\n", "var", "next", "item", "\n", "for", "{", "next", "=", "t", ".", "next", "(", ")", "\n", "if", "next", ".", "typ", "!=", "itemText", "{", "break", "\n", "}", "\n", "text", "+=", "next", ".", "val", "\n", "}", "\n", "t", ".", "backup", "(", ")", "\n", "var", "textvalue", "=", "rawtext", "(", "text", ",", "seenComment", ",", "next", ".", "typ", "==", "itemComment", ")", "\n", "if", "len", "(", "textvalue", ")", "==", "0", "{", "return", "nil", ",", "false", "\n", "}", "\n", "return", "&", "ast", ".", "RawTextNode", "{", "token", ".", "pos", ",", "textvalue", "}", ",", "false", "\n", "case", "itemLeftDelim", ":", "return", "t", ".", "beginTag", "(", ")", ",", "false", "\n", "case", "itemSoyDocStart", ":", "return", "t", ".", "parseSoyDoc", "(", "token", ")", ",", "false", "\n", "default", ":", "t", ".", "unexpected", "(", "token", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "nil", ",", "false", "\n", "}" ]
// textOrTag reads raw text or recognizes the start of tags until the end tag.
[ "textOrTag", "reads", "raw", "text", "or", "recognizes", "the", "start", "of", "tags", "until", "the", "end", "tag", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/parse.go#L71-L115
3,980
robfig/soy
parse/parse.go
parseLet
func (t *tree) parseLet(token item) ast.Node { var name = t.expect(itemDollarIdent, "let") if t.peek().typ == itemColon { t.next() var node = &ast.LetValueNode{token.pos, name.val[1:], t.parseExpr(0)} t.expect(itemRightDelimEnd, "let") return node } t.parseAttrs("kind") switch next := t.next(); next.typ { case itemRightDelim: var node = &ast.LetContentNode{token.pos, name.val[1:], t.itemList(itemLetEnd)} t.expect(itemRightDelim, "let") return node default: t.unexpected(next, "{let}") } panic("unreachable") }
go
func (t *tree) parseLet(token item) ast.Node { var name = t.expect(itemDollarIdent, "let") if t.peek().typ == itemColon { t.next() var node = &ast.LetValueNode{token.pos, name.val[1:], t.parseExpr(0)} t.expect(itemRightDelimEnd, "let") return node } t.parseAttrs("kind") switch next := t.next(); next.typ { case itemRightDelim: var node = &ast.LetContentNode{token.pos, name.val[1:], t.itemList(itemLetEnd)} t.expect(itemRightDelim, "let") return node default: t.unexpected(next, "{let}") } panic("unreachable") }
[ "func", "(", "t", "*", "tree", ")", "parseLet", "(", "token", "item", ")", "ast", ".", "Node", "{", "var", "name", "=", "t", ".", "expect", "(", "itemDollarIdent", ",", "\"", "\"", ")", "\n", "if", "t", ".", "peek", "(", ")", ".", "typ", "==", "itemColon", "{", "t", ".", "next", "(", ")", "\n", "var", "node", "=", "&", "ast", ".", "LetValueNode", "{", "token", ".", "pos", ",", "name", ".", "val", "[", "1", ":", "]", ",", "t", ".", "parseExpr", "(", "0", ")", "}", "\n", "t", ".", "expect", "(", "itemRightDelimEnd", ",", "\"", "\"", ")", "\n", "return", "node", "\n", "}", "\n", "t", ".", "parseAttrs", "(", "\"", "\"", ")", "\n", "switch", "next", ":=", "t", ".", "next", "(", ")", ";", "next", ".", "typ", "{", "case", "itemRightDelim", ":", "var", "node", "=", "&", "ast", ".", "LetContentNode", "{", "token", ".", "pos", ",", "name", ".", "val", "[", "1", ":", "]", ",", "t", ".", "itemList", "(", "itemLetEnd", ")", "}", "\n", "t", ".", "expect", "(", "itemRightDelim", ",", "\"", "\"", ")", "\n", "return", "node", "\n", "default", ":", "t", ".", "unexpected", "(", "next", ",", "\"", "\"", ")", "\n", "}", "\n", "panic", "(", "\"", "\"", ")", "\n", "}" ]
// "let" has just been read.
[ "let", "has", "just", "been", "read", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/parse.go#L240-L258
3,981
robfig/soy
parse/parse.go
parseCss
func (t *tree) parseCss(token item) ast.Node { var cmdText = t.expect(itemText, "css") t.expect(itemRightDelim, "css") var lastComma = strings.LastIndex(cmdText.val, ",") if lastComma == -1 { return &ast.CssNode{token.pos, nil, strings.TrimSpace(cmdText.val)} } var exprText = strings.TrimSpace(cmdText.val[:lastComma]) return &ast.CssNode{ token.pos, t.parseQuotedExpr(exprText), strings.TrimSpace(cmdText.val[lastComma+1:]), } }
go
func (t *tree) parseCss(token item) ast.Node { var cmdText = t.expect(itemText, "css") t.expect(itemRightDelim, "css") var lastComma = strings.LastIndex(cmdText.val, ",") if lastComma == -1 { return &ast.CssNode{token.pos, nil, strings.TrimSpace(cmdText.val)} } var exprText = strings.TrimSpace(cmdText.val[:lastComma]) return &ast.CssNode{ token.pos, t.parseQuotedExpr(exprText), strings.TrimSpace(cmdText.val[lastComma+1:]), } }
[ "func", "(", "t", "*", "tree", ")", "parseCss", "(", "token", "item", ")", "ast", ".", "Node", "{", "var", "cmdText", "=", "t", ".", "expect", "(", "itemText", ",", "\"", "\"", ")", "\n", "t", ".", "expect", "(", "itemRightDelim", ",", "\"", "\"", ")", "\n", "var", "lastComma", "=", "strings", ".", "LastIndex", "(", "cmdText", ".", "val", ",", "\"", "\"", ")", "\n", "if", "lastComma", "==", "-", "1", "{", "return", "&", "ast", ".", "CssNode", "{", "token", ".", "pos", ",", "nil", ",", "strings", ".", "TrimSpace", "(", "cmdText", ".", "val", ")", "}", "\n", "}", "\n", "var", "exprText", "=", "strings", ".", "TrimSpace", "(", "cmdText", ".", "val", "[", ":", "lastComma", "]", ")", "\n", "return", "&", "ast", ".", "CssNode", "{", "token", ".", "pos", ",", "t", ".", "parseQuotedExpr", "(", "exprText", ")", ",", "strings", ".", "TrimSpace", "(", "cmdText", ".", "val", "[", "lastComma", "+", "1", ":", "]", ")", ",", "}", "\n", "}" ]
// "css" has just been read.
[ "css", "has", "just", "been", "read", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/parse.go#L261-L274
3,982
robfig/soy
parse/parse.go
parseCall
func (t *tree) parseCall(token item) ast.Node { var templateName string switch tok := t.next(); tok.typ { case itemDotIdent: templateName = tok.val case itemIdent: // this ident could either be {call fully.qualified.name} or attributes. switch tok2 := t.next(); tok2.typ { case itemDotIdent: templateName = tok.val + tok2.val for tokn := t.next(); tokn.typ == itemDotIdent; tokn = t.next() { templateName += tokn.val } t.backup() default: t.backup2(tok) } default: t.backup() } attrs := t.parseAttrs("name", "data") if templateName == "" { templateName = attrs["name"] } if templateName == "" { t.errorf("call: template name not found") } // If it's not a fully qualified template name, apply the namespace or aliases if templateName[0] == '.' { templateName = t.namespace + templateName } else if dot := strings.Index(templateName, "."); dot != -1 { if alias, ok := t.aliases[templateName[:dot]]; ok { templateName = alias + templateName[dot:] } } var allData = false var dataNode ast.Node = nil if data, ok := attrs["data"]; ok { if data == "all" { allData = true } else { dataNode = t.parseQuotedExpr(data) } } switch tok := t.next(); tok.typ { case itemRightDelimEnd: return &ast.CallNode{token.pos, templateName, allData, dataNode, nil} case itemRightDelim: body := t.parseCallParams() t.expect(itemLeftDelim, "call") t.expect(itemCallEnd, "call") t.expect(itemRightDelim, "call") return &ast.CallNode{token.pos, templateName, allData, dataNode, body} default: t.unexpected(tok, "error scanning {call}") } panic("unreachable") }
go
func (t *tree) parseCall(token item) ast.Node { var templateName string switch tok := t.next(); tok.typ { case itemDotIdent: templateName = tok.val case itemIdent: // this ident could either be {call fully.qualified.name} or attributes. switch tok2 := t.next(); tok2.typ { case itemDotIdent: templateName = tok.val + tok2.val for tokn := t.next(); tokn.typ == itemDotIdent; tokn = t.next() { templateName += tokn.val } t.backup() default: t.backup2(tok) } default: t.backup() } attrs := t.parseAttrs("name", "data") if templateName == "" { templateName = attrs["name"] } if templateName == "" { t.errorf("call: template name not found") } // If it's not a fully qualified template name, apply the namespace or aliases if templateName[0] == '.' { templateName = t.namespace + templateName } else if dot := strings.Index(templateName, "."); dot != -1 { if alias, ok := t.aliases[templateName[:dot]]; ok { templateName = alias + templateName[dot:] } } var allData = false var dataNode ast.Node = nil if data, ok := attrs["data"]; ok { if data == "all" { allData = true } else { dataNode = t.parseQuotedExpr(data) } } switch tok := t.next(); tok.typ { case itemRightDelimEnd: return &ast.CallNode{token.pos, templateName, allData, dataNode, nil} case itemRightDelim: body := t.parseCallParams() t.expect(itemLeftDelim, "call") t.expect(itemCallEnd, "call") t.expect(itemRightDelim, "call") return &ast.CallNode{token.pos, templateName, allData, dataNode, body} default: t.unexpected(tok, "error scanning {call}") } panic("unreachable") }
[ "func", "(", "t", "*", "tree", ")", "parseCall", "(", "token", "item", ")", "ast", ".", "Node", "{", "var", "templateName", "string", "\n", "switch", "tok", ":=", "t", ".", "next", "(", ")", ";", "tok", ".", "typ", "{", "case", "itemDotIdent", ":", "templateName", "=", "tok", ".", "val", "\n", "case", "itemIdent", ":", "// this ident could either be {call fully.qualified.name} or attributes.", "switch", "tok2", ":=", "t", ".", "next", "(", ")", ";", "tok2", ".", "typ", "{", "case", "itemDotIdent", ":", "templateName", "=", "tok", ".", "val", "+", "tok2", ".", "val", "\n", "for", "tokn", ":=", "t", ".", "next", "(", ")", ";", "tokn", ".", "typ", "==", "itemDotIdent", ";", "tokn", "=", "t", ".", "next", "(", ")", "{", "templateName", "+=", "tokn", ".", "val", "\n", "}", "\n", "t", ".", "backup", "(", ")", "\n", "default", ":", "t", ".", "backup2", "(", "tok", ")", "\n", "}", "\n", "default", ":", "t", ".", "backup", "(", ")", "\n", "}", "\n", "attrs", ":=", "t", ".", "parseAttrs", "(", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "if", "templateName", "==", "\"", "\"", "{", "templateName", "=", "attrs", "[", "\"", "\"", "]", "\n", "}", "\n", "if", "templateName", "==", "\"", "\"", "{", "t", ".", "errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// If it's not a fully qualified template name, apply the namespace or aliases", "if", "templateName", "[", "0", "]", "==", "'.'", "{", "templateName", "=", "t", ".", "namespace", "+", "templateName", "\n", "}", "else", "if", "dot", ":=", "strings", ".", "Index", "(", "templateName", ",", "\"", "\"", ")", ";", "dot", "!=", "-", "1", "{", "if", "alias", ",", "ok", ":=", "t", ".", "aliases", "[", "templateName", "[", ":", "dot", "]", "]", ";", "ok", "{", "templateName", "=", "alias", "+", "templateName", "[", "dot", ":", "]", "\n", "}", "\n", "}", "\n\n", "var", "allData", "=", "false", "\n", "var", "dataNode", "ast", ".", "Node", "=", "nil", "\n", "if", "data", ",", "ok", ":=", "attrs", "[", "\"", "\"", "]", ";", "ok", "{", "if", "data", "==", "\"", "\"", "{", "allData", "=", "true", "\n", "}", "else", "{", "dataNode", "=", "t", ".", "parseQuotedExpr", "(", "data", ")", "\n", "}", "\n", "}", "\n\n", "switch", "tok", ":=", "t", ".", "next", "(", ")", ";", "tok", ".", "typ", "{", "case", "itemRightDelimEnd", ":", "return", "&", "ast", ".", "CallNode", "{", "token", ".", "pos", ",", "templateName", ",", "allData", ",", "dataNode", ",", "nil", "}", "\n", "case", "itemRightDelim", ":", "body", ":=", "t", ".", "parseCallParams", "(", ")", "\n", "t", ".", "expect", "(", "itemLeftDelim", ",", "\"", "\"", ")", "\n", "t", ".", "expect", "(", "itemCallEnd", ",", "\"", "\"", ")", "\n", "t", ".", "expect", "(", "itemRightDelim", ",", "\"", "\"", ")", "\n", "return", "&", "ast", ".", "CallNode", "{", "token", ".", "pos", ",", "templateName", ",", "allData", ",", "dataNode", ",", "body", "}", "\n", "default", ":", "t", ".", "unexpected", "(", "tok", ",", "\"", "\"", ")", "\n", "}", "\n", "panic", "(", "\"", "\"", ")", "\n", "}" ]
// "call" has just been read.
[ "call", "has", "just", "been", "read", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/parse.go#L277-L338
3,983
robfig/soy
parse/parse.go
parseSwitch
func (t *tree) parseSwitch(token item, end itemType) ast.Node { const ctx = "switch" var switchValue = t.parseExpr(0) t.expect(itemRightDelim, ctx) var cases []*ast.SwitchCaseNode for { switch tok := t.next(); tok.typ { case itemLeftDelim: case itemText: // ignore spaces between tags. text is an error though. if allSpace(tok.val) { continue } t.unexpected(tok, "between switch cases") case itemCase, itemDefault: cases = append(cases, t.parseCase(tok)) case end: t.expect(itemRightDelim, ctx) return &ast.SwitchNode{token.pos, switchValue, cases} } } }
go
func (t *tree) parseSwitch(token item, end itemType) ast.Node { const ctx = "switch" var switchValue = t.parseExpr(0) t.expect(itemRightDelim, ctx) var cases []*ast.SwitchCaseNode for { switch tok := t.next(); tok.typ { case itemLeftDelim: case itemText: // ignore spaces between tags. text is an error though. if allSpace(tok.val) { continue } t.unexpected(tok, "between switch cases") case itemCase, itemDefault: cases = append(cases, t.parseCase(tok)) case end: t.expect(itemRightDelim, ctx) return &ast.SwitchNode{token.pos, switchValue, cases} } } }
[ "func", "(", "t", "*", "tree", ")", "parseSwitch", "(", "token", "item", ",", "end", "itemType", ")", "ast", ".", "Node", "{", "const", "ctx", "=", "\"", "\"", "\n", "var", "switchValue", "=", "t", ".", "parseExpr", "(", "0", ")", "\n", "t", ".", "expect", "(", "itemRightDelim", ",", "ctx", ")", "\n\n", "var", "cases", "[", "]", "*", "ast", ".", "SwitchCaseNode", "\n", "for", "{", "switch", "tok", ":=", "t", ".", "next", "(", ")", ";", "tok", ".", "typ", "{", "case", "itemLeftDelim", ":", "case", "itemText", ":", "// ignore spaces between tags. text is an error though.", "if", "allSpace", "(", "tok", ".", "val", ")", "{", "continue", "\n", "}", "\n", "t", ".", "unexpected", "(", "tok", ",", "\"", "\"", ")", "\n", "case", "itemCase", ",", "itemDefault", ":", "cases", "=", "append", "(", "cases", ",", "t", ".", "parseCase", "(", "tok", ")", ")", "\n", "case", "end", ":", "t", ".", "expect", "(", "itemRightDelim", ",", "ctx", ")", "\n", "return", "&", "ast", ".", "SwitchNode", "{", "token", ".", "pos", ",", "switchValue", ",", "cases", "}", "\n", "}", "\n", "}", "\n", "}" ]
// "switch" has just been read.
[ "switch", "has", "just", "been", "read", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/parse.go#L423-L444
3,984
robfig/soy
parse/parse.go
parseCase
func (t *tree) parseCase(token item) *ast.SwitchCaseNode { var values []ast.Node for { if token.typ != itemDefault { values = append(values, t.parseExpr(0)) } switch tok := t.next(); tok.typ { case itemComma: continue case itemRightDelim: var body = t.itemList(itemCase, itemDefault, itemSwitchEnd, itemPluralEnd) t.backup() return &ast.SwitchCaseNode{token.pos, values, body} default: t.unexpected(tok, "switch case") } } }
go
func (t *tree) parseCase(token item) *ast.SwitchCaseNode { var values []ast.Node for { if token.typ != itemDefault { values = append(values, t.parseExpr(0)) } switch tok := t.next(); tok.typ { case itemComma: continue case itemRightDelim: var body = t.itemList(itemCase, itemDefault, itemSwitchEnd, itemPluralEnd) t.backup() return &ast.SwitchCaseNode{token.pos, values, body} default: t.unexpected(tok, "switch case") } } }
[ "func", "(", "t", "*", "tree", ")", "parseCase", "(", "token", "item", ")", "*", "ast", ".", "SwitchCaseNode", "{", "var", "values", "[", "]", "ast", ".", "Node", "\n", "for", "{", "if", "token", ".", "typ", "!=", "itemDefault", "{", "values", "=", "append", "(", "values", ",", "t", ".", "parseExpr", "(", "0", ")", ")", "\n", "}", "\n", "switch", "tok", ":=", "t", ".", "next", "(", ")", ";", "tok", ".", "typ", "{", "case", "itemComma", ":", "continue", "\n", "case", "itemRightDelim", ":", "var", "body", "=", "t", ".", "itemList", "(", "itemCase", ",", "itemDefault", ",", "itemSwitchEnd", ",", "itemPluralEnd", ")", "\n", "t", ".", "backup", "(", ")", "\n", "return", "&", "ast", ".", "SwitchCaseNode", "{", "token", ".", "pos", ",", "values", ",", "body", "}", "\n", "default", ":", "t", ".", "unexpected", "(", "tok", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "}" ]
// "case" has just been read.
[ "case", "has", "just", "been", "read", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/parse.go#L447-L464
3,985
robfig/soy
parse/parse.go
parseFor
func (t *tree) parseFor(token item) ast.Node { var ctx = token.val // for and foreach have the same syntax, differing only in the requirement they impose: // - for requires the collection to be a function call to "range" // - foreach requires the collection to be a variable reference. var vartoken = t.expect(itemDollarIdent, ctx) var intoken = t.expect(itemIdent, ctx) if intoken.val != "in" { t.unexpected(intoken, "for loop (expected 'in')") } // get the collection to iterate through and enforce the requirements var collection = t.parseExpr(0) t.expect(itemRightDelim, "foreach") if token.typ == itemFor { f, ok := collection.(*ast.FunctionNode) if !ok || f.Name != "range" { t.errorf("for: expected to iterate through range()") } } var body = t.itemList(itemIfempty, itemForeachEnd, itemForEnd) t.backup() var ifempty ast.Node if t.next().typ == itemIfempty { t.expect(itemRightDelim, "ifempty") ifempty = t.itemList(itemForeachEnd, itemForEnd) } t.expect(itemRightDelim, "/foreach") return &ast.ForNode{token.pos, vartoken.val[1:], collection, body, ifempty} }
go
func (t *tree) parseFor(token item) ast.Node { var ctx = token.val // for and foreach have the same syntax, differing only in the requirement they impose: // - for requires the collection to be a function call to "range" // - foreach requires the collection to be a variable reference. var vartoken = t.expect(itemDollarIdent, ctx) var intoken = t.expect(itemIdent, ctx) if intoken.val != "in" { t.unexpected(intoken, "for loop (expected 'in')") } // get the collection to iterate through and enforce the requirements var collection = t.parseExpr(0) t.expect(itemRightDelim, "foreach") if token.typ == itemFor { f, ok := collection.(*ast.FunctionNode) if !ok || f.Name != "range" { t.errorf("for: expected to iterate through range()") } } var body = t.itemList(itemIfempty, itemForeachEnd, itemForEnd) t.backup() var ifempty ast.Node if t.next().typ == itemIfempty { t.expect(itemRightDelim, "ifempty") ifempty = t.itemList(itemForeachEnd, itemForEnd) } t.expect(itemRightDelim, "/foreach") return &ast.ForNode{token.pos, vartoken.val[1:], collection, body, ifempty} }
[ "func", "(", "t", "*", "tree", ")", "parseFor", "(", "token", "item", ")", "ast", ".", "Node", "{", "var", "ctx", "=", "token", ".", "val", "\n", "// for and foreach have the same syntax, differing only in the requirement they impose:", "// - for requires the collection to be a function call to \"range\"", "// - foreach requires the collection to be a variable reference.", "var", "vartoken", "=", "t", ".", "expect", "(", "itemDollarIdent", ",", "ctx", ")", "\n", "var", "intoken", "=", "t", ".", "expect", "(", "itemIdent", ",", "ctx", ")", "\n", "if", "intoken", ".", "val", "!=", "\"", "\"", "{", "t", ".", "unexpected", "(", "intoken", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// get the collection to iterate through and enforce the requirements", "var", "collection", "=", "t", ".", "parseExpr", "(", "0", ")", "\n", "t", ".", "expect", "(", "itemRightDelim", ",", "\"", "\"", ")", "\n", "if", "token", ".", "typ", "==", "itemFor", "{", "f", ",", "ok", ":=", "collection", ".", "(", "*", "ast", ".", "FunctionNode", ")", "\n", "if", "!", "ok", "||", "f", ".", "Name", "!=", "\"", "\"", "{", "t", ".", "errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "var", "body", "=", "t", ".", "itemList", "(", "itemIfempty", ",", "itemForeachEnd", ",", "itemForEnd", ")", "\n", "t", ".", "backup", "(", ")", "\n", "var", "ifempty", "ast", ".", "Node", "\n", "if", "t", ".", "next", "(", ")", ".", "typ", "==", "itemIfempty", "{", "t", ".", "expect", "(", "itemRightDelim", ",", "\"", "\"", ")", "\n", "ifempty", "=", "t", ".", "itemList", "(", "itemForeachEnd", ",", "itemForEnd", ")", "\n", "}", "\n", "t", ".", "expect", "(", "itemRightDelim", ",", "\"", "\"", ")", "\n", "return", "&", "ast", ".", "ForNode", "{", "token", ".", "pos", ",", "vartoken", ".", "val", "[", "1", ":", "]", ",", "collection", ",", "body", ",", "ifempty", "}", "\n", "}" ]
// "for" or "foreach" has just been read.
[ "for", "or", "foreach", "has", "just", "been", "read", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/parse.go#L467-L497
3,986
robfig/soy
parse/parse.go
parseIf
func (t *tree) parseIf(token item) ast.Node { var conds []*ast.IfCondNode var isElse = false for { var condExpr ast.Node if !isElse { condExpr = t.parseExpr(0) } t.expect(itemRightDelim, "if") var body = t.itemList(itemElseif, itemElse, itemIfEnd) conds = append(conds, &ast.IfCondNode{token.pos, condExpr, body}) t.backup() switch t.next().typ { case itemElseif: // continue case itemElse: isElse = true case itemIfEnd: t.expect(itemRightDelim, "/if") return &ast.IfNode{token.pos, conds} } } }
go
func (t *tree) parseIf(token item) ast.Node { var conds []*ast.IfCondNode var isElse = false for { var condExpr ast.Node if !isElse { condExpr = t.parseExpr(0) } t.expect(itemRightDelim, "if") var body = t.itemList(itemElseif, itemElse, itemIfEnd) conds = append(conds, &ast.IfCondNode{token.pos, condExpr, body}) t.backup() switch t.next().typ { case itemElseif: // continue case itemElse: isElse = true case itemIfEnd: t.expect(itemRightDelim, "/if") return &ast.IfNode{token.pos, conds} } } }
[ "func", "(", "t", "*", "tree", ")", "parseIf", "(", "token", "item", ")", "ast", ".", "Node", "{", "var", "conds", "[", "]", "*", "ast", ".", "IfCondNode", "\n", "var", "isElse", "=", "false", "\n", "for", "{", "var", "condExpr", "ast", ".", "Node", "\n", "if", "!", "isElse", "{", "condExpr", "=", "t", ".", "parseExpr", "(", "0", ")", "\n", "}", "\n", "t", ".", "expect", "(", "itemRightDelim", ",", "\"", "\"", ")", "\n", "var", "body", "=", "t", ".", "itemList", "(", "itemElseif", ",", "itemElse", ",", "itemIfEnd", ")", "\n", "conds", "=", "append", "(", "conds", ",", "&", "ast", ".", "IfCondNode", "{", "token", ".", "pos", ",", "condExpr", ",", "body", "}", ")", "\n", "t", ".", "backup", "(", ")", "\n", "switch", "t", ".", "next", "(", ")", ".", "typ", "{", "case", "itemElseif", ":", "// continue", "case", "itemElse", ":", "isElse", "=", "true", "\n", "case", "itemIfEnd", ":", "t", ".", "expect", "(", "itemRightDelim", ",", "\"", "\"", ")", "\n", "return", "&", "ast", ".", "IfNode", "{", "token", ".", "pos", ",", "conds", "}", "\n", "}", "\n", "}", "\n", "}" ]
// "if" has just been read.
[ "if", "has", "just", "been", "read", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/parse.go#L500-L522
3,987
robfig/soy
parse/parse.go
parseMsg
func (t *tree) parseMsg(token item) ast.Node { const ctx = "msg" var attrs = t.parseAttrs("desc", "meaning", "hidden") if _, ok := attrs["desc"]; !ok { t.errorf("Tag 'msg' must have a 'desc' attribute") } t.expect(itemRightDelim, ctx) // Parse the message body. t.inmsg = true var contents = t.itemList(itemMsgEnd) t.inmsg = false // Replace children nodes with placeholders. var node = &ast.MsgNode{token.pos, 0, attrs["meaning"], attrs["desc"], t.placeholderize(contents)} // Validate: if there's a plural tag, it should be the only child var hasPlural = false for _, child := range node.Body.Children() { if _, ok := child.(*ast.MsgPluralNode); ok { hasPlural = true } } if hasPlural && len(node.Body.Children()) != 1 { t.errorf("content not allowed outside plural tag") } t.expect(itemRightDelim, ctx) return node }
go
func (t *tree) parseMsg(token item) ast.Node { const ctx = "msg" var attrs = t.parseAttrs("desc", "meaning", "hidden") if _, ok := attrs["desc"]; !ok { t.errorf("Tag 'msg' must have a 'desc' attribute") } t.expect(itemRightDelim, ctx) // Parse the message body. t.inmsg = true var contents = t.itemList(itemMsgEnd) t.inmsg = false // Replace children nodes with placeholders. var node = &ast.MsgNode{token.pos, 0, attrs["meaning"], attrs["desc"], t.placeholderize(contents)} // Validate: if there's a plural tag, it should be the only child var hasPlural = false for _, child := range node.Body.Children() { if _, ok := child.(*ast.MsgPluralNode); ok { hasPlural = true } } if hasPlural && len(node.Body.Children()) != 1 { t.errorf("content not allowed outside plural tag") } t.expect(itemRightDelim, ctx) return node }
[ "func", "(", "t", "*", "tree", ")", "parseMsg", "(", "token", "item", ")", "ast", ".", "Node", "{", "const", "ctx", "=", "\"", "\"", "\n", "var", "attrs", "=", "t", ".", "parseAttrs", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "_", ",", "ok", ":=", "attrs", "[", "\"", "\"", "]", ";", "!", "ok", "{", "t", ".", "errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "t", ".", "expect", "(", "itemRightDelim", ",", "ctx", ")", "\n\n", "// Parse the message body.", "t", ".", "inmsg", "=", "true", "\n", "var", "contents", "=", "t", ".", "itemList", "(", "itemMsgEnd", ")", "\n", "t", ".", "inmsg", "=", "false", "\n\n", "// Replace children nodes with placeholders.", "var", "node", "=", "&", "ast", ".", "MsgNode", "{", "token", ".", "pos", ",", "0", ",", "attrs", "[", "\"", "\"", "]", ",", "attrs", "[", "\"", "\"", "]", ",", "t", ".", "placeholderize", "(", "contents", ")", "}", "\n\n", "// Validate: if there's a plural tag, it should be the only child", "var", "hasPlural", "=", "false", "\n", "for", "_", ",", "child", ":=", "range", "node", ".", "Body", ".", "Children", "(", ")", "{", "if", "_", ",", "ok", ":=", "child", ".", "(", "*", "ast", ".", "MsgPluralNode", ")", ";", "ok", "{", "hasPlural", "=", "true", "\n", "}", "\n", "}", "\n", "if", "hasPlural", "&&", "len", "(", "node", ".", "Body", ".", "Children", "(", ")", ")", "!=", "1", "{", "t", ".", "errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "t", ".", "expect", "(", "itemRightDelim", ",", "ctx", ")", "\n", "return", "node", "\n", "}" ]
// "msg" has just been read.
[ "msg", "has", "just", "been", "read", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/parse.go#L579-L608
3,988
robfig/soy
parse/parse.go
parsePlural
func (t *tree) parsePlural(tok item) ast.Node { const ctx = "plural" if !t.inmsg { t.unexpected(tok, "not in msg") } // plural and switch nodes have the same structure. // BUG: the location quoted the erorr messages will not be correct. var sw = t.parseSwitch(tok, itemPluralEnd).(*ast.SwitchNode) var defaultNode ast.ParentNode var cases []*ast.MsgPluralCaseNode for _, node := range sw.Cases { if len(node.Values) == 0 { defaultNode = node.Body.(ast.ParentNode) } else { var intNode, ok = node.Values[0].(*ast.IntNode) if !ok || len(node.Values) > 1 { t.errorf("plural case must be a single integer, got %v", node.Values) } cases = append(cases, &ast.MsgPluralCaseNode{node.Pos, int(intNode.Value), node.Body.(ast.ParentNode)}) } } if defaultNode == nil { t.errorf("{default} case required") } return &ast.MsgPluralNode{sw.Pos, "", sw.Value, cases, defaultNode} }
go
func (t *tree) parsePlural(tok item) ast.Node { const ctx = "plural" if !t.inmsg { t.unexpected(tok, "not in msg") } // plural and switch nodes have the same structure. // BUG: the location quoted the erorr messages will not be correct. var sw = t.parseSwitch(tok, itemPluralEnd).(*ast.SwitchNode) var defaultNode ast.ParentNode var cases []*ast.MsgPluralCaseNode for _, node := range sw.Cases { if len(node.Values) == 0 { defaultNode = node.Body.(ast.ParentNode) } else { var intNode, ok = node.Values[0].(*ast.IntNode) if !ok || len(node.Values) > 1 { t.errorf("plural case must be a single integer, got %v", node.Values) } cases = append(cases, &ast.MsgPluralCaseNode{node.Pos, int(intNode.Value), node.Body.(ast.ParentNode)}) } } if defaultNode == nil { t.errorf("{default} case required") } return &ast.MsgPluralNode{sw.Pos, "", sw.Value, cases, defaultNode} }
[ "func", "(", "t", "*", "tree", ")", "parsePlural", "(", "tok", "item", ")", "ast", ".", "Node", "{", "const", "ctx", "=", "\"", "\"", "\n", "if", "!", "t", ".", "inmsg", "{", "t", ".", "unexpected", "(", "tok", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// plural and switch nodes have the same structure.", "// BUG: the location quoted the erorr messages will not be correct.", "var", "sw", "=", "t", ".", "parseSwitch", "(", "tok", ",", "itemPluralEnd", ")", ".", "(", "*", "ast", ".", "SwitchNode", ")", "\n", "var", "defaultNode", "ast", ".", "ParentNode", "\n", "var", "cases", "[", "]", "*", "ast", ".", "MsgPluralCaseNode", "\n", "for", "_", ",", "node", ":=", "range", "sw", ".", "Cases", "{", "if", "len", "(", "node", ".", "Values", ")", "==", "0", "{", "defaultNode", "=", "node", ".", "Body", ".", "(", "ast", ".", "ParentNode", ")", "\n", "}", "else", "{", "var", "intNode", ",", "ok", "=", "node", ".", "Values", "[", "0", "]", ".", "(", "*", "ast", ".", "IntNode", ")", "\n", "if", "!", "ok", "||", "len", "(", "node", ".", "Values", ")", ">", "1", "{", "t", ".", "errorf", "(", "\"", "\"", ",", "node", ".", "Values", ")", "\n", "}", "\n", "cases", "=", "append", "(", "cases", ",", "&", "ast", ".", "MsgPluralCaseNode", "{", "node", ".", "Pos", ",", "int", "(", "intNode", ".", "Value", ")", ",", "node", ".", "Body", ".", "(", "ast", ".", "ParentNode", ")", "}", ")", "\n", "}", "\n", "}", "\n", "if", "defaultNode", "==", "nil", "{", "t", ".", "errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "&", "ast", ".", "MsgPluralNode", "{", "sw", ".", "Pos", ",", "\"", "\"", ",", "sw", ".", "Value", ",", "cases", ",", "defaultNode", "}", "\n", "}" ]
// "plural" has just been read
[ "plural", "has", "just", "been", "read" ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/parse.go#L611-L637
3,989
robfig/soy
parse/parse.go
placeholderize
func (t *tree) placeholderize(parent ast.ParentNode) *ast.ListNode { // Wrap the children in Placeholder nodes unless they are RawText var r []ast.Node for _, child := range parent.Children() { switch child := child.(type) { case *ast.RawTextNode: r = append(r, t.parseMsgRawText(child)...) case *ast.MsgPluralNode: var cases []*ast.MsgPluralCaseNode for _, pc := range child.Cases { cases = append(cases, &ast.MsgPluralCaseNode{pc.Pos, pc.Value, t.placeholderize(pc.Body.(*ast.ListNode))}) } r = append(r, &ast.MsgPluralNode{child.Pos, "", child.Value, cases, t.placeholderize(child.Default.(*ast.ListNode))}) default: r = append(r, &ast.MsgPlaceholderNode{child.Position(), "", child}) } } return &ast.ListNode{parent.Position(), r} }
go
func (t *tree) placeholderize(parent ast.ParentNode) *ast.ListNode { // Wrap the children in Placeholder nodes unless they are RawText var r []ast.Node for _, child := range parent.Children() { switch child := child.(type) { case *ast.RawTextNode: r = append(r, t.parseMsgRawText(child)...) case *ast.MsgPluralNode: var cases []*ast.MsgPluralCaseNode for _, pc := range child.Cases { cases = append(cases, &ast.MsgPluralCaseNode{pc.Pos, pc.Value, t.placeholderize(pc.Body.(*ast.ListNode))}) } r = append(r, &ast.MsgPluralNode{child.Pos, "", child.Value, cases, t.placeholderize(child.Default.(*ast.ListNode))}) default: r = append(r, &ast.MsgPlaceholderNode{child.Position(), "", child}) } } return &ast.ListNode{parent.Position(), r} }
[ "func", "(", "t", "*", "tree", ")", "placeholderize", "(", "parent", "ast", ".", "ParentNode", ")", "*", "ast", ".", "ListNode", "{", "// Wrap the children in Placeholder nodes unless they are RawText", "var", "r", "[", "]", "ast", ".", "Node", "\n", "for", "_", ",", "child", ":=", "range", "parent", ".", "Children", "(", ")", "{", "switch", "child", ":=", "child", ".", "(", "type", ")", "{", "case", "*", "ast", ".", "RawTextNode", ":", "r", "=", "append", "(", "r", ",", "t", ".", "parseMsgRawText", "(", "child", ")", "...", ")", "\n", "case", "*", "ast", ".", "MsgPluralNode", ":", "var", "cases", "[", "]", "*", "ast", ".", "MsgPluralCaseNode", "\n", "for", "_", ",", "pc", ":=", "range", "child", ".", "Cases", "{", "cases", "=", "append", "(", "cases", ",", "&", "ast", ".", "MsgPluralCaseNode", "{", "pc", ".", "Pos", ",", "pc", ".", "Value", ",", "t", ".", "placeholderize", "(", "pc", ".", "Body", ".", "(", "*", "ast", ".", "ListNode", ")", ")", "}", ")", "\n", "}", "\n", "r", "=", "append", "(", "r", ",", "&", "ast", ".", "MsgPluralNode", "{", "child", ".", "Pos", ",", "\"", "\"", ",", "child", ".", "Value", ",", "cases", ",", "t", ".", "placeholderize", "(", "child", ".", "Default", ".", "(", "*", "ast", ".", "ListNode", ")", ")", "}", ")", "\n", "default", ":", "r", "=", "append", "(", "r", ",", "&", "ast", ".", "MsgPlaceholderNode", "{", "child", ".", "Position", "(", ")", ",", "\"", "\"", ",", "child", "}", ")", "\n", "}", "\n", "}", "\n", "return", "&", "ast", ".", "ListNode", "{", "parent", ".", "Position", "(", ")", ",", "r", "}", "\n", "}" ]
// placeholderize wraps all children of the given node in placeholders as // necessary. the new list of children nodes is returned.
[ "placeholderize", "wraps", "all", "children", "of", "the", "given", "node", "in", "placeholders", "as", "necessary", ".", "the", "new", "list", "of", "children", "nodes", "is", "returned", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/parse.go#L641-L660
3,990
robfig/soy
parse/parse.go
parseMsgRawText
func (t *tree) parseMsgRawText(node *ast.RawTextNode) []ast.Node { var ( r []ast.Node txt = node.Text pos = node.Position() ) for len(txt) > 0 { var start, end = len(txt), len(txt) var ii = htmlTagRegexp.FindSubmatchIndex(txt) if ii != nil { start, end = ii[0], ii[1] } if start > 0 { r = append(r, &ast.RawTextNode{pos, txt[:start]}) pos += ast.Pos(start) } if end > start { r = append(r, &ast.MsgPlaceholderNode{pos, "", &ast.MsgHtmlTagNode{pos, txt[start:end]}}) pos += ast.Pos(end - start) } txt = txt[end:] } return r }
go
func (t *tree) parseMsgRawText(node *ast.RawTextNode) []ast.Node { var ( r []ast.Node txt = node.Text pos = node.Position() ) for len(txt) > 0 { var start, end = len(txt), len(txt) var ii = htmlTagRegexp.FindSubmatchIndex(txt) if ii != nil { start, end = ii[0], ii[1] } if start > 0 { r = append(r, &ast.RawTextNode{pos, txt[:start]}) pos += ast.Pos(start) } if end > start { r = append(r, &ast.MsgPlaceholderNode{pos, "", &ast.MsgHtmlTagNode{pos, txt[start:end]}}) pos += ast.Pos(end - start) } txt = txt[end:] } return r }
[ "func", "(", "t", "*", "tree", ")", "parseMsgRawText", "(", "node", "*", "ast", ".", "RawTextNode", ")", "[", "]", "ast", ".", "Node", "{", "var", "(", "r", "[", "]", "ast", ".", "Node", "\n", "txt", "=", "node", ".", "Text", "\n", "pos", "=", "node", ".", "Position", "(", ")", "\n", ")", "\n", "for", "len", "(", "txt", ")", ">", "0", "{", "var", "start", ",", "end", "=", "len", "(", "txt", ")", ",", "len", "(", "txt", ")", "\n", "var", "ii", "=", "htmlTagRegexp", ".", "FindSubmatchIndex", "(", "txt", ")", "\n", "if", "ii", "!=", "nil", "{", "start", ",", "end", "=", "ii", "[", "0", "]", ",", "ii", "[", "1", "]", "\n", "}", "\n\n", "if", "start", ">", "0", "{", "r", "=", "append", "(", "r", ",", "&", "ast", ".", "RawTextNode", "{", "pos", ",", "txt", "[", ":", "start", "]", "}", ")", "\n", "pos", "+=", "ast", ".", "Pos", "(", "start", ")", "\n", "}", "\n\n", "if", "end", ">", "start", "{", "r", "=", "append", "(", "r", ",", "&", "ast", ".", "MsgPlaceholderNode", "{", "pos", ",", "\"", "\"", ",", "&", "ast", ".", "MsgHtmlTagNode", "{", "pos", ",", "txt", "[", "start", ":", "end", "]", "}", "}", ")", "\n", "pos", "+=", "ast", ".", "Pos", "(", "end", "-", "start", ")", "\n", "}", "\n\n", "txt", "=", "txt", "[", "end", ":", "]", "\n", "}", "\n", "return", "r", "\n", "}" ]
// parseMsgRawText returns a sequence of text and html placeholder nodes for the // given raw text.
[ "parseMsgRawText", "returns", "a", "sequence", "of", "text", "and", "html", "placeholder", "nodes", "for", "the", "given", "raw", "text", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/parse.go#L669-L695
3,991
robfig/soy
parse/parse.go
notmsg
func (t *tree) notmsg(tok item) { if t.inmsg { t.unexpected(tok, "msg") } }
go
func (t *tree) notmsg(tok item) { if t.inmsg { t.unexpected(tok, "msg") } }
[ "func", "(", "t", "*", "tree", ")", "notmsg", "(", "tok", "item", ")", "{", "if", "t", ".", "inmsg", "{", "t", ".", "unexpected", "(", "tok", ",", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// notmsg asserts that the parser is not currently within a message node
[ "notmsg", "asserts", "that", "the", "parser", "is", "not", "currently", "within", "a", "message", "node" ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/parse.go#L698-L702
3,992
robfig/soy
parse/parse.go
parseAutoescape
func (t *tree) parseAutoescape(attrs map[string]string) ast.AutoescapeType { switch val := attrs["autoescape"]; val { case "": return ast.AutoescapeUnspecified case "contextual": return ast.AutoescapeContextual case "deprecated-contextual": return ast.AutoescapeContextual case "true": return ast.AutoescapeOn case "false": return ast.AutoescapeOff default: t.errorf(`expected "true", "false", or "contextual" for autoescape, got %q`, val) } panic("unreachable") }
go
func (t *tree) parseAutoescape(attrs map[string]string) ast.AutoescapeType { switch val := attrs["autoescape"]; val { case "": return ast.AutoescapeUnspecified case "contextual": return ast.AutoescapeContextual case "deprecated-contextual": return ast.AutoescapeContextual case "true": return ast.AutoescapeOn case "false": return ast.AutoescapeOff default: t.errorf(`expected "true", "false", or "contextual" for autoescape, got %q`, val) } panic("unreachable") }
[ "func", "(", "t", "*", "tree", ")", "parseAutoescape", "(", "attrs", "map", "[", "string", "]", "string", ")", "ast", ".", "AutoescapeType", "{", "switch", "val", ":=", "attrs", "[", "\"", "\"", "]", ";", "val", "{", "case", "\"", "\"", ":", "return", "ast", ".", "AutoescapeUnspecified", "\n", "case", "\"", "\"", ":", "return", "ast", ".", "AutoescapeContextual", "\n", "case", "\"", "\"", ":", "return", "ast", ".", "AutoescapeContextual", "\n", "case", "\"", "\"", ":", "return", "ast", ".", "AutoescapeOn", "\n", "case", "\"", "\"", ":", "return", "ast", ".", "AutoescapeOff", "\n", "default", ":", "t", ".", "errorf", "(", "`expected \"true\", \"false\", or \"contextual\" for autoescape, got %q`", ",", "val", ")", "\n", "}", "\n", "panic", "(", "\"", "\"", ")", "\n", "}" ]
// parseAutoescape returns the specified autoescape selection, or // AutoescapeContextual by default.
[ "parseAutoescape", "returns", "the", "specified", "autoescape", "selection", "or", "AutoescapeContextual", "by", "default", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/parse.go#L726-L742
3,993
robfig/soy
parse/parse.go
boolAttr
func (t *tree) boolAttr(attrs map[string]string, key string, defaultValue bool) bool { switch str, ok := attrs[key]; { case !ok: return defaultValue case str == "true": return true case str == "false": return false default: t.errorf("expected 'true' or 'false', got %q", str) } panic("") }
go
func (t *tree) boolAttr(attrs map[string]string, key string, defaultValue bool) bool { switch str, ok := attrs[key]; { case !ok: return defaultValue case str == "true": return true case str == "false": return false default: t.errorf("expected 'true' or 'false', got %q", str) } panic("") }
[ "func", "(", "t", "*", "tree", ")", "boolAttr", "(", "attrs", "map", "[", "string", "]", "string", ",", "key", "string", ",", "defaultValue", "bool", ")", "bool", "{", "switch", "str", ",", "ok", ":=", "attrs", "[", "key", "]", ";", "{", "case", "!", "ok", ":", "return", "defaultValue", "\n", "case", "str", "==", "\"", "\"", ":", "return", "true", "\n", "case", "str", "==", "\"", "\"", ":", "return", "false", "\n", "default", ":", "t", ".", "errorf", "(", "\"", "\"", ",", "str", ")", "\n", "}", "\n", "panic", "(", "\"", "\"", ")", "\n", "}" ]
// boolAttr returns a boolean value from the given attribute map.
[ "boolAttr", "returns", "a", "boolean", "value", "from", "the", "given", "attribute", "map", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/parse.go#L774-L786
3,994
robfig/soy
parse/parse.go
parseListOrMap
func (t *tree) parseListOrMap(token item) ast.Node { // check if it's empty switch t.next().typ { case itemColon: t.expect(itemRightBracket, "map literal") return &ast.MapLiteralNode{token.pos, nil} case itemRightBracket: return &ast.ListLiteralNode{token.pos, nil} } t.backup() // parse the first expression, and check the subsequent delimiter var firstExpr = t.parseExpr(0) switch tok := t.next(); tok.typ { case itemColon: return t.parseMapLiteral(token, firstExpr) case itemComma: return t.parseListLiteral(token, firstExpr) case itemRightBracket: return &ast.ListLiteralNode{token.pos, []ast.Node{firstExpr}} default: t.unexpected(tok, "list/map literal") } return nil }
go
func (t *tree) parseListOrMap(token item) ast.Node { // check if it's empty switch t.next().typ { case itemColon: t.expect(itemRightBracket, "map literal") return &ast.MapLiteralNode{token.pos, nil} case itemRightBracket: return &ast.ListLiteralNode{token.pos, nil} } t.backup() // parse the first expression, and check the subsequent delimiter var firstExpr = t.parseExpr(0) switch tok := t.next(); tok.typ { case itemColon: return t.parseMapLiteral(token, firstExpr) case itemComma: return t.parseListLiteral(token, firstExpr) case itemRightBracket: return &ast.ListLiteralNode{token.pos, []ast.Node{firstExpr}} default: t.unexpected(tok, "list/map literal") } return nil }
[ "func", "(", "t", "*", "tree", ")", "parseListOrMap", "(", "token", "item", ")", "ast", ".", "Node", "{", "// check if it's empty", "switch", "t", ".", "next", "(", ")", ".", "typ", "{", "case", "itemColon", ":", "t", ".", "expect", "(", "itemRightBracket", ",", "\"", "\"", ")", "\n", "return", "&", "ast", ".", "MapLiteralNode", "{", "token", ".", "pos", ",", "nil", "}", "\n", "case", "itemRightBracket", ":", "return", "&", "ast", ".", "ListLiteralNode", "{", "token", ".", "pos", ",", "nil", "}", "\n", "}", "\n", "t", ".", "backup", "(", ")", "\n\n", "// parse the first expression, and check the subsequent delimiter", "var", "firstExpr", "=", "t", ".", "parseExpr", "(", "0", ")", "\n", "switch", "tok", ":=", "t", ".", "next", "(", ")", ";", "tok", ".", "typ", "{", "case", "itemColon", ":", "return", "t", ".", "parseMapLiteral", "(", "token", ",", "firstExpr", ")", "\n", "case", "itemComma", ":", "return", "t", ".", "parseListLiteral", "(", "token", ",", "firstExpr", ")", "\n", "case", "itemRightBracket", ":", "return", "&", "ast", ".", "ListLiteralNode", "{", "token", ".", "pos", ",", "[", "]", "ast", ".", "Node", "{", "firstExpr", "}", "}", "\n", "default", ":", "t", ".", "unexpected", "(", "tok", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// "[" has just been read
[ "[", "has", "just", "been", "read" ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/parse.go#L897-L921
3,995
robfig/soy
parse/parse.go
parseTernary
func (t *tree) parseTernary(cond ast.Node) ast.Node { n1 := t.parseExpr(0) t.expect(itemColon, "ternary") n2 := t.parseExpr(0) result := &ast.TernNode{cond.Position(), cond, n1, n2} if t.peek().typ == itemColon { t.next() return t.parseTernary(result) } return result }
go
func (t *tree) parseTernary(cond ast.Node) ast.Node { n1 := t.parseExpr(0) t.expect(itemColon, "ternary") n2 := t.parseExpr(0) result := &ast.TernNode{cond.Position(), cond, n1, n2} if t.peek().typ == itemColon { t.next() return t.parseTernary(result) } return result }
[ "func", "(", "t", "*", "tree", ")", "parseTernary", "(", "cond", "ast", ".", "Node", ")", "ast", ".", "Node", "{", "n1", ":=", "t", ".", "parseExpr", "(", "0", ")", "\n", "t", ".", "expect", "(", "itemColon", ",", "\"", "\"", ")", "\n", "n2", ":=", "t", ".", "parseExpr", "(", "0", ")", "\n", "result", ":=", "&", "ast", ".", "TernNode", "{", "cond", ".", "Position", "(", ")", ",", "cond", ",", "n1", ",", "n2", "}", "\n", "if", "t", ".", "peek", "(", ")", ".", "typ", "==", "itemColon", "{", "t", ".", "next", "(", ")", "\n", "return", "t", ".", "parseTernary", "(", "result", ")", "\n", "}", "\n", "return", "result", "\n", "}" ]
// parseTernary parses the ternary operator within an expression. // itemTernIf has already been read, and the condition is provided.
[ "parseTernary", "parses", "the", "ternary", "operator", "within", "an", "expression", ".", "itemTernIf", "has", "already", "been", "read", "and", "the", "condition", "is", "provided", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/parse.go#L973-L983
3,996
robfig/soy
parse/parse.go
expect
func (t *tree) expect(expected itemType, context string) item { token := t.next() if token.typ != expected { t.unexpected(token, fmt.Sprintf("%v (expected %v)", context, expected.String())) } return token }
go
func (t *tree) expect(expected itemType, context string) item { token := t.next() if token.typ != expected { t.unexpected(token, fmt.Sprintf("%v (expected %v)", context, expected.String())) } return token }
[ "func", "(", "t", "*", "tree", ")", "expect", "(", "expected", "itemType", ",", "context", "string", ")", "item", "{", "token", ":=", "t", ".", "next", "(", ")", "\n", "if", "token", ".", "typ", "!=", "expected", "{", "t", ".", "unexpected", "(", "token", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "context", ",", "expected", ".", "String", "(", ")", ")", ")", "\n", "}", "\n", "return", "token", "\n", "}" ]
// expect consumes the next token and guarantees it has the required type.
[ "expect", "consumes", "the", "next", "token", "and", "guarantees", "it", "has", "the", "required", "type", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/parse/parse.go#L1201-L1207
3,997
robfig/soy
soymsg/id.go
calcID
func calcID(n *ast.MsgNode) uint64 { var buf bytes.Buffer writeFingerprint(&buf, n, false) var fp = fingerprint(buf.Bytes()) if n.Meaning != "" { var topbit uint64 if fp&(1<<63) > 0 { topbit = 1 } fp = (fp << 1) + topbit + fingerprint([]byte(n.Meaning)) } return fp & 0x7fffffffffffffff }
go
func calcID(n *ast.MsgNode) uint64 { var buf bytes.Buffer writeFingerprint(&buf, n, false) var fp = fingerprint(buf.Bytes()) if n.Meaning != "" { var topbit uint64 if fp&(1<<63) > 0 { topbit = 1 } fp = (fp << 1) + topbit + fingerprint([]byte(n.Meaning)) } return fp & 0x7fffffffffffffff }
[ "func", "calcID", "(", "n", "*", "ast", ".", "MsgNode", ")", "uint64", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "writeFingerprint", "(", "&", "buf", ",", "n", ",", "false", ")", "\n\n", "var", "fp", "=", "fingerprint", "(", "buf", ".", "Bytes", "(", ")", ")", "\n", "if", "n", ".", "Meaning", "!=", "\"", "\"", "{", "var", "topbit", "uint64", "\n", "if", "fp", "&", "(", "1", "<<", "63", ")", ">", "0", "{", "topbit", "=", "1", "\n", "}", "\n", "fp", "=", "(", "fp", "<<", "1", ")", "+", "topbit", "+", "fingerprint", "(", "[", "]", "byte", "(", "n", ".", "Meaning", ")", ")", "\n", "}", "\n\n", "return", "fp", "&", "0x7fffffffffffffff", "\n", "}" ]
// calcID calculates the message ID for the given message node. // The ID changes if the text content or meaning attribute changes. // It is invariant to changes in description.
[ "calcID", "calculates", "the", "message", "ID", "for", "the", "given", "message", "node", ".", "The", "ID", "changes", "if", "the", "text", "content", "or", "meaning", "attribute", "changes", ".", "It", "is", "invariant", "to", "changes", "in", "description", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/soymsg/id.go#L14-L28
3,998
robfig/soy
soymsg/id.go
writeFingerprint
func writeFingerprint(buf *bytes.Buffer, part ast.Node, braces bool) { switch part := part.(type) { case *ast.MsgNode: for _, part := range part.Body.Children() { writeFingerprint(buf, part, braces) } case *ast.RawTextNode: buf.Write(part.Text) case *ast.MsgPlaceholderNode: if braces { buf.WriteString("{" + part.Name + "}") } else { buf.WriteString(part.Name) } case *ast.MsgPluralNode: buf.WriteString("{" + part.VarName + ",plural,") for _, plCase := range part.Cases { buf.WriteString("=" + strconv.Itoa(plCase.Value) + "{") for _, child := range plCase.Body.Children() { writeFingerprint(buf, child, true) } buf.WriteString("}") } buf.WriteString("other{") for _, child := range part.Default.Children() { writeFingerprint(buf, child, true) } buf.WriteString("}}") default: panic(fmt.Sprintf("unrecognized type %T", part)) } }
go
func writeFingerprint(buf *bytes.Buffer, part ast.Node, braces bool) { switch part := part.(type) { case *ast.MsgNode: for _, part := range part.Body.Children() { writeFingerprint(buf, part, braces) } case *ast.RawTextNode: buf.Write(part.Text) case *ast.MsgPlaceholderNode: if braces { buf.WriteString("{" + part.Name + "}") } else { buf.WriteString(part.Name) } case *ast.MsgPluralNode: buf.WriteString("{" + part.VarName + ",plural,") for _, plCase := range part.Cases { buf.WriteString("=" + strconv.Itoa(plCase.Value) + "{") for _, child := range plCase.Body.Children() { writeFingerprint(buf, child, true) } buf.WriteString("}") } buf.WriteString("other{") for _, child := range part.Default.Children() { writeFingerprint(buf, child, true) } buf.WriteString("}}") default: panic(fmt.Sprintf("unrecognized type %T", part)) } }
[ "func", "writeFingerprint", "(", "buf", "*", "bytes", ".", "Buffer", ",", "part", "ast", ".", "Node", ",", "braces", "bool", ")", "{", "switch", "part", ":=", "part", ".", "(", "type", ")", "{", "case", "*", "ast", ".", "MsgNode", ":", "for", "_", ",", "part", ":=", "range", "part", ".", "Body", ".", "Children", "(", ")", "{", "writeFingerprint", "(", "buf", ",", "part", ",", "braces", ")", "\n", "}", "\n", "case", "*", "ast", ".", "RawTextNode", ":", "buf", ".", "Write", "(", "part", ".", "Text", ")", "\n", "case", "*", "ast", ".", "MsgPlaceholderNode", ":", "if", "braces", "{", "buf", ".", "WriteString", "(", "\"", "\"", "+", "part", ".", "Name", "+", "\"", "\"", ")", "\n", "}", "else", "{", "buf", ".", "WriteString", "(", "part", ".", "Name", ")", "\n", "}", "\n", "case", "*", "ast", ".", "MsgPluralNode", ":", "buf", ".", "WriteString", "(", "\"", "\"", "+", "part", ".", "VarName", "+", "\"", "\"", ")", "\n", "for", "_", ",", "plCase", ":=", "range", "part", ".", "Cases", "{", "buf", ".", "WriteString", "(", "\"", "\"", "+", "strconv", ".", "Itoa", "(", "plCase", ".", "Value", ")", "+", "\"", "\"", ")", "\n", "for", "_", ",", "child", ":=", "range", "plCase", ".", "Body", ".", "Children", "(", ")", "{", "writeFingerprint", "(", "buf", ",", "child", ",", "true", ")", "\n", "}", "\n", "buf", ".", "WriteString", "(", "\"", "\"", ")", "\n", "}", "\n", "buf", ".", "WriteString", "(", "\"", "\"", ")", "\n", "for", "_", ",", "child", ":=", "range", "part", ".", "Default", ".", "Children", "(", ")", "{", "writeFingerprint", "(", "buf", ",", "child", ",", "true", ")", "\n", "}", "\n", "buf", ".", "WriteString", "(", "\"", "\"", ")", "\n", "default", ":", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "part", ")", ")", "\n", "}", "\n", "}" ]
// writeFingerprint writes the string used to fingerprint a message to the buffer. // if braces is true, the string written has placeholders surrounded by braces. // Plural messages always have braced placeholders.
[ "writeFingerprint", "writes", "the", "string", "used", "to", "fingerprint", "a", "message", "to", "the", "buffer", ".", "if", "braces", "is", "true", "the", "string", "written", "has", "placeholders", "surrounded", "by", "braces", ".", "Plural", "messages", "always", "have", "braced", "placeholders", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/soymsg/id.go#L33-L64
3,999
robfig/soy
soymsg/id.go
fingerprint
func fingerprint(str []byte) uint64 { var hi = hash32(str, 0, len(str), 0) var lo = hash32(str, 0, len(str), 102072) if (hi == 0) && (lo == 0 || lo == 1) { // Turn 0/1 into another fingerprint hi ^= 0x130f9bef lo ^= 0x94a0a928 } return (uint64(hi) << 32) | uint64(lo&0xffffffff) }
go
func fingerprint(str []byte) uint64 { var hi = hash32(str, 0, len(str), 0) var lo = hash32(str, 0, len(str), 102072) if (hi == 0) && (lo == 0 || lo == 1) { // Turn 0/1 into another fingerprint hi ^= 0x130f9bef lo ^= 0x94a0a928 } return (uint64(hi) << 32) | uint64(lo&0xffffffff) }
[ "func", "fingerprint", "(", "str", "[", "]", "byte", ")", "uint64", "{", "var", "hi", "=", "hash32", "(", "str", ",", "0", ",", "len", "(", "str", ")", ",", "0", ")", "\n", "var", "lo", "=", "hash32", "(", "str", ",", "0", ",", "len", "(", "str", ")", ",", "102072", ")", "\n", "if", "(", "hi", "==", "0", ")", "&&", "(", "lo", "==", "0", "||", "lo", "==", "1", ")", "{", "// Turn 0/1 into another fingerprint", "hi", "^=", "0x130f9bef", "\n", "lo", "^=", "0x94a0a928", "\n", "}", "\n", "return", "(", "uint64", "(", "hi", ")", "<<", "32", ")", "|", "uint64", "(", "lo", "&", "0xffffffff", ")", "\n", "}" ]
// fingerprinting functions ported from official Soy, so that we end up with the // same message ids.
[ "fingerprinting", "functions", "ported", "from", "official", "Soy", "so", "that", "we", "end", "up", "with", "the", "same", "message", "ids", "." ]
6b9d0368d4265c382c3e11fe774d93aa8d431064
https://github.com/robfig/soy/blob/6b9d0368d4265c382c3e11fe774d93aa8d431064/soymsg/id.go#L69-L78