Documentation
¶
Overview ¶
Package linewrap wraps text so that they are n characters, or less in length. Wrapped lines can be indented or turned into comments; c, c++, and shell style comments are supported.
Any /r characters encountered will be elided during the wrapping process; only /n is supported for new lines.
The size of tabs is configurable.
With a few exceptions, lines can be wrapped at unicode dash and whitespace characters.
The classification of unicode tokens is drawn from Jukka "Yucca" Korpela's unicode tables on: https://www.cs.tut.fi/~jkorpela/unicode/linebr.html, https://www.cs.tut.fi/~jkorpela/chars/spaces.html, and https://www.cs.tut.fi/~jkorpela/dashes.html. Additionally, information from http://www.unicode.org/reports/tr14/#Properties was used.
The list of symbols handled is not exhaustive.
Line breaks may be inserted before or after whitespace characters. Any trailing spaces on a line will be elided. With the exception of indentation, all leading whitespaces on a wrapped line will be elided.
space U+0020 ogham space mark U+1680 mongolian vowel separator U+180E en quad U+2000 em quad U+2001 en space U+2002 em space U+2003 three per em space U+2004 four per em space U+2005 six per em space U+2006 figure space U+2007 punctuation space U+2008 thin space U+2009 hair space U+200A zero width space U+200B medium mathematical space U+205F ideographic space U+3000
Exceptions to whitespace characters (no break will occur):
no-break space U+00A0 zero width no-break space U+202F
Line breaks may be inserted after a dash (hyphen) character. An em dash (U+2014) can have a break before or after its occurrence but linewrap will only break after its occurrence. A hyphen minus (U+002D) is not supposed to break on a numeric context but linewrap does not make that differentiation.
hyphen minus U+002D soft hyphen U+00AD armenian hyphen U+058A hyphen U+2010 figure dash U+2012 en dash U+2013 em dash U+2014 horizontal bar U+2015 swung dash U+2053 superscript mnus U+207B subscript minus U+208B two em dash U+2E3A three em dash U+2E3B presentation form for vertical em dash U+FE31 presentation form for vertical en dash U+FE32 small em dash U+FE58 small hyphen minus U+FE63 full width hyphen minus U+FF0D
Exceptions to dash characters (no break will occur):
tilde U+007E minus sign U+2212 wavy dash U+301C wavy dash U+3939 mongolian todo hyphen U+1806
Index ¶
Constants ¶
const ( LineLength = 80 // default line length TabSize = 8 // default tab size )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommentStyle ¶
type CommentStyle int
const ( NoComment CommentStyle = iota CPPComment // C++ style line comment: // ShellComment // shell style line comment: # CComment // c style block comment: /* */ )
func ParseCommentStyle ¶
func ParseCommentStyle(s string) CommentStyle
func (CommentStyle) String ¶
func (c CommentStyle) String() string
type Wrapper ¶
type Wrapper struct {
Length int // Max length of the line.
CommentStyle // the type of comment,
// contains filtered or unexported fields
}
Wrapper wraps lines so that the output is lines of Length characters or less.
func (*Wrapper) IndentText ¶
IndentText sets the value that should be used to indent wrapped lines.
func (*Wrapper) Reset ¶
func (w *Wrapper) Reset()
Reset resets the non-configuration fields so that it's usable for a new input. The Wrapper's configuration is not affected.
