Skip to content

Commit

Permalink
Update json-gold to most recent master
Browse files Browse the repository at this point in the history
  • Loading branch information
olomix committed Dec 11, 2024
1 parent 8a3a954 commit fc059e4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ require (
// stable version. After the release of version 0.5.1 or later, it will be
// necessary to update to the stable version.
// https://github.com/piprate/json-gold/commit/36fcca9d7e487684a764e552e7d837a14546a157
github.com/piprate/json-gold v0.5.1-0.20230111113000-6ddbe6e6f19f
// and this
// https://github.com/piprate/json-gold/commit/19254b3ec65b01ad353de8412ae7ba10857258cf
github.com/piprate/json-gold v0.5.1-0.20241210232033-19254b3ec65b
github.com/pkg/errors v0.9.1
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35
github.com/santhosh-tekuri/jsonschema/v5 v5.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/piprate/json-gold v0.5.1-0.20230111113000-6ddbe6e6f19f h1:HlPa7RcxTCrva5izPfTEfvYecO7LTahgmMRD1Qp13xg=
github.com/piprate/json-gold v0.5.1-0.20230111113000-6ddbe6e6f19f/go.mod h1:WZ501QQMbZZ+3pXFPhQKzNwS1+jls0oqov3uQ2WasLs=
github.com/piprate/json-gold v0.5.1-0.20241210232033-19254b3ec65b h1:xyh6boGzDR4EpdEDe9ix1KhHNgOSiBjBocahA6FalEQ=
github.com/piprate/json-gold v0.5.1-0.20241210232033-19254b3ec65b/go.mod h1:RVhE35veDX19r5gfUAR+IYHkAUuPwJO8Ie/qVeFaIzw=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
21 changes: 6 additions & 15 deletions merklize/merklize.go
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ func convertAnyToString(value any, datatype string) (str string, err error) {
if err != nil {
return "", err
}
return getCanonicalDouble(f), nil
return ld.GetCanonicalDouble(f), nil
case int:
return intToXSDDoubleStr(v)
case int8:
Expand All @@ -1167,9 +1167,9 @@ func convertAnyToString(value any, datatype string) (str string, err error) {
switch v := value.(type) {
case float64:
// https://www.w3.org/TR/2014/REC-json-ld-api-20140116/#data-round-tripping
str = getCanonicalDouble(v)
str = ld.GetCanonicalDouble(v)
case float32:
str = getCanonicalDouble(float64(v))
str = ld.GetCanonicalDouble(float64(v))
case string:
str = fmt.Sprintf("%v", v)
case int64, int32, int16, int8, int, bool:
Expand Down Expand Up @@ -1198,7 +1198,7 @@ type allUInts interface {
// the same, which is not correct. That is why we use big.Rat here to check
// that float can represent integer value without loss of precision.
func intToXSDDoubleStr[T allInts](v T) (string, error) {
out := getCanonicalDouble(float64(v))
out := ld.GetCanonicalDouble(float64(v))

r := new(big.Rat)
_, ok := r.SetString(out)
Expand All @@ -1221,7 +1221,7 @@ func intToXSDDoubleStr[T allInts](v T) (string, error) {
// see comment for intToXSDDoubleStr for explanations why this function
// uses big.Rat
func uintToXSDDoubleStr[T allUInts](v T) (string, error) {
out := getCanonicalDouble(float64(v))
out := ld.GetCanonicalDouble(float64(v))

r := new(big.Rat)
_, ok := r.SetString(out)
Expand Down Expand Up @@ -1337,7 +1337,7 @@ func convertStringToXSDValue(datatype string, value string,
if err != nil {
return "", err
}
resultValue = getCanonicalDouble(f)
resultValue = ld.GetCanonicalDouble(f)

default:
resultValue = value
Expand All @@ -1346,15 +1346,6 @@ func convertStringToXSDValue(datatype string, value string,
return resultValue, err
}

var canonicalDoubleRegEx = regexp.MustCompile(`(\d)0*E\+?(-)?0*(\d)`)

// getCanonicalDouble: a temporary solution until this PR would be merged:
// https://github.com/piprate/json-gold/pull/78/files
// After that replace with ld.GetCanonicalDouble
func getCanonicalDouble(v float64) string {
return canonicalDoubleRegEx.ReplaceAllString(fmt.Sprintf("%1.15E", v), "${1}E${2}${3}")
}

// count number of entries with same key to distinguish between plain values
// and arrays (sets)
func countEntries(nodes []*ld.Quad) (map[qArrKey]int, error) {
Expand Down

0 comments on commit fc059e4

Please sign in to comment.