boundaryh

package
v0.0.0-...-61d31b1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2018 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Overview

Package boundaryh implements boundary Unicode algorithms: - Unicode Line Breaking Algorithm (TR14) - finds possible line breaking position, - Unicode Text Segmentation (TR29) - finds grapheme clusters, words and sentences boundary. For more information see http://unicode.org/reports/tr14 and http://unicode.org/reports/tr29 . Passing empty slice (or nil) or position outside of passed slice causes "Invalid", "InvalidPos" or empty result (depending on result type). Line breaking related functions also can return "NoLineBreak" result if there is no possible breaking. This is because line breaking algorithm does not allow breaking before 0-th rune (while other algorithms allow). In fact "NoLineBreak" is just named "0", but usually it must be treated specially.

Index

Constants

View Source
const InvalidPos = -1

InvalidPos indicates invalid result position. This means that arguments to function is invalid (i.e. looking for word in empty string or looking for grapheme cluster at outside of string).

View Source
const NoLineBreak int = 0

NoLineBreak indicates that where is no possible line break. TR14 says, that there is no break at start of string (this is required to avoid breaking line after zero runes).

Variables

This section is empty.

Functions

func FirstGraphemeCluster

func FirstGraphemeCluster(bytes []byte) (r int)

FirstGraphemeCluster computes first grapheme cluster. Returns (index of cluster's last rune)+1. Result also may be treated as length of the first grapheme cluster. First grapheme cluster may retrieved by "bytes[:r]".

func FirstGraphemeClusterInRunes

func FirstGraphemeClusterInRunes(runes []rune) (r int)

FirstGraphemeClusterInRunes computes first grapheme cluster. Returns (index of cluster's last rune)+1. Result also may be treated as length of the first grapheme cluster. First grapheme cluster may retrieved by "runes[:r]".

func FirstGraphemeClusterInString

func FirstGraphemeClusterInString(s string) (r int)

FirstGraphemeClusterInString computes first grapheme cluster. Returns (index of cluster's last rune)+1. Result also may be treated as length of the first grapheme cluster. First grapheme cluster may retrieved by "s[:r]".

func FirstLineBreak

func FirstLineBreak(bytes []byte) int

FirstLineBreak returns first possible line break.

func FirstLineBreakInRunes

func FirstLineBreakInRunes(runes []rune) int

FirstLineBreakInRunes returns first possible line break.

func FirstLineBreakInString

func FirstLineBreakInString(s string) int

FirstLineBreakInString returns first possible line break.

func FirstSentence

func FirstSentence(bytes []byte) int

FirstSentence computes first sentence. Returns (index of sentence's last rune)+1. Result also may be treated as length of the first sentence. First sentence may retrieved by "bytes[:r]".

func FirstSentenceInRunes

func FirstSentenceInRunes(runes []rune) int

FirstSentenceInRunes computes first sentence. Returns (index of sentence's last rune)+1. Result also may be treated as length of the first sentence. First sentence may retrieved by "runes[:r]".

func FirstSentenceInString

func FirstSentenceInString(s string) int

FirstSentenceInString computes first sentence. Returns (index of sentence's last rune)+1. Result also may be treated as length of the first sentence. First sentence may retrieved by "s[:r]".

func FirstWord

func FirstWord(bytes []byte) int

FirstWord computes first word. Returns (index of word's last rune)+1. Result also may be treated as length of the first word. First word may retrieved by "bytes[:r]".

func FirstWordInRunes

func FirstWordInRunes(runes []rune) int

FirstWordInRunes computes first word. Returns (index of word's last rune)+1. Result also may be treated as length of the first word. First word may retrieved by "runes[:r]".

func FirstWordInString

func FirstWordInString(s string) int

FirstWordInString computes first word. Returns (index of word's last rune)+1. Result also may be treated as length of the first word. First word may retrieved by "s[:r]".

func GraphemeClusterBegin

func GraphemeClusterBegin(bytes []byte, pos int) int

GraphemeClusterBegin computes grapheme cluster which contains pos-th rune. Returns grapheme cluster's first rune index. In other words, returns first grapheme cluster's boundary on the left of pos-th rune.

func GraphemeClusterBeginInRunes

func GraphemeClusterBeginInRunes(runes []rune, pos int) int

GraphemeClusterBeginInRunes computes grapheme cluster which contains pos-th rune. Returns grapheme cluster's first rune index. In other words, returns first grapheme cluster's boundary on the left of pos-th rune.

func GraphemeClusterBeginInString

func GraphemeClusterBeginInString(s string, pos int) int

GraphemeClusterBeginInString computes grapheme cluster which contains pos-th rune. Returns grapheme cluster's first rune index. In other words, returns first grapheme cluster's boundary on the left of pos-th rune.

func GraphemeClusterBreaks

func GraphemeClusterBreaks(bytes []byte) (breaks []int)

GraphemeClusterBreaks computes all grapheme clusters and returns all breaks.

func GraphemeClusterBreaksInRunes

func GraphemeClusterBreaksInRunes(runes []rune) (breaks []int)

GraphemeClusterBreaksInRunes computes all grapheme clusters and returns all breaks.

func GraphemeClusterBreaksInString

func GraphemeClusterBreaksInString(s string) (breaks []int)

GraphemeClusterBreaksInString computes all grapheme clusters and returns all breaks.

func GraphemeClusterEnd

func GraphemeClusterEnd(bytes []byte, pos int) int

GraphemeClusterEnd computes grapheme cluster which contains pos-th rune. Returns (index of grapheme cluster's last rune)+1. In other words, returns first grapheme cluster's boundary on the right of pos-th rune.

func GraphemeClusterEndInRunes

func GraphemeClusterEndInRunes(runes []rune, pos int) int

GraphemeClusterEndInRunes computes grapheme cluster which contains pos-th rune. Returns (index of grapheme cluster's last rune)+1. In other words, returns first grapheme cluster's boundary on the right of pos-th rune.

func GraphemeClusterEndInString

func GraphemeClusterEndInString(s string, pos int) int

GraphemeClusterEndInString computes grapheme cluster which contains pos-th rune. Returns (index of grapheme cluster's last rune)+1. In other words, returns first grapheme cluster's boundary on the right of pos-th rune.

func LastGraphemeCluster

func LastGraphemeCluster(bytes []byte) (r int)

LastGraphemeCluster computes last grapheme cluster. Returns index of cluster's first rune. Last grapheme cluster may retrieved by "bytes[r:]".

func LastGraphemeClusterInRunes

func LastGraphemeClusterInRunes(runes []rune) (r int)

LastGraphemeClusterInRunes computes last grapheme cluster. Returns index of cluster's first rune. Last grapheme cluster may retrieved by "runes[r:]".

func LastGraphemeClusterInString

func LastGraphemeClusterInString(s string) (r int)

LastGraphemeClusterInString computes last grapheme cluster. Returns index of cluster's first rune. Last grapheme cluster may retrieved by "s[r:]".

func LastLineBreak

func LastLineBreak(bytes []byte) int

LastLineBreak returns last possible line break (except line break at end of string).

func LastLineBreakInRunes

func LastLineBreakInRunes(runes []rune) int

LastLineBreakInRunes returns last possible line break (except line break at end of string).

func LastLineBreakInString

func LastLineBreakInString(s string) int

LastLineBreakInString returns last possible line break (except line break at end of string).

func LastSentence

func LastSentence(bytes []byte) int

LastSentence computes last sentence. Returns index of sentence's first rune. Last sentence may retrieved by "bytes[r:]".

func LastSentenceInRunes

func LastSentenceInRunes(runes []rune) int

LastSentenceInRunes computes last sentence. Returns index of sentence's first rune. Last sentence may retrieved by "runes[r:]".

func LastSentenceInString

func LastSentenceInString(s string) int

LastSentenceInString computes last sentence. Returns index of sentence's first rune. Last sentence may retrieved by "s[r:]".

func LastWord

func LastWord(bytes []byte) int

LastWord computes last word. Returns index of word's first rune. Last word may retrieved by "bytes[r:]".

func LastWordInRunes

func LastWordInRunes(runes []rune) int

LastWordInRunes computes last word. Returns index of word's first rune. Last word may retrieved by "runes[r:]".

func LastWordInString

func LastWordInString(s string) int

LastWordInString computes last word. Returns index of word's first rune. Last word may retrieved by "s[r:]".

func LineBreakAfter

func LineBreakAfter(bytes []byte, pos int) int

LineBreakAfter returns first possible line break on the right side of pos-th rune.

func LineBreakAfterInRunes

func LineBreakAfterInRunes(runes []rune, pos int) int

LineBreakAfterInRunes returns first possible line break on the right side of pos-th rune.

func LineBreakAfterInString

func LineBreakAfterInString(s string, pos int) int

LineBreakAfterInString returns first possible line break on the right side of pos-th rune.

func LineBreakBefore

func LineBreakBefore(bytes []byte, pos int) int

LineBreakBefore returns first (nearest) possible line break on the left side of pos-th rune.

func LineBreakBeforeInRunes

func LineBreakBeforeInRunes(runes []rune, pos int) int

LineBreakBeforeInRunes returns first (nearest) possible line break on the left side of pos-th rune.

func LineBreakBeforeInString

func LineBreakBeforeInString(s string, pos int) int

LineBreakBeforeInString returns first (nearest) possible line break on the left side of pos-th rune.

func LineBreaks

func LineBreaks(bytes []byte) (breaks []int)

LineBreaks returns all possible line breaks.

func LineBreaksInRunes

func LineBreaksInRunes(runes []rune) (breaks []int)

LineBreaksInRunes returns all possible line breaks.

func LineBreaksInString

func LineBreaksInString(s string) (breaks []int)

LineBreaksInString returns all possible line breaks.

func SentenceBegin

func SentenceBegin(bytes []byte, pos int) int

SentenceBegin computes sentence which contains pos-th rune. Returns sentence's first rune index. In other words, returns first sentence's boundary on the left of pos-th rune.

func SentenceBeginInRunes

func SentenceBeginInRunes(runes []rune, pos int) int

SentenceBeginInRunes computes sentence which contains pos-th rune. Returns sentence's first rune index. In other words, returns first sentence's boundary on the left of pos-th rune.

func SentenceBeginInString

func SentenceBeginInString(s string, pos int) int

SentenceBeginInString computes sentence which contains pos-th rune. Returns sentence's first rune index. In other words, returns first sentence's boundary on the left of pos-th rune.

func SentenceBreaks

func SentenceBreaks(bytes []byte) (breaks []int)

SentenceBreaks computes all sentences and returns all breaks.

func SentenceBreaksInRunes

func SentenceBreaksInRunes(runes []rune) (breaks []int)

SentenceBreaksInRunes computes all sentences and returns all breaks.

func SentenceBreaksInString

func SentenceBreaksInString(s string) (breaks []int)

SentenceBreaksInString computes all sentences and returns all breaks.

func SentenceEnd

func SentenceEnd(bytes []byte, pos int) int

SentenceEnd computes sentence which contains pos-th rune. Returns (index of sentence's last rune)+1. In other words, returns first sentence's boundary on the right of pos-th rune.

func SentenceEndInRunes

func SentenceEndInRunes(runes []rune, pos int) int

SentenceEndInRunes computes sentence which contains pos-th rune. Returns (index of sentence's last rune)+1. In other words, returns first sentence's boundary on the right of pos-th rune.

func SentenceEndInString

func SentenceEndInString(s string, pos int) int

SentenceEndInString computes sentence which contains pos-th rune. Returns (index of sentence's last rune)+1. In other words, returns first sentence's boundary on the right of pos-th rune.

func WordBegin

func WordBegin(bytes []byte, pos int) int

WordBegin computes word which contains pos-th rune. Returns word's first rune index. In other words, returns first word's boundary on the left of pos-th rune.

func WordBeginInRunes

func WordBeginInRunes(runes []rune, pos int) int

WordBeginInRunes computes word which contains pos-th rune. Returns word's first rune index. In other words, returns first word's boundary on the left of pos-th rune.

func WordBeginInString

func WordBeginInString(s string, pos int) int

WordBeginInString computes word which contains pos-th rune. Returns word's first rune index. In other words, returns first word's boundary on the left of pos-th rune.

func WordBreaks

func WordBreaks(bytes []byte) (breaks []int)

WordBreaks computes all words and returns all breaks.

func WordBreaksInRunes

func WordBreaksInRunes(runes []rune) (breaks []int)

WordBreaksInRunes computes all words and returns all breaks.

func WordBreaksInString

func WordBreaksInString(s string) (breaks []int)

WordBreaksInString computes all words and returns all breaks.

func WordEnd

func WordEnd(bytes []byte, pos int) int

WordEnd computes word which contains pos-th rune. Returns (index of word's last rune)+1. In other words, returns first word's boundary on the right of pos-th rune.

func WordEndInRunes

func WordEndInRunes(runes []rune, pos int) int

WordEndInRunes computes word which contains pos-th rune. Returns (index of word's last rune)+1. In other words, returns first word's boundary on the right of pos-th rune.

func WordEndInString

func WordEndInString(s string, pos int) int

WordEndInString computes word which contains pos-th rune. Returns (index of word's last rune)+1. In other words, returns first word's boundary on the right of pos-th rune.

Types

type Boundary

type Boundary struct {
	From int // index of first element
	To   int // (index of last element) + 1
}

Boundary represents subslice by its indexes. Subslice can be retrieved by "s[b.From:b.To]".

func GraphemeClusterAt

func GraphemeClusterAt(bytes []byte, pos int) Boundary

GraphemeClusterAt computes grapheme clusters which contains pos-th rune and return their boundary. Grapheme cluster may retrieved by "bytes[r.From:r.To]".

func GraphemeClusterAtInRunes

func GraphemeClusterAtInRunes(runes []rune, pos int) Boundary

GraphemeClusterAtInRunes computes grapheme clusters which contains pos-th rune and return their boundary. Grapheme cluster may retrieved by "runes[r.From:r.To]".

func GraphemeClusterAtInString

func GraphemeClusterAtInString(s string, pos int) Boundary

GraphemeClusterAtInString computes grapheme clusters which contains pos-th rune and return their boundary. Grapheme cluster may retrieved by "s[r.From:r.To]".

func GraphemeClusters

func GraphemeClusters(bytes []byte) (boundaries []Boundary)

GraphemeClusters computes all grapheme clusters and returns theirs boundaries.

func GraphemeClustersInRunes

func GraphemeClustersInRunes(runes []rune) (boundaries []Boundary)

GraphemeClustersInRunes computes all grapheme clusters and returns theirs boundaries.

func GraphemeClustersInString

func GraphemeClustersInString(s string) (boundaries []Boundary)

GraphemeClustersInString computes all grapheme clusters and returns theirs boundaries.

func Invalid

func Invalid() Boundary

Invalid returns "Invalid" boundary.

func SentenceAt

func SentenceAt(bytes []byte, pos int) Boundary

SentenceAt computes sentence which contains pos-th rune and return their boundary. Sentence may retrieved by "bytes[r.From:r.To]".

func SentenceAtInRunes

func SentenceAtInRunes(runes []rune, pos int) Boundary

SentenceAtInRunes computes sentence which contains pos-th rune and return their boundary. Sentence may retrieved by "runes[r.From:r.To]".

func SentenceAtInString

func SentenceAtInString(s string, pos int) Boundary

SentenceAtInString computes sentence which contains pos-th rune and return their boundary. Sentence may retrieved by "s[r.From:r.To]".

func Sentences

func Sentences(bytes []byte) (boundaries []Boundary)

Sentences computes all sentences and returns theirs boundaries.

func SentencesInRunes

func SentencesInRunes(runes []rune) (boundaries []Boundary)

SentencesInRunes computes all sentences and returns theirs boundaries.

func SentencesInString

func SentencesInString(s string) (boundaries []Boundary)

SentencesInString computes all sentences and returns theirs boundaries.

func WordAt

func WordAt(bytes []byte, pos int) Boundary

WordAt computes word which contains pos-th rune and return their boundary. word may retrieved by "bytes[r.From:r.To]".

func WordAtInRunes

func WordAtInRunes(runes []rune, pos int) Boundary

WordAtInRunes computes word which contains pos-th rune and return their boundary. word may retrieved by "runes[r.From:r.To]".

func WordAtInString

func WordAtInString(s string, pos int) Boundary

WordAtInString computes word which contains pos-th rune and return their boundary. word may retrieved by "s[r.From:r.To]".

func Words

func Words(bytes []byte) (boundaries []Boundary)

Words computes all words and returns theirs boundaries.

func WordsInRunes

func WordsInRunes(runes []rune) (boundaries []Boundary)

WordsInRunes computes all words and returns theirs boundaries.

func WordsInString

func WordsInString(s string) (boundaries []Boundary)

WordsInString computes all words and returns theirs boundaries.

func (Boundary) IsInvalid

func (b Boundary) IsInvalid() bool

IsInvalid checks if boundary is invalid in terms of "Invalid" constructor (and does not check anything else). Warning: !b.IsValid() is not equal to b.IsInvalid().

func (Boundary) IsValid

func (b Boundary) IsValid() bool

IsValid checks if boundary is valid in general. Warning: !b.IsValid() is not equal to b.IsInvalid().

func (Boundary) Len

func (b Boundary) Len() int

Len returns length of subslice represented by boundary. Len of "Invalid" boundary is 0. Valid boundary also may have zero length.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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