Debian Codegraph @

tools/gen-jscore/helpers.go

raw symbols SCIP
1 package main
2
3 import (
4 "fmt"
5 "unicode"
6 )
7
8 // ucfirst converts the first rune of val to uppercase an returns the result.
9 func ucfirst(val string) string {
10 r := []rune(val)
11 r[0] = unicode.ToUpper(r[0])
12
13 return string(r)
14 }
15
16 // dict is a template helper returns a map created from alternating values.
17 // Values must be passed as key, value pairs with key being a string.
18 // It can be used to pass the combination of multiple values to a template.
19 func dict(values ...interface{}) (map[string]interface{}, error) {
20 if len(values)%2 != 0 {
21 return nil, fmt.Errorf("map requires parameters which are multiple of 2 got %d", len(values))
22 }
23
24 m := make(map[string]interface{}, len(values)/2)
25 for i := 0; i < len(values); i += 2 {
26 key, ok := values[i].(string)
27 if !ok {
28 return nil, fmt.Errorf("map keys must be strings got %T", values[i])
29 }
30 m[key] = values[i+1]
31 }
32
33 return m, nil
34 }