go-chatwords

Parse line as chat words

MIT License

Stars
1

go-chatwords

Parse line as chat words.

This package is inspired to github.com/mattn/go-shellwords.

Motivation

To develop a chat bot, it is useful to split a string into substrings. There are many awesome packages for cli tool, but it is out of scope for many of them to split a string into substrings. And some existing packages are made for shell, so they are inapropriate for the chat bot in terms of treat of special characters.

Usage

// ["<UXXXXX>", "echo", "hello world"], ""
args, text := chatwords.Split("<UXXXXX> echo 'hello world'", -1)
// ["<UXXXXX>", "echo"], " 'hello world'"
args, text := chatwords.Split("<UXXXXX> echo 'hello world'", 2)

The test code is also useful to understand this package's behavior.

Rules to split

special characters

  • quote: ', "
  • space: , \t
  • escape: \\

This package is not for shell, so the number of special characters is very small.

License

MIT

Package Rankings
Top 8.57% on Proxy.golang.org
Badges
Extracted from project README
go.dev Build Status codecov Go Report Card GitHub last commit License