Documentation ¶
Overview ¶
Package nl provides line break characters for multiple system and microcomputer platforms.
Index ¶
Examples ¶
Constants ¶
View Source
const ( LF rune = 10 // LF is the control code for a line feed. CR rune = 13 // CR is the control code for a carriage return. NL rune = 21 // NL is the control code for a new line, an EBCDIC control. NEL rune = 133 // NEL is the control code for a next line. )
Common ASCII and EBCDIC control codes for new lines.
Variables ¶
View Source
var ErrReader = errors.New("the r reader cannot be nil")
Functions ¶
func Lines ¶
Lines counts the number of lines in the interface. The lb rune pair is the line break sequence. If the line break only has one rune, then the second rune should be 0.
func NewLine ¶
NewLine returns a new line or line break characters for the system platform.
Example ¶
package main import ( "fmt" "github.com/bengarrett/retrotxtgo/nl" ) func main() { s := nl.NewLine(nl.Windows) fmt.Printf("%q\n", s) s = nl.NewLine(nl.Macintosh) fmt.Printf("%q\n", s) s = nl.NewLine(nl.Linux) fmt.Printf("%q\n", s) }
Output: "\r\n" "\r" "\n"
Types ¶
type LineBreak ¶
type LineBreak struct { Abbr string `json:"string" xml:"string,attr"` // Abbr is the abbreviation for the line break. Escape string `json:"escape" xml:"-"` // Escape is the escape sequence for the line break. Decimal [2]rune `json:"decimal" xml:"decimal"` // Decimal is the numeric character code for the line break. }
LineBreak contains details on the line break sequence used to create a new line in a text file.
func (*LineBreak) Find ¶
Find determines the new lines characters found in the rune pair.
Example ¶
package main import ( "fmt" "github.com/bengarrett/retrotxtgo/nl" ) func main() { lb := &nl.LineBreak{} // A Windows example of a line break. windows := [2]rune{rune('\r'), rune('\n')} lb.Find(windows) fmt.Printf("%s %q %d %X\n", lb.Abbr, lb.Escape, lb.Decimal, lb.Decimal) // A macOS, Linux, or Unix example of a line break. linux := [2]rune{rune('\n')} lb.Find(linux) fmt.Printf("%s %q %d %X\n", lb.Abbr, lb.Escape, lb.Decimal, lb.Decimal) }
Output: CRLF "\r\n" [13 10] [D A] LF "\n" [10 0] [A 0]
func (*LineBreak) Total ¶
Total counts the number of lines in the named file based on the provided line break sequence.
Example ¶
package main import ( "fmt" "github.com/bengarrett/retrotxtgo/nl" ) func main() { lb := &nl.LineBreak{} linux := [2]rune{rune('\n')} lb.Find(linux) // Count the number of lines in a file. total, _ := lb.Total("testdata/textlf.txt") fmt.Println(total) }
Output: 7
type System ¶
type System int
System is a micro or computer platform.
const ( Host System = iota // Host is the host operating system default. Acorn // Acorn is the Acorn Archimedes. Amiga // Amiga is the Commodore Amiga. Commodore // Commodore is the Commodore 64 and compatibles. Darwin // Darwin is Apple macOS. Linux // Linux is the Linux operating system. Macintosh // Macintosh is the Apple Macintosh. PCDos // PCDos is an IBM PC and Microsoft DOS and compatibles. Unix // Unix are both Unix and BSD. Windows // Windows is Microsoft Windows. )
Click to show internal directories.
Click to hide internal directories.