python 的 shlex.split Go 替代方案

python's shlex.split alternative for Go

简单的问题 - 有没有像 python 的 shlex.split 这样的东西可以让我简单地 parse/split/quote/escape shell-like quoted/backslashed 字符串?

Link 到 shlex 文档: http://docs.python.org/3.4/library/shlex.html

shlex.split 的作用示例:

>>> import shlex
>>> shlex.split('abc ab\ c  "ab\"cd" key="\"val\""')
['abc', 'ab c', 'ab"cd', 'key="val"']

标准库中没有任何内容,但 Google 确实发布了他们自己的 shlex library which has been forked and changed some in flynn-archive/go-shlex

例如:

package main

import (
    "fmt"
    "github.com/google/shlex"
)

func main() {
    input := "abc ab\ c  \"ab\\"cd\" key=\"\\"val\\"\""
    fmt.Println("Processing:", input)
    tokens, _ := shlex.Split(input)
    fmt.Printf("%#v\n", tokens)
    // []string{"abc", "ab c", "ab\"cd", "key=\"val\""}
}