You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
  2. // released under the MIT license
  3. package irc
  4. // argsToStrings takes the arguments and splits them into a series of strings,
  5. // each argument separated by delim and each string bounded by maxLength.
  6. func argsToStrings(maxLength int, arguments []string, delim string) []string {
  7. var messages []string
  8. var buffer string
  9. for {
  10. if len(arguments) < 1 {
  11. break
  12. }
  13. if len(buffer) > 0 && maxLength < len(buffer)+len(delim)+len(arguments[0]) {
  14. messages = append(messages, buffer)
  15. buffer = ""
  16. continue
  17. }
  18. if len(buffer) > 1 {
  19. buffer += delim
  20. }
  21. buffer += arguments[0]
  22. arguments = arguments[1:]
  23. }
  24. if len(buffer) > 0 {
  25. messages = append(messages, buffer)
  26. }
  27. return messages
  28. }