blob: c1bd8a48ec70b1dc0feb2b5fcc8cdd1b13c985f4 (
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
package utils
import (
"os"
)
// Repeats a rune given amount of times and returns the result as a string
func RepeatRune(r rune, times int) (result string) {
for i := 0; i < times; i++ {
result += string(r)
}
return
}
// Replaces a character inside a string with a given rune at index
//
// Thanks https://stackoverflow.com/a/24894202/12036073
func ReplaceAtIndex(in string, r rune, i int) string {
out := []rune(in)
out[i] = r
return string(out)
}
func TwoDByteArrayToStringArray(in [][]byte) (result []string) {
for _, v := range in {
result = append(result, string(v))
}
return
}
func AppendToFile(path string, value string) {
allChatsFile, _ := os.OpenFile(path, os.O_APPEND|os.O_WRONLY, 0644)
allChatsFile.WriteString(value)
allChatsFile.Close()
}
func TotalPages(maxSize int, messageAmount int) int {
return messageAmount / maxSize
}
func Paginate(page int, maxSize int, messages ...string) []string {
return messages[len(messages)-maxSize*page : len(messages)-maxSize*(page-1)]
}
|