...

Package collate

import "github.com/go-kivik/kivik/v4/x/collate"
Overview
Index

Overview ▾

Package collate provides (near) CouchDB-compatible collation functions.

The collation order provided by this package differs slightly from that described by the CouchDB documentation. In particular:

  • The Unicode UCI algorithm supported natively by Go sorts the backtick (`) and caret (^) after other symbols, not before.
  • Because Go's maps are unordered, this implementation does not honor the order of object key members when collating. That is to say, the object `{b:2,a:1}` is treated as equivalent to `{a:1,b:2}` for collation purposes. This is tracked in issue #952. Please leave a comment there if this is affecting you.

func CompareObject

func CompareObject(a, b interface{}) int

CompareObject compares two unmarshaled JSON objects. The function will panic if it encounters an unexpected type. The comparison is performed recursively, with keys sorted before comparison. The result will be 0 if a==b, -1 if a < b, and +1 if a > b.

func CompareString

func CompareString(a, b string) int

CompareString returns an integer comparing the two strings. The result will be 0 if a==b, -1 if a < b, and +1 if a > b.