From bee6dcfe05d6e6a1030f6863cf849b339a2000dc Mon Sep 17 00:00:00 2001 From: thisisaaronland Date: Mon, 29 Mar 2021 14:51:47 -0700 Subject: [PATCH] update vendor deps --- go.mod | 6 +- go.sum | 8 + .../sfomuseum/go-flags/multi/int.go | 41 +++++ vendor/github.com/tidwall/gjson/README.md | 10 +- vendor/github.com/tidwall/gjson/SYNTAX.md | 15 +- vendor/github.com/tidwall/gjson/gjson.go | 74 ++++---- vendor/github.com/tidwall/gjson/go.mod | 2 +- vendor/github.com/tidwall/gjson/go.sum | 6 +- vendor/github.com/tidwall/pretty/.travis.yml | 1 - vendor/github.com/tidwall/pretty/README.md | 43 ++++- vendor/github.com/tidwall/pretty/pretty.go | 158 ++++++++++++++++-- .../go-writer-featurecollection/README.md | 3 +- .../featurecollection.go | 8 +- vendor/modules.txt | 8 +- 14 files changed, 315 insertions(+), 68 deletions(-) delete mode 100644 vendor/github.com/tidwall/pretty/.travis.yml diff --git a/go.mod b/go.mod index 11eb9f8..b0f12c4 100644 --- a/go.mod +++ b/go.mod @@ -5,8 +5,8 @@ go 1.16 require ( github.com/aaronland/go-json-query v0.0.2 github.com/paulmach/orb v0.2.1 - github.com/sfomuseum/go-flags v0.7.0 - github.com/tidwall/gjson v1.6.8 + github.com/sfomuseum/go-flags v0.8.2 + github.com/tidwall/gjson v1.7.4 github.com/tidwall/sjson v1.1.5 github.com/whosonfirst/go-reader v0.5.0 github.com/whosonfirst/go-whosonfirst-export/v2 v2.2.0 @@ -14,5 +14,5 @@ require ( github.com/whosonfirst/go-whosonfirst-reader v0.0.2 github.com/whosonfirst/go-whosonfirst-writer v0.2.1 github.com/whosonfirst/go-writer v0.4.1 - github.com/whosonfirst/go-writer-featurecollection v0.0.1 + github.com/whosonfirst/go-writer-featurecollection v0.0.2 ) diff --git a/go.sum b/go.sum index e29d6a4..4f86ab9 100644 --- a/go.sum +++ b/go.sum @@ -83,6 +83,8 @@ github.com/sfomuseum/go-flags v0.6.0 h1:zwqOKRe7vZGGtKYQiAjZHg6TF/cbavMMZssD4WjW github.com/sfomuseum/go-flags v0.6.0/go.mod h1:ML3DTNbF9xnjExSdS/9FtVLjIUhRU5gm/ehzISv+t2w= github.com/sfomuseum/go-flags v0.7.0 h1:tj0BhAEhc7enIA0kuLjVNrVkqiUelX5jQkyL/A0cNAo= github.com/sfomuseum/go-flags v0.7.0/go.mod h1:ML3DTNbF9xnjExSdS/9FtVLjIUhRU5gm/ehzISv+t2w= +github.com/sfomuseum/go-flags v0.8.2 h1:elSU3KWMo442d1YjXu5Y/bokxvkGV+OrgAHshHZaeIo= +github.com/sfomuseum/go-flags v0.8.2/go.mod h1:ML3DTNbF9xnjExSdS/9FtVLjIUhRU5gm/ehzISv+t2w= github.com/skelterjohn/geom v0.0.0-20180103142417-96f3e8a219c5 h1:qQF/q/+xaKD4CAVz3zfuvpij8U4ihSGIhHfOROI4NFc= github.com/skelterjohn/geom v0.0.0-20180103142417-96f3e8a219c5/go.mod h1:w8cQIijHlvvZM7afYlixPThHAdD+AkRFw3Mb9yQ2Y+I= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= @@ -96,6 +98,8 @@ github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJH github.com/tidwall/gjson v1.6.7/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI= github.com/tidwall/gjson v1.6.8 h1:CTmXMClGYPAmln7652e69B7OLXfTi5ABcPPwjIWUv7w= github.com/tidwall/gjson v1.6.8/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI= +github.com/tidwall/gjson v1.7.4 h1:19cchw8FOxkG5mdLRkGf9jqIqEyqdZhPqW60XfyFxk8= +github.com/tidwall/gjson v1.7.4/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk= github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E= github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE= github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= @@ -103,6 +107,8 @@ github.com/tidwall/pretty v0.0.0-20190325153808-1166b9ac2b65/go.mod h1:XNkn88O1C github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU= github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/tidwall/pretty v1.1.0 h1:K3hMW5epkdAVwibsQEfR/7Zj0Qgt4DxtNumTq/VloO8= +github.com/tidwall/pretty v1.1.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/tidwall/sjson v1.1.4/go.mod h1:wXpKXu8CtDjKAZ+3DrKY5ROCorDFahq8l0tey/Lx1fg= github.com/tidwall/sjson v1.1.5 h1:wsUceI/XDyZk3J1FUvuuYlK62zJv2HO2Pzb8A5EWdUE= github.com/tidwall/sjson v1.1.5/go.mod h1:VuJzsZnTowhSxWdOgsAnb886i4AjEyTkk7tNtsL7EYE= @@ -179,6 +185,8 @@ github.com/whosonfirst/go-writer v0.4.1 h1:pAZ/cwaCM129PfwYy28ggCIRfL98OkrYxNnAx github.com/whosonfirst/go-writer v0.4.1/go.mod h1:kFzhremCFtnkJdmviwJEPLFYKQ5+vq6ocJPxt1bHPFY= github.com/whosonfirst/go-writer-featurecollection v0.0.1 h1:C2FkK1xUM3JVNpAYRTM4SP2j7z+AaihvgQu84ViUfTk= github.com/whosonfirst/go-writer-featurecollection v0.0.1/go.mod h1:JyV2uXLdyooDuP57nA8qe1u6akPIP08wFnaOBzQNlok= +github.com/whosonfirst/go-writer-featurecollection v0.0.2 h1:M6TcLVXL1eMRMScURHy1VrxA715wbwBddc6MR7gAyN0= +github.com/whosonfirst/go-writer-featurecollection v0.0.2/go.mod h1:JyV2uXLdyooDuP57nA8qe1u6akPIP08wFnaOBzQNlok= github.com/whosonfirst/walk v0.0.1 h1:t0QrqGwOdPMSeovFZSXfiS0GIGHrRXK3Wb9z5Uhs2bg= github.com/whosonfirst/walk v0.0.1/go.mod h1:1KtP/VeooSlFOI61p+THc/C16Ra8Z5MjpjI0tsd3c1M= github.com/whosonfirst/warning v0.1.0 h1:NgMa6a6Xv7FdDNgpqK5j/FDo6qrcFzFtidAExDqPfC0= diff --git a/vendor/github.com/sfomuseum/go-flags/multi/int.go b/vendor/github.com/sfomuseum/go-flags/multi/int.go index c99f16d..fda94e5 100644 --- a/vendor/github.com/sfomuseum/go-flags/multi/int.go +++ b/vendor/github.com/sfomuseum/go-flags/multi/int.go @@ -5,6 +5,47 @@ import ( "strings" ) +type MultiInt []int + +func (m *MultiInt) String() string { + + str_values := make([]string, len(*m)) + + for i, v := range *m { + str_values[i] = strconv.Itoa(v) + } + + return strings.Join(str_values, "\n") +} + +func (m *MultiInt) Set(str_value string) error { + + value, err := strconv.Atoi(str_value) + + if err != nil { + return err + } + + *m = append(*m, value) + return nil +} + +func (m *MultiInt) Get() interface{} { + return *m +} + +func (m *MultiInt) Contains(value int) bool { + + for _, test := range *m { + + if test == value { + return true + } + } + + return false +} + type MultiInt64 []int64 func (m *MultiInt64) String() string { diff --git a/vendor/github.com/tidwall/gjson/README.md b/vendor/github.com/tidwall/gjson/README.md index 8553273..5562014 100644 --- a/vendor/github.com/tidwall/gjson/README.md +++ b/vendor/github.com/tidwall/gjson/README.md @@ -14,6 +14,8 @@ It has features such as [one line retrieval](#get-a-value), [dot notation paths] Also check out [SJSON](https://github.com/tidwall/sjson) for modifying json, and the [JJ](https://github.com/tidwall/jj) command line tool. +For the Rust version go to [gjson.rs](https://github.com/tidwall/gjson.rs). + Getting Started =============== @@ -482,11 +484,3 @@ widget.text.onMouseUp ``` *These benchmarks were run on a MacBook Pro 15" 2.8 GHz Intel Core i7 using Go 1.8 and can be found [here](https://github.com/tidwall/gjson-benchmarks).* - - -## Contact -Josh Baker [@tidwall](http://twitter.com/tidwall) - -## License - -GJSON source code is available under the MIT [License](/LICENSE). diff --git a/vendor/github.com/tidwall/gjson/SYNTAX.md b/vendor/github.com/tidwall/gjson/SYNTAX.md index 5ea0407..86235b9 100644 --- a/vendor/github.com/tidwall/gjson/SYNTAX.md +++ b/vendor/github.com/tidwall/gjson/SYNTAX.md @@ -77,14 +77,21 @@ Special purpose characters, such as `.`, `*`, and `?` can be escaped with `\`. fav\.movie "Deer Hunter" ``` -You'll also need to make sure that the `\` character is correctly escaped when hardcoding a path in source code. +You'll also need to make sure that the `\` character is correctly escaped when hardcoding a path in you source code. ```go -res := gjson.Get(json, "fav\\.movie") // must escape the slash -res := gjson.Get(json, `fav\.movie`) // no need to escape the slash +// Go +val := gjson.Get(json, "fav\\.movie") // must escape the slash +val := gjson.Get(json, `fav\.movie`) // no need to escape the slash +``` +```rust +// Rust +let val = gjson::get(json, "fav\\.movie") // must escape the slash +let val = gjson::get(json, r#"fav\.movie"#) // no need to escape the slash ``` + ### Arrays The `#` character allows for digging into JSON Arrays. @@ -248,6 +255,8 @@ gjson.AddModifier("case", func(json, arg string) string { "children.@case:lower.@reverse" ["jack","alex","sara"] ``` +*Note: Custom modifiers are not yet available in the Rust version* + ### Multipaths Starting with v1.3.0, GJSON added the ability to join multiple paths together diff --git a/vendor/github.com/tidwall/gjson/gjson.go b/vendor/github.com/tidwall/gjson/gjson.go index 4f988d0..7bb82e9 100644 --- a/vendor/github.com/tidwall/gjson/gjson.go +++ b/vendor/github.com/tidwall/gjson/gjson.go @@ -731,8 +731,13 @@ func parseArrayPath(path string) (r arrayPathResult) { } if path[i] == '.' { r.part = path[:i] - r.path = path[i+1:] - r.more = true + if !r.arrch && i < len(path)-1 && isDotPiperChar(path[i+1]) { + r.pipe = path[i+1:] + r.piped = true + } else { + r.path = path[i+1:] + r.more = true + } return } if path[i] == '#' { @@ -978,6 +983,11 @@ right: return s } +// peek at the next byte and see if it's a '@', '[', or '{'. +func isDotPiperChar(c byte) bool { + return !DisableModifiers && (c == '@' || c == '[' || c == '{') +} + type objectPathResult struct { part string path string @@ -996,12 +1006,8 @@ func parseObjectPath(path string) (r objectPathResult) { return } if path[i] == '.' { - // peek at the next byte and see if it's a '@', '[', or '{'. r.part = path[:i] - if !DisableModifiers && - i < len(path)-1 && - (path[i+1] == '@' || - path[i+1] == '[' || path[i+1] == '{') { + if i < len(path)-1 && isDotPiperChar(path[i+1]) { r.pipe = path[i+1:] r.piped = true } else { @@ -1031,14 +1037,11 @@ func parseObjectPath(path string) (r objectPathResult) { continue } else if path[i] == '.' { r.part = string(epart) - // peek at the next byte and see if it's a '@' modifier - if !DisableModifiers && - i < len(path)-1 && path[i+1] == '@' { + if i < len(path)-1 && isDotPiperChar(path[i+1]) { r.pipe = path[i+1:] r.piped = true } else { r.path = path[i+1:] - r.more = true } r.more = true return @@ -1403,7 +1406,6 @@ func parseArray(c *parseContext, i int, path string) (int, bool) { } return false } - for i < len(c.json)+1 { if !rp.arrch { pmatch = partidx == h @@ -1605,10 +1607,17 @@ func parseArray(c *parseContext, i int, path string) (int, bool) { c.calcd = true return i + 1, true } - if len(multires) > 0 && !c.value.Exists() { - c.value = Result{ - Raw: string(append(multires, ']')), - Type: JSON, + if !c.value.Exists() { + if len(multires) > 0 { + c.value = Result{ + Raw: string(append(multires, ']')), + Type: JSON, + } + } else if rp.query.all { + c.value = Result{ + Raw: "[]", + Type: JSON, + } } } return i + 1, false @@ -2173,11 +2182,6 @@ func parseAny(json string, i int, hit bool) (int, Result, bool) { return i, res, false } -var ( // used for testing - testWatchForFallback bool - testLastWasFallback bool -) - // GetMany searches json for the multiple paths. // The return value is a Result array where the number of items // will be equal to the number of input paths. @@ -2378,6 +2382,12 @@ func validnumber(data []byte, i int) (outi int, ok bool) { // sign if data[i] == '-' { i++ + if i == len(data) { + return i, false + } + if data[i] < '0' || data[i] > '9' { + return i, false + } } // int if i == len(data) { @@ -2528,7 +2538,10 @@ func parseInt(s string) (n int64, ok bool) { return n, true } +// safeInt validates a given JSON number +// ensures it lies within the minimum and maximum representable JSON numbers func safeInt(f float64) (n int64, ok bool) { + // https://tc39.es/ecma262/#sec-number.min_safe_integer || https://tc39.es/ecma262/#sec-number.max_safe_integer if f < -9007199254740991 || f > 9007199254740991 { return 0, false } @@ -2739,19 +2752,24 @@ func modFlatten(json, arg string) string { out = append(out, '[') var idx int res.ForEach(func(_, value Result) bool { - if idx > 0 { - out = append(out, ',') - } + var raw string if value.IsArray() { if deep { - out = append(out, unwrap(modFlatten(value.Raw, arg))...) + raw = unwrap(modFlatten(value.Raw, arg)) } else { - out = append(out, unwrap(value.Raw)...) + raw = unwrap(value.Raw) } } else { - out = append(out, value.Raw...) + raw = value.Raw + } + raw = strings.TrimSpace(raw) + if len(raw) > 0 { + if idx > 0 { + out = append(out, ',') + } + out = append(out, raw...) + idx++ } - idx++ return true }) out = append(out, ']') diff --git a/vendor/github.com/tidwall/gjson/go.mod b/vendor/github.com/tidwall/gjson/go.mod index 30d1804..9853a30 100644 --- a/vendor/github.com/tidwall/gjson/go.mod +++ b/vendor/github.com/tidwall/gjson/go.mod @@ -4,5 +4,5 @@ go 1.12 require ( github.com/tidwall/match v1.0.3 - github.com/tidwall/pretty v1.0.2 + github.com/tidwall/pretty v1.1.0 ) diff --git a/vendor/github.com/tidwall/gjson/go.sum b/vendor/github.com/tidwall/gjson/go.sum index 1eb2014..739d132 100644 --- a/vendor/github.com/tidwall/gjson/go.sum +++ b/vendor/github.com/tidwall/gjson/go.sum @@ -1,6 +1,4 @@ -github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc= -github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E= github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE= github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= -github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU= -github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/tidwall/pretty v1.1.0 h1:K3hMW5epkdAVwibsQEfR/7Zj0Qgt4DxtNumTq/VloO8= +github.com/tidwall/pretty v1.1.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= diff --git a/vendor/github.com/tidwall/pretty/.travis.yml b/vendor/github.com/tidwall/pretty/.travis.yml deleted file mode 100644 index 4f2ee4d..0000000 --- a/vendor/github.com/tidwall/pretty/.travis.yml +++ /dev/null @@ -1 +0,0 @@ -language: go diff --git a/vendor/github.com/tidwall/pretty/README.md b/vendor/github.com/tidwall/pretty/README.md index 0988469..7a61422 100644 --- a/vendor/github.com/tidwall/pretty/README.md +++ b/vendor/github.com/tidwall/pretty/README.md @@ -1,8 +1,6 @@ # Pretty -[![Build Status](https://img.shields.io/travis/tidwall/pretty.svg?style=flat-square)](https://travis-ci.org/tidwall/prettty) -[![Coverage Status](https://img.shields.io/badge/coverage-100%25-brightgreen.svg?style=flat-square)](http://gocover.io/github.com/tidwall/pretty) -[![GoDoc](https://img.shields.io/badge/api-reference-blue.svg?style=flat-square)](https://pkg.go.dev/github.com/tidwall/pretty) +[![GoDoc](https://img.shields.io/badge/api-reference-blue.svg?style=flat-square)](https://pkg.go.dev/github.com/tidwall/pretty) Pretty is a Go package that provides [fast](#performance) methods for formatting JSON for human readability, or to compact JSON for smaller payloads. @@ -81,6 +79,45 @@ Will format the json to: {"name":{"first":"Tom","last":"Anderson"},"age":37,"children":["Sara","Alex","Jack"],"fav.movie":"Deer Hunter","friends":[{"first":"Janet","last":"Murphy","age":44}]}``` ``` +## Spec + +Spec cleans comments and trailing commas from input JSON, converting it to +valid JSON per the official spec: https://tools.ietf.org/html/rfc8259 + +The resulting JSON will always be the same length as the input and it will +include all of the same line breaks at matching offsets. This is to ensure +the result can be later processed by a external parser and that that +parser will report messages or errors with the correct offsets. + +The following example uses a JSON document that has comments and trailing +commas and converts it prior to unmarshalling to using the standard Go +JSON library. + +```go + +data := ` +{ + /* Dev Machine */ + "dbInfo": { + "host": "localhost", + "port": 5432, // use full email address + "username": "josh", + "password": "pass123", // use a hashed password + } + /* Only SMTP Allowed */ + "emailInfo": { + "email": "josh@example.com", + "password": "pass123", + "smtp": "smpt.example.com", + } +} +` + +err := json.Unmarshal(pretty.Spec(data), &config) + +``` + + ## Customized output diff --git a/vendor/github.com/tidwall/pretty/pretty.go b/vendor/github.com/tidwall/pretty/pretty.go index 2951c61..7fa9d63 100644 --- a/vendor/github.com/tidwall/pretty/pretty.go +++ b/vendor/github.com/tidwall/pretty/pretty.go @@ -118,21 +118,27 @@ type pair struct { vstart, vend int } -type byKey struct { +type byKeyVal struct { sorted bool json []byte pairs []pair } -func (arr *byKey) Len() int { +func (arr *byKeyVal) Len() int { return len(arr.pairs) } -func (arr *byKey) Less(i, j int) bool { +func (arr *byKeyVal) Less(i, j int) bool { key1 := arr.json[arr.pairs[i].kstart+1 : arr.pairs[i].kend-1] key2 := arr.json[arr.pairs[j].kstart+1 : arr.pairs[j].kend-1] - return string(key1) < string(key2) + if string(key1) < string(key2) { + return true + } + if string(key1) > string(key2) { + return false + } + return arr.pairs[i].vstart < arr.pairs[j].vstart } -func (arr *byKey) Swap(i, j int) { +func (arr *byKeyVal) Swap(i, j int) { arr.pairs[i], arr.pairs[j] = arr.pairs[j], arr.pairs[i] arr.sorted = true } @@ -174,7 +180,11 @@ func appendPrettyObject(buf, json []byte, i int, open, close byte, pretty bool, } if n > 0 { nl = len(buf) - buf = append(buf, '\n') + if buf[nl-1] == ' ' { + buf[nl-1] = '\n' + } else { + buf = append(buf, '\n') + } } if buf[len(buf)-1] != open { buf = appendTabs(buf, prefix, indent, tabs) @@ -193,7 +203,11 @@ func appendPrettyObject(buf, json []byte, i int, open, close byte, pretty bool, var p pair if pretty { nl = len(buf) - buf = append(buf, '\n') + if buf[nl-1] == ' ' { + buf[nl-1] = '\n' + } else { + buf = append(buf, '\n') + } if open == '{' && sortkeys { p.kstart = i p.vstart = len(buf) @@ -235,8 +249,8 @@ func sortPairs(json, buf []byte, pairs []pair) []byte { } vstart := pairs[0].vstart vend := pairs[len(pairs)-1].vend - arr := byKey{false, json, pairs} - sort.Sort(&arr) + arr := byKeyVal{false, json, pairs} + sort.Stable(&arr) if !arr.sorted { return buf } @@ -305,6 +319,7 @@ func appendTabs(buf []byte, prefix, indent string, tabs int) []byte { type Style struct { Key, String, Number [2]string True, False, Null [2]string + Escape [2]string Append func(dst []byte, c byte) []byte } @@ -328,6 +343,7 @@ func init() { True: [2]string{"\x1B[96m", "\x1B[0m"}, False: [2]string{"\x1B[96m", "\x1B[0m"}, Null: [2]string{"\x1B[91m", "\x1B[0m"}, + Escape: [2]string{"\x1B[35m", "\x1B[0m"}, Append: func(dst []byte, c byte) []byte { if c < ' ' && (c != '\r' && c != '\n' && c != '\t' && c != '\v') { dst = append(dst, "\\u00"...) @@ -367,8 +383,39 @@ func Color(src []byte, style *Style) []byte { dst = append(dst, style.String[0]...) } dst = apnd(dst, '"') + esc := false + uesc := 0 for i = i + 1; i < len(src); i++ { - dst = apnd(dst, src[i]) + if src[i] == '\\' { + if key { + dst = append(dst, style.Key[1]...) + } else { + dst = append(dst, style.String[1]...) + } + dst = append(dst, style.Escape[0]...) + dst = apnd(dst, src[i]) + esc = true + if i+1 < len(src) && src[i+1] == 'u' { + uesc = 5 + } else { + uesc = 1 + } + } else if esc { + dst = apnd(dst, src[i]) + if uesc == 1 { + esc = false + dst = append(dst, style.Escape[1]...) + if key { + dst = append(dst, style.Key[0]...) + } else { + dst = append(dst, style.String[0]...) + } + } else { + uesc-- + } + } else { + dst = apnd(dst, src[i]) + } if src[i] == '"' { j := i - 1 for ; ; j-- { @@ -381,7 +428,9 @@ func Color(src []byte, style *Style) []byte { } } } - if key { + if esc { + dst = append(dst, style.Escape[1]...) + } else if key { dst = append(dst, style.Key[1]...) } else { dst = append(dst, style.String[1]...) @@ -434,3 +483,90 @@ func Color(src []byte, style *Style) []byte { } return dst } + +// Spec strips out comments and trailing commas and convert the input to a +// valid JSON per the official spec: https://tools.ietf.org/html/rfc8259 +// +// The resulting JSON will always be the same length as the input and it will +// include all of the same line breaks at matching offsets. This is to ensure +// the result can be later processed by a external parser and that that +// parser will report messages or errors with the correct offsets. +func Spec(src []byte) []byte { + return spec(src, nil) +} + +// SpecInPlace is the same as Spec, but this method reuses the input json +// buffer to avoid allocations. Do not use the original bytes slice upon return. +func SpecInPlace(src []byte) []byte { + return spec(src, src) +} + +func spec(src, dst []byte) []byte { + dst = dst[:0] + for i := 0; i < len(src); i++ { + if src[i] == '/' { + if i < len(src)-1 { + if src[i+1] == '/' { + dst = append(dst, ' ', ' ') + i += 2 + for ; i < len(src); i++ { + if src[i] == '\n' { + dst = append(dst, '\n') + break + } else if src[i] == '\t' || src[i] == '\r' { + dst = append(dst, src[i]) + } else { + dst = append(dst, ' ') + } + } + continue + } + if src[i+1] == '*' { + dst = append(dst, ' ', ' ') + i += 2 + for ; i < len(src)-1; i++ { + if src[i] == '*' && src[i+1] == '/' { + dst = append(dst, ' ', ' ') + i++ + break + } else if src[i] == '\n' || src[i] == '\t' || + src[i] == '\r' { + dst = append(dst, src[i]) + } else { + dst = append(dst, ' ') + } + } + continue + } + } + } + dst = append(dst, src[i]) + if src[i] == '"' { + for i = i + 1; i < len(src); i++ { + dst = append(dst, src[i]) + if src[i] == '"' { + j := i - 1 + for ; ; j-- { + if src[j] != '\\' { + break + } + } + if (j-i)%2 != 0 { + break + } + } + } + } else if src[i] == '}' || src[i] == ']' { + for j := len(dst) - 2; j >= 0; j-- { + if dst[j] <= ' ' { + continue + } + if dst[j] == ',' { + dst[j] = ' ' + } + break + } + } + } + return dst +} diff --git a/vendor/github.com/whosonfirst/go-writer-featurecollection/README.md b/vendor/github.com/whosonfirst/go-writer-featurecollection/README.md index e98f1e8..c93bec3 100644 --- a/vendor/github.com/whosonfirst/go-writer-featurecollection/README.md +++ b/vendor/github.com/whosonfirst/go-writer-featurecollection/README.md @@ -1,5 +1,6 @@ # go-writer-featurecollection +GeoJSON FeatureCollection output handler for the go-writer Writer interface. ## Important @@ -7,4 +8,4 @@ This is work in progress. Documentation to follow. ## See also -* https://github.com/whosonfirst/go-writer \ No newline at end of file +* https://github.com/whosonfirst/go-writer diff --git a/vendor/github.com/whosonfirst/go-writer-featurecollection/featurecollection.go b/vendor/github.com/whosonfirst/go-writer-featurecollection/featurecollection.go index 1b247b3..d776c9b 100644 --- a/vendor/github.com/whosonfirst/go-writer-featurecollection/featurecollection.go +++ b/vendor/github.com/whosonfirst/go-writer-featurecollection/featurecollection.go @@ -103,7 +103,13 @@ func (fc *FeatureCollectionWriter) WriterURI(ctx context.Context, str_uri string func (fc *FeatureCollectionWriter) Close(ctx context.Context) error { - sr := strings.NewReader("]}") + body := `]}` + + if atomic.LoadInt64(&fc.count) == 0 { + body = `{"type":"FeatureCollection", "features":[]}` + } + + sr := strings.NewReader(body) _, err := fc.writer.Write(ctx, "", sr) if err != nil { diff --git a/vendor/modules.txt b/vendor/modules.txt index 947f56d..28d8bbb 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -43,17 +43,17 @@ github.com/sfomuseum/go-edtf/level2 github.com/sfomuseum/go-edtf/parser github.com/sfomuseum/go-edtf/re github.com/sfomuseum/go-edtf/tests -# github.com/sfomuseum/go-flags v0.7.0 +# github.com/sfomuseum/go-flags v0.8.2 ## explicit github.com/sfomuseum/go-flags/multi # github.com/skelterjohn/geom v0.0.0-20180103142417-96f3e8a219c5 github.com/skelterjohn/geom -# github.com/tidwall/gjson v1.6.8 +# github.com/tidwall/gjson v1.7.4 ## explicit github.com/tidwall/gjson # github.com/tidwall/match v1.0.3 github.com/tidwall/match -# github.com/tidwall/pretty v1.0.2 +# github.com/tidwall/pretty v1.1.0 github.com/tidwall/pretty # github.com/tidwall/sjson v1.1.5 ## explicit @@ -111,7 +111,7 @@ github.com/whosonfirst/go-whosonfirst-writer # github.com/whosonfirst/go-writer v0.4.1 ## explicit github.com/whosonfirst/go-writer -# github.com/whosonfirst/go-writer-featurecollection v0.0.1 +# github.com/whosonfirst/go-writer-featurecollection v0.0.2 ## explicit github.com/whosonfirst/go-writer-featurecollection # github.com/whosonfirst/walk v0.0.1