Skip to content

Instantly share code, notes, and snippets.

@koduki
Created June 27, 2019 08:10
Show Gist options
  • Select an option

  • Save koduki/5776e4ffc92cb057efce9e6a7087d98d to your computer and use it in GitHub Desktop.

Select an option

Save koduki/5776e4ffc92cb057efce9e6a7087d98d to your computer and use it in GitHub Desktop.
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