Created
June 27, 2019 08:10
-
-
Save koduki/5776e4ffc92cb057efce9e6a7087d98d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| func scan(str string)[]string { | |
| var head []string | |
| var tail string | |
| if str == "" { | |
| return []string{} | |
| }else{ | |
| x := string(str[0]) | |
| switch x { | |
| case "'": | |
| head, tail = splitQuote(str) | |
| case " ": | |
| head, tail = skipSpace(str) | |
| default: | |
| head, tail = splitSpace(str) | |
| } | |
| return append(head, scan(tail)...) | |
| } | |
| } | |
| func skipSpace(str string)([]string, string) { | |
| return []string {}, str[1:len(str)] | |
| } | |
| func splitSpace(str string)([]string, string) { | |
| head := "" | |
| tail := "" | |
| for i := 0; i < len(str); i++ { | |
| x := string(str[i]) | |
| if x == " " { | |
| tail = str[(i+1):len(str)] | |
| break | |
| } else { | |
| head += x | |
| } | |
| } | |
| return []string{head}, tail | |
| } | |
| func splitQuote(str string)([]string, string) { | |
| head := "" | |
| tail := "" | |
| for i := 1; i < len(str); i++ { | |
| x := string(str[i]) | |
| if x == "'" { | |
| tail = str[(i+2):len(str)] | |
| break | |
| } else { | |
| head += x | |
| } | |
| } | |
| return []string{head}, tail | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment