-
Notifications
You must be signed in to change notification settings - Fork 0
/
text.go
38 lines (35 loc) · 764 Bytes
/
text.go
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
package save
import (
"fmt"
)
type Text struct {
Text string
Link string
Date string
Media string
FlagLink bool
FlagDate bool
}
func (t Text) Gen(size int) string {
tweetText := t.Text
var appendText string
if t.Media != "" {
appendText += fmt.Sprintf("\n%s", t.Media)
}
if t.FlagLink {
appendText += fmt.Sprintf("\n%s", t.Link)
}
if t.FlagDate {
appendText += fmt.Sprintf("\n%s", t.Date)
}
if len([]byte(tweetText))+len([]byte(appendText)) > size {
if len([]byte(appendText)) > size/2 {
appendText = appendText[:size/2] + "..."
}
trim := size-len([]byte(appendText))-3
if trim > 0 && trim < len([]byte(tweetText)) {
tweetText = string([]byte(tweetText)[:trim]) + "..."
}
}
return tweetText + appendText
}