Commit 6cc94a06e9fe55808badb616b9e8605ba275a7a4

Authored by Marko Tikvić
1 parent 5d0856f6f3
Exists in master

cleanup

Showing 1 changed file with 16 additions and 23 deletions   Show diff stats
... ... @@ -5,6 +5,8 @@ import (
5 5 "strconv"
6 6 "strings"
7 7 "unicode"
  8 +
  9 + "golang.org/x/exp/utf8string"
8 10 )
9 11  
10 12 const sanitisationPatern = "\"';&*<>=\\`:"
... ... @@ -112,6 +114,15 @@ func StringAt(s string, index int) string {
112 114 return string(s[index])
113 115 }
114 116  
  117 +func StringAtRune(s string, index int) string {
  118 + str := utf8string.NewString(s)
  119 + max := str.RuneCount()
  120 + if index < max {
  121 + return string(str.At(index))
  122 + }
  123 + return ""
  124 +}
  125 +
115 126 // SplitText ...
116 127 func SplitText(s string, maxLen int) (lines []string) {
117 128 runes := []rune(s)
... ... @@ -149,38 +160,20 @@ func SplitText(s string, maxLen int) (lines []string) {
149 160 return lines
150 161 }
151 162  
152   -func CutTextWithThreeDots(txt string, maxLen int) string {
153   - if len(txt) < maxLen || len(txt) <= 3 {
154   - return txt
155   - }
156   -
157   - return txt[:maxLen-3] + "..."
158   -}
159   -
160   -const threeDots = "\u2056\u2056\u2056"
161   -
162   -func LimitTextWithThreeDots(txt string, maxLen int) string {
163   - if len(txt) <= maxLen {
164   - return txt
165   - }
166   -
167   - return txt[:maxLen] + threeDots
168   -}
169   -
170   -func LimitMSWordTextWithThreeDots(txt string, maxLen int) string {
171   - if len(txt) <= maxLen {
  163 +func CutTextWith(txt string, maxLen int, tail string) string {
  164 + if len(txt) < maxLen || len(txt) <= len(tail) {
172 165 return txt
173 166 }
174 167  
175   - return txt[:maxLen] + "..."
  168 + return txt[:maxLen-3] + tail
176 169 }
177 170  
178   -func ThreeDots(txt string, maxLen int) string {
  171 +func LimitTextWith(txt string, maxLen int, tail string) string {
179 172 if len(txt) <= maxLen {
180 173 return txt
181 174 }
182 175  
183   - return txt[:maxLen] + "..."
  176 + return txt[:maxLen] + tail
184 177 }
185 178  
186 179 // SplitStringAtWholeWords ...
... ...