Created
November 9, 2019 00:31
-
-
Save as/8181621f04f6792d0be72f45e7860e7a to your computer and use it in GitHub Desktop.
whitespace ignoring string comparison (draft)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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