blob: 4b61d36803c6822da0309357a9e92b052a6023cd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
defmodule Nola.Irc.Message do
@max_chars 440
def splitlong(string, max_chars \\ 440)
def splitlong(string, max_chars) when is_list(string) do
Enum.map(string, fn s -> splitlong(s, max_chars) end)
|> List.flatten()
end
def splitlong(string, max_chars) do
string
|> String.codepoints()
|> Enum.chunk_every(max_chars)
|> Enum.map(&Enum.join/1)
end
def splitlong_with_prefix(string, prefix, max_chars \\ 440) do
prefix = "#{prefix} "
max_chars = max_chars - length(String.codepoints(prefix))
string
|> String.codepoints()
|> Enum.chunk_every(max_chars)
|> Enum.map(fn line -> prefix <> Enum.join(line) end)
end
end
|