aboutsummaryrefslogtreecommitdiffstats
path: root/util/text/text.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-12-23 20:47:18 +0100
committerMichael Muré <batolettre@gmail.com>2018-12-23 20:47:18 +0100
commit7454b9505ae2d680293d3d00d72df14f36f4e616 (patch)
tree7d7d0d00f57a264857ba7e086913203116d5a737 /util/text/text.go
parent261aa61711639cf98a9aa987e86377d520b8c868 (diff)
downloadgit-bug-7454b9505ae2d680293d3d00d72df14f36f4e616.tar.gz
text: more chinese related fixes
Diffstat (limited to 'util/text/text.go')
-rw-r--r--util/text/text.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/util/text/text.go b/util/text/text.go
index b41b892b..c000596c 100644
--- a/util/text/text.go
+++ b/util/text/text.go
@@ -58,7 +58,7 @@ func WrapLeftPadded(text string, lineWidth int, leftPad int) (string, int) {
} else {
// Break a word longer than a line
if wordLength > lineWidth {
- for wordLength > 0 && len(word) > 0 {
+ for wordLength > 0 && wordLen(word) > 0 {
l := minInt(spaceLeft, wordLength)
part, leftover := splitWord(word, l)
word = leftover
@@ -76,6 +76,10 @@ func WrapLeftPadded(text string, lineWidth int, leftPad int) (string, int) {
nbLine++
spaceLeft = lineWidth - leftPad
}
+
+ if wordLength <= 0 {
+ break
+ }
}
} else {
// Normal break
@@ -90,8 +94,11 @@ func WrapLeftPadded(text string, lineWidth int, leftPad int) (string, int) {
}
}
- textBuffer.WriteString(pad + strings.TrimRight(lineBuffer.String(), " "))
- lineBuffer.Reset()
+ if lineBuffer.Len() > 0 {
+ textBuffer.WriteString(pad + strings.TrimRight(lineBuffer.String(), " "))
+ lineBuffer.Reset()
+ }
+
firstLine = false
}