diff options
author | Ondrej Fabry <ofabry@cisco.com> | 2019-08-02 15:07:53 +0200 |
---|---|---|
committer | Ondrej Fabry <ofabry@cisco.com> | 2019-08-02 15:07:53 +0200 |
commit | ca6003af1a7e1adb7d45879c2d5038bc05c2bb1a (patch) | |
tree | 97a3620b0fc5c7a0ee032fe7d12d37b6303cfb01 /vendor/github.com/bennyscetbun/jsongo/print.go | |
parent | 639870b5083a1e66f4584ec7a5f30492fcdb7168 (diff) |
Migrate to modules, refactor Makefile and use Travis for CI
- migrate to Go modules and remove vendor
- refactor Makefile
- add version package and store version
- split extras from the rest
- use travis for CI
Change-Id: I81b35220653b0f7c9a0fcdd4c527d691ec1e96c1
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'vendor/github.com/bennyscetbun/jsongo/print.go')
-rw-r--r-- | vendor/github.com/bennyscetbun/jsongo/print.go | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/vendor/github.com/bennyscetbun/jsongo/print.go b/vendor/github.com/bennyscetbun/jsongo/print.go deleted file mode 100644 index 6869918..0000000 --- a/vendor/github.com/bennyscetbun/jsongo/print.go +++ /dev/null @@ -1,74 +0,0 @@ -package jsongo - -import ( - "fmt" - "regexp" - "strings" -) - -//Thanks https://github.com/chuckpreslar/inflect for the UpperCamelCase - -// Split's a string so that it can be converted to a different casing. -// Splits on underscores, hyphens, spaces and camel casing. -func split(str string) []string { - // FIXME: This isn't a perfect solution. - // ex. WEiRD CaSINg (Support for 13 year old developers) - return strings.Split(regexp.MustCompile(`-|_|([a-z])([A-Z])`).ReplaceAllString(strings.Trim(str, `-|_| `), `$1 $2`), ` `) -} - -// UpperCamelCase converts a string to it's upper camel case version. -func UpperCamelCase(str string) string { - pieces := split(str) - - for index, s := range pieces { - pieces[index] = fmt.Sprintf(`%v%v`, strings.ToUpper(string(s[0])), strings.ToLower(s[1:])) - } - - return strings.Join(pieces, ``) -} - -func (that *JSONNode) printValue(indentlevel int, indentchar string) { - fmt.Printf(" %T ", that.Get()) -} - -func (that *JSONNode) printMap(indentlevel int, indentchar string) { - fmt.Printf(" struct {\n") - for key := range that.m { - printfindent(indentlevel+1, indentchar, "%s", UpperCamelCase(key)) - that.m[key].print(indentlevel+1, indentchar) - fmt.Printf(" `json:\"%s\"`\n", key) - } - printfindent(indentlevel, indentchar, "}") -} - -func (that *JSONNode) printArray(indentlevel int, indentchar string) { - if len(that.a) == 0 { - fmt.Printf(" []interface{} ") - return - } - fmt.Printf(" [] ") - for key := range that.a { - that.a[key].print(indentlevel+1, indentchar) - break - } -} - -//DebugProspect Print all the data the we ve got on a node and all it s children -func (that *JSONNode) print(indentlevel int, indentchar string) { - switch that.t { - case TypeValue: - that.printValue(indentlevel, indentchar) - case TypeMap: - that.printMap(indentlevel, indentchar) - case TypeArray: - that.printArray(indentlevel, indentchar) - case TypeUndefined: - printfindent(indentlevel, indentchar, "Is of Type: TypeUndefined\n") - } -} - -//Print Print all the data the we ve got on a node and all it s children as a go struct :) (FOR DEV PURPOSE) -func (that *JSONNode) Print() { - that.print(0, "\t") - fmt.Printf("\n") -} |