eol

package module
v0.0.0-...-6080dd1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 13 Imported by: 1

README

go-eol

Package eol implements tools for working with end-of-line characters, for the Go programming language.

The end-of-line sequences it supports is:

  • "\n" // line-feed (LF)
  • "\n\r" // line-feed (LF), carriage-return (CR)
  • "\v" // vertical-tab (VT)
  • "\f" // form-feed (FF)
  • "\r" // carriage-return (CR)
  • "\r\n" // carriage-return (CR), line-feed (LF)
  • "\u0085" // next-line (NEL)
  • "\u2028" // line-separator (LS)
  • "\u2029" // paragraph-separator (PS)

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/sourcecode.social/reiver/go-eol

GoDoc

Example

Here is an example:


import "sourcecode.social/reiver/go-eol"

// ...

eodofline, size, err := eol.ReadEOL(runereader)
if nil != err {
	return err
}

Import

To import package eol use import code like the follownig:

import "sourcecode.social/reiver/go-eol"

Installation

To install package eol do the following:

GOPROXY=direct go get https://sourcecode.social/reiver/go-eol

Author

Package eol was written by Charles Iliya Krempeaux

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsEOL

func IsEOL(r rune) bool

func ReadCR

func ReadCR(runescanner io.RuneScanner) (size int, err error)

ReadCR tries to read the "\r" (i.e., carriage-return) end-of-line sequence.

If successful, it returns the number-of-bytes read (to read in end-of-line sequence "\r").

If the character read is not a '\r', then ReadCR will try to unread the character.

Example usage:

size, err := eol.ReadCR(runescanner)

func ReadCRLF

func ReadCRLF(runescanner io.RuneScanner) (size int, err error)

ReadCRLF tries to read the "\r\n" (i.e., carriage-return line-feed) end-of-line sequence.

If successful, it returns the number-of-bytes read (to read in end-of-line sequence "\r\n").

If the first character read is not a '\r', then ReadCRLF will try to unread the character. If the second character read is not a '\n', then ReadCRLF will also try to unread the second character, but will not be able to unread the first character (i.e., '\r') it already read.

Example usage:

size, err := eol.ReadCRLF(runescanner)

func ReadEOL

func ReadEOL(runescanner io.RuneScanner) (endofline string, size int, err error)

ReadEOL tries to read an end-of-line sequence.

The end-of-line sequences it supports are:

line-feed       (LF)  (U+000A) ('\n')
line-feed, carriage-return     ("\n\r")
vertical-tab    (VT)  (U+000B) ('\v')
vertical-tab    (VT)  (U+000B) ('\f')
carriage-return (CR)  (U+000D) ('\r')
carriage-return, line-feed     ("\r\n")
next-line       (NEL) (U+0085)
line-separator  (LS)  (U+2028)
line-separator  (LS)  (U+2029)

If successful, ReadEOL return the end-of-line sequence it found and the number-of-bytes read (to read in end-of-line sequence it found).

Example usage: /

eolSequence, size, err := eol.ReadEOL(runescanner)

func ReadFF

func ReadFF(runescanner io.RuneScanner) (size int, err error)

ReadFF tries to read the "\f" (i.e., form-feed) end-of-line sequence.

If successful, it returns the number-of-bytes read (to read in end-of-line sequence "\f").

If the character read is not a '\f', then ReadFF will try to unread the character.

Example usage:

size, err := eol.ReadFF(runescanner)

func ReadLF

func ReadLF(runescanner io.RuneScanner) (size int, err error)

ReadLF tries to read the "\n" (i.e., line-feed) end-of-line sequence.

If successful, it returns the number-of-bytes read (to read in end-of-line sequence "\n").

If the character read is not a '\n', then ReadLF will try to unread the character.

Example usage:

size, err := eol.ReadLF(runescanner)

func ReadLFCR

func ReadLFCR(runescanner io.RuneScanner) (size int, err error)

ReadLFCR tries to read the "\r\n" (i.e., carriage-return line-feed) end-of-line sequence.

If successful, it returns the number-of-bytes read (to read in end-of-line sequence "\r\n").

If the first character read is not a '\n', then ReadLFCR will try to unread the character. If the second character read is not a '\r', then ReadLFCR will also try to unread the second character, but will not be able to unread the first character (i.e., '\n') it already read.

Example usage:

size, err := eol.ReadLFCR(runescanner)

func ReadLS

func ReadLS(runescanner io.RuneScanner) (size int, err error)

ReadLS tries to read the "\u2028" (i.e., line-separator) end-of-line sequence.

If successful, it returns the number-of-bytes read (to read in end-of-line sequence "\u2028").

If the character read is not a '\u2028', then ReadLS will try to unread the character.

Example usage:

size, err := eol.ReadLS(runescanner)

func ReadNEL

func ReadNEL(runescanner io.RuneScanner) (size int, err error)

ReadNEL tries to read the "\u0085" (i.e., next-line) end-of-line sequence.

If successful, it returns the number-of-bytes read (to read in end-of-line sequence "\u0085").

If the character read is not a '\u0085', then ReadNEL will try to unread the character.

Example usage:

size, err := eol.ReadNEL(runescanner)

func ReadPS

func ReadPS(runescanner io.RuneScanner) (size int, err error)

ReadPS tries to read the "\r" (i.e., carriage-return) end-of-line sequence.

If successful, it returns the number-of-bytes read (to read in end-of-line sequence "\r").

If the character read is not a '\r', then ReadPS will try to unread the character.

Example usage:

size, err := eol.ReadPS(runescanner)

func ReadThisEOL

func ReadThisEOL(runescanner io.RuneScanner, endofline string) (size int, err error)

ReadThisEOL tries to read the specified end-of-line sequence.

The end-of-line sequences it supports are:

line-feed       (LF)  (U+000A) ('\n')
carriage-return (CR)  (U+000D) ('\r')
carriage-return, line-feed    ("\r\n")
next-line       (NEL) (U+0085)
line-separator  (LS)  (U+2028)

If successful, ReadThisEOL return the number-of-bytes read (to read in the specified end-of-line sequence).

Example usage: /

size, err := eol.ReadThisEOL(runescanner, eol.CRLF)

func ReadVT

func ReadVT(runescanner io.RuneScanner) (size int, err error)

ReadVT tries to read the "\v" (i.e., carriage-return) end-of-line sequence.

If successful, it returns the number-of-bytes read (to read in end-of-line sequence "\v").

If the character read is not a '\v', then ReadVT will try to unread the character.

Example usage:

size, err := eol.ReadVT(runescanner)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL