package shlex
Import Path
github.com/anmitsu/go-shlex (on go.dev)
Dependency Relation
imports 5 packages, and imported by one package
Involved Source Files
Package shlex provides a simple lexical analysis like Unix shell.
Code Examples
{
cmd := `cp -Rdp "file name" 'file name2' dir\ name`
words1, err := shlex.Split(cmd, true)
if err != nil {
log.Fatal(err)
}
words2, err := shlex.Split(cmd, false)
if err != nil {
log.Fatal(err)
}
fmt.Println("Source command:")
fmt.Println(`cp -Rdp "file name" 'file name2' dir\ name`)
fmt.Println()
fmt.Println("POSIX mode:")
for _, word := range words1 {
fmt.Println(word)
}
fmt.Println()
fmt.Println("Non-POSIX mode:")
for _, word := range words2 {
fmt.Println(word)
}
}
Package-Level Type Names (total 3)
DefaultTokenizer implements a simple tokenizer like Unix shell.
(*DefaultTokenizer) IsEscape(r rune) bool
(*DefaultTokenizer) IsEscapedQuote(r rune) bool
(*DefaultTokenizer) IsQuote(r rune) bool
(*DefaultTokenizer) IsWhitespace(r rune) bool
(*DefaultTokenizer) IsWord(r rune) bool
*DefaultTokenizer : Tokenizer
Lexer represents a lexical analyzer.
SetTokenizer sets a Tokenizer.
(*Lexer) Split() ([]string, error)
func NewLexer(r io.Reader, posix, whitespacesplit bool) *Lexer
func NewLexerString(s string, posix, whitespacesplit bool) *Lexer
Tokenizer is the interface that classifies a token according to
words, whitespaces, quotations, escapes and escaped quotations.
( Tokenizer) IsEscape(rune) bool
( Tokenizer) IsEscapedQuote(rune) bool
( Tokenizer) IsQuote(rune) bool
( Tokenizer) IsWhitespace(rune) bool
( Tokenizer) IsWord(rune) bool
*DefaultTokenizer
func (*Lexer).SetTokenizer(t Tokenizer)
Package-Level Functions (total 3)
NewLexer creates a new Lexer reading from io.Reader. This Lexer
has a DefaultTokenizer according to posix and whitespacesplit
rules.
NewLexerString creates a new Lexer reading from a string. This
Lexer has a DefaultTokenizer according to posix and whitespacesplit
rules.
Split splits a string according to posix or non-posix rules.
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |