Skip to content

Instantly share code, notes, and snippets.

@as
Created November 9, 2019 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save as/8181621f04f6792d0be72f45e7860e7a to your computer and use it in GitHub Desktop.
Save as/8181621f04f6792d0be72f45e7860e7a to your computer and use it in GitHub Desktop.
whitespace ignoring string comparison (draft)
package main
import "fmt"
func main() {
fmt.Println(cmp("abc", " a db c "))
}
func cmp(a, b string) bool {
if len(a) < len(b) {
a, b = b, a
}
p, q := 0, 0
for p != len(a) && q != len(b) {
spool:
for p != len(a) && a[p] == ' ' {
p++
}
for q != len(b) && b[q] == ' ' {
q++
}
for p != len(a) && q != len(b) {
if a[p] == ' ' || b[q] == ' '{
goto spool
}
if a[p] != b[q] {
return false
}
p++
q++
}
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment