mirror of
https://github.com/ergochat/ergo.git
synced 2025-12-20 02:00:11 -08:00
consolidate ArgsToStrings
This commit is contained in:
parent
0c9ecbade7
commit
ec375f5bdc
5 changed files with 22 additions and 42 deletions
|
|
@ -18,37 +18,6 @@ var (
|
|||
ErrInvalidParams = errors.New("Invalid parameters")
|
||||
)
|
||||
|
||||
// ArgsToStrings takes the arguments and splits them into a series of strings,
|
||||
// each argument separated by delim and each string bounded by maxLength.
|
||||
func ArgsToStrings(maxLength int, arguments []string, delim string) []string {
|
||||
var messages []string
|
||||
|
||||
var buffer string
|
||||
for {
|
||||
if len(arguments) < 1 {
|
||||
break
|
||||
}
|
||||
|
||||
if len(buffer) > 0 && maxLength < len(buffer)+len(delim)+len(arguments[0]) {
|
||||
messages = append(messages, buffer)
|
||||
buffer = ""
|
||||
continue
|
||||
}
|
||||
|
||||
if len(buffer) > 0 {
|
||||
buffer += delim
|
||||
}
|
||||
buffer += arguments[0]
|
||||
arguments = arguments[1:]
|
||||
}
|
||||
|
||||
if len(buffer) > 0 {
|
||||
messages = append(messages, buffer)
|
||||
}
|
||||
|
||||
return messages
|
||||
}
|
||||
|
||||
func StringToBool(str string) (result bool, err error) {
|
||||
switch strings.ToLower(str) {
|
||||
case "on", "true", "t", "yes", "y", "enabled":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue