github.com/pgavlin/text@v0.0.0-20240419000839-8438d0a47805/compare.go (about) 1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package text 6 7 import "github.com/pgavlin/text/internal/bytealg" 8 9 // Compare returns an integer comparing two strings lexicographically. 10 // The result will be 0 if a == b, -1 if a < b, and +1 if a > b. 11 // 12 // Compare is included only for symmetry with package bytes. 13 // It is usually clearer and always faster to use the built-in 14 // string comparison operators ==, <, >, and so on. 15 func Compare[S1, S2 String](a S1, b S2) int { 16 return bytealg.Compare(a, b) 17 } 18 19 // Equal compares two strings for equality. 20 func Equal[S1, S2 String](a S1, b S2) bool { 21 return bytealg.AsString(a) == bytealg.AsString(b) 22 }