Merge branch 'incorrect_line_wrapping_endash' of asdf/bombadillo into master

This commit is contained in:
Sloom Sloum Sluom IV 2019-09-14 20:57:30 -04:00 committed by Gitea
commit 4ea753561f
1 changed files with 10 additions and 6 deletions

View File

@ -81,21 +81,25 @@ func Clear(dir string) {
}
// takes the document content (as a slice) and modifies any lines that are longer
// than the specified console width, splitting them over two lines. returns the
// amended document content as a slice.
// word wrapping uses a "greedy" algorithm
// Takes the document content (as a slice of strings) and wraps any lines that
// are longer than the specified console width. returns the amended document
// content as a slice of strings.
// Word wrapping uses a "greedy" algorithm, where long lines are split in to
// words, and then rebuilt word by word to fill the available space. any
// leftover words overflow to the next line.
// To offer some support for unicode, some lengths are calculated using a slice
// of runes in the following way: len([]rune(string))
func wrapLines(s []string, consolewidth int) []string {
out := []string{}
for _, ln := range s {
if len(ln) <= consolewidth {
if len([]rune(ln)) <= consolewidth {
out = append(out, ln)
} else {
words := strings.SplitAfter(ln, " ")
var subout bytes.Buffer
for i, wd := range words {
sublen := subout.Len()
wdlen := len(wd)
wdlen := len([]rune(wd))
if sublen+wdlen <= consolewidth {
subout.WriteString(wd)
if i == len(words)-1 {