MCPcopy Create free account
hub / github.com/OpenPrinting/goipp / ValueSimilar

Function ValueSimilar

value.go:192–213  ·  view source on GitHub ↗

ValueSimilar checks if two values are **logically** equal, which means the following: - If values are equal (i.e., ValueEqual() returns true), they are similar. - Binary and String values are similar, if they represent the same sequence of bytes. - Two collections are similar, if they contain the sa

(v1, v2 Value)

Source from the content-addressed store, hash-verified

190// set of attributes (but may be differently ordered) and
191// values of these attributes are similar.
192func ValueSimilar(v1, v2 Value) bool {
193 if ValueEqual(v1, v2) {
194 return true
195 }
196
197 t1 := v1.Type()
198 t2 := v2.Type()
199
200 switch {
201 case t1 == TypeBinary && t2 == TypeString:
202 return bytes.Equal(v1.(Binary), []byte(v2.(String)))
203
204 case t1 == TypeString && t2 == TypeBinary:
205 return bytes.Equal([]byte(v1.(String)), v2.(Binary))
206
207 case t1 == TypeCollection && t2 == TypeCollection:
208 return Attributes(v1.(Collection)).Similar(
209 Attributes(v2.(Collection)))
210 }
211
212 return false
213}
214
215// Void is the Value that represents "no value"
216//

Callers 2

SimilarMethod · 0.85
TestValueEqualSimilarFunction · 0.85

Calls 5

ValueEqualFunction · 0.85
AttributesTypeAlias · 0.85
TypeMethod · 0.65
EqualMethod · 0.45
SimilarMethod · 0.45

Tested by 1

TestValueEqualSimilarFunction · 0.68