mirror of
https://github.com/jeremyd/ergo.git
synced 2026-04-26 23:49:59 -07:00
Split utils out to a separate subpackage
This commit is contained in:
35
irc/utils/args.go
Normal file
35
irc/utils/args.go
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
|
||||
// released under the MIT license
|
||||
|
||||
package utils
|
||||
|
||||
// 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) > 1 {
|
||||
buffer += delim
|
||||
}
|
||||
buffer += arguments[0]
|
||||
arguments = arguments[1:]
|
||||
}
|
||||
|
||||
if len(buffer) > 0 {
|
||||
messages = append(messages, buffer)
|
||||
}
|
||||
|
||||
return messages
|
||||
}
|
||||
Reference in New Issue
Block a user