diff options
author | Michael Muré <batolettre@gmail.com> | 2018-12-23 20:47:18 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-12-23 20:47:18 +0100 |
commit | 7454b9505ae2d680293d3d00d72df14f36f4e616 (patch) | |
tree | 7d7d0d00f57a264857ba7e086913203116d5a737 /util/text | |
parent | 261aa61711639cf98a9aa987e86377d520b8c868 (diff) | |
download | git-bug-7454b9505ae2d680293d3d00d72df14f36f4e616.tar.gz |
text: more chinese related fixes
Diffstat (limited to 'util/text')
-rw-r--r-- | util/text/text.go | 13 | ||||
-rw-r--r-- | util/text/text_test.go | 20 |
2 files changed, 27 insertions, 6 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 } diff --git a/util/text/text_test.go b/util/text/text_test.go index f37b4ce6..cf72431e 100644 --- a/util/text/text_test.go +++ b/util/text/text_test.go @@ -126,9 +126,18 @@ func TestWrapLeftPadded(t *testing.T) { { "The Lorem ipsum text is typically composed of pseudo-Latin words. It is commonly used as placeholder text to examine or demonstrate the visual effects of various graphic design.", ` The Lorem ipsum text is typically composed of - pseudo-Latin words. It is commonly used as placeholder - text to examine or demonstrate the visual effects of - various graphic design.`, + pseudo-Latin words. It is commonly used as placeholder + text to examine or demonstrate the visual effects of + various graphic design.`, + 59, 4, + }, + // Handle Chinese + { + "婞一枳郲逴靲屮蜧曀殳,掫乇峔掮傎溒兀緉冘仜。郼牪艽螗媷錵朸一詅掜豗怙刉笀丌,楀棶乇矹迡搦囷圣亍昄漚粁仈祂。覂一洳袶揙楱亍滻瘯毌,掗屮柅軡菵腩乜榵毌夯。勼哻怌婇怤灟葠雺奷朾恦扰衪岨坋誁乇芚誙腞。冇笉妺悆浂鱦賌廌灱灱觓坋佫呬耴跣兀枔蓔輈。嵅咍犴膰痭瘰机一靬涽捊矷尒玶乇,煚塈丌岰陊鉖怞戉兀甿跾觓夬侄。棩岧汌橩僁螗玎一逭舴圂衪扐衲兀,嵲媕亍衩衿溽昃夯丌侄蒰扂丱呤。毰侘妅錣廇螉仴一暀淖蚗佶庂咺丌,輀鈁乇彽洢溦洰氶乇构碨洐巿阹。", + ` 婞一枳郲逴靲屮蜧曀殳,掫乇峔掮傎溒兀緉冘仜。郼牪艽螗媷錵朸一詅掜豗怙刉笀丌,楀棶乇矹迡搦囷圣亍昄漚粁仈祂。覂一 + 洳袶揙楱亍滻瘯毌,掗屮柅軡菵腩乜榵毌夯。勼哻怌婇怤灟葠雺奷朾恦扰衪岨坋誁乇芚誙腞。冇笉妺悆浂鱦賌廌灱灱觓坋佫呬 + 耴跣兀枔蓔輈。嵅咍犴膰痭瘰机一靬涽捊矷尒玶乇,煚塈丌岰陊鉖怞戉兀甿跾觓夬侄。棩岧汌橩僁螗玎一逭舴圂衪扐衲兀,嵲 + 媕亍衩衿溽昃夯丌侄蒰扂丱呤。毰侘妅錣廇螉仴一暀淖蚗佶庂咺丌,輀鈁乇彽洢溦洰氶乇构碨洐巿阹。`, 59, 4, }, } @@ -239,6 +248,11 @@ func TestSplitWord(t *testing.T) { 2, "快檢", "什麼望對", }, + { + "快檢什麼望對", + 3, + "快檢什", "麼望對", + }, // Handle chinese with colors { "快\x1b[31m檢什麼\x1b[0m望對", |