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
- func FirstGraphemeCluster(bytes []byte) (r int)
- func FirstGraphemeClusterInRunes(runes []rune) (r int)
- func FirstGraphemeClusterInString(s string) (r int)
- func FirstLineBreak(bytes []byte) int
- func FirstLineBreakInRunes(runes []rune) int
- func FirstLineBreakInString(s string) int
- func FirstSentence(bytes []byte) int
- func FirstSentenceInRunes(runes []rune) int
- func FirstSentenceInString(s string) int
- func FirstWord(bytes []byte) int
- func FirstWordInRunes(runes []rune) int
- func FirstWordInString(s string) int
- func GraphemeClusterBegin(bytes []byte, pos int) int
- func GraphemeClusterBeginInRunes(runes []rune, pos int) int
- func GraphemeClusterBeginInString(s string, pos int) int
- func GraphemeClusterBreaks(bytes []byte) (breaks []int)
- func GraphemeClusterBreaksInRunes(runes []rune) (breaks []int)
- func GraphemeClusterBreaksInString(s string) (breaks []int)
- func GraphemeClusterEnd(bytes []byte, pos int) int
- func GraphemeClusterEndInRunes(runes []rune, pos int) int
- func GraphemeClusterEndInString(s string, pos int) int
- func LastGraphemeCluster(bytes []byte) (r int)
- func LastGraphemeClusterInRunes(runes []rune) (r int)
- func LastGraphemeClusterInString(s string) (r int)
- func LastLineBreak(bytes []byte) int
- func LastLineBreakInRunes(runes []rune) int
- func LastLineBreakInString(s string) int
- func LastSentence(bytes []byte) int
- func LastSentenceInRunes(runes []rune) int
- func LastSentenceInString(s string) int
- func LastWord(bytes []byte) int
- func LastWordInRunes(runes []rune) int
- func LastWordInString(s string) int
- func LineBreakAfter(bytes []byte, pos int) int
- func LineBreakAfterInRunes(runes []rune, pos int) int
- func LineBreakAfterInString(s string, pos int) int
- func LineBreakBefore(bytes []byte, pos int) int
- func LineBreakBeforeInRunes(runes []rune, pos int) int
- func LineBreakBeforeInString(s string, pos int) int
- func LineBreaks(bytes []byte) (breaks []int)
- func LineBreaksInRunes(runes []rune) (breaks []int)
- func LineBreaksInString(s string) (breaks []int)
- func SentenceBegin(bytes []byte, pos int) int
- func SentenceBeginInRunes(runes []rune, pos int) int
- func SentenceBeginInString(s string, pos int) int
- func SentenceBreaks(bytes []byte) (breaks []int)
- func SentenceBreaksInRunes(runes []rune) (breaks []int)
- func SentenceBreaksInString(s string) (breaks []int)
- func SentenceEnd(bytes []byte, pos int) int
- func SentenceEndInRunes(runes []rune, pos int) int
- func SentenceEndInString(s string, pos int) int
- func WordBegin(bytes []byte, pos int) int
- func WordBeginInRunes(runes []rune, pos int) int
- func WordBeginInString(s string, pos int) int
- func WordBreaks(bytes []byte) (breaks []int)
- func WordBreaksInRunes(runes []rune) (breaks []int)
- func WordBreaksInString(s string) (breaks []int)
- func WordEnd(bytes []byte, pos int) int
- func WordEndInRunes(runes []rune, pos int) int
- func WordEndInString(s string, pos int) int
- type Boundary
- func GraphemeClusterAt(bytes []byte, pos int) Boundary
- func GraphemeClusterAtInRunes(runes []rune, pos int) Boundary
- func GraphemeClusterAtInString(s string, pos int) Boundary
- func GraphemeClusters(bytes []byte) (boundaries []Boundary)
- func GraphemeClustersInRunes(runes []rune) (boundaries []Boundary)
- func GraphemeClustersInString(s string) (boundaries []Boundary)
- func Invalid() Boundary
- func SentenceAt(bytes []byte, pos int) Boundary
- func SentenceAtInRunes(runes []rune, pos int) Boundary
- func SentenceAtInString(s string, pos int) Boundary
- func Sentences(bytes []byte) (boundaries []Boundary)
- func SentencesInRunes(runes []rune) (boundaries []Boundary)
- func SentencesInString(s string) (boundaries []Boundary)
- func WordAt(bytes []byte, pos int) Boundary
- func WordAtInRunes(runes []rune, pos int) Boundary
- func WordAtInString(s string, pos int) Boundary
- func Words(bytes []byte) (boundaries []Boundary)
- func WordsInRunes(runes []rune) (boundaries []Boundary)
- func WordsInString(s string) (boundaries []Boundary)
Constants ¶
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).
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 ¶
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 ¶
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 ¶
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 ¶
FirstLineBreak returns first possible line break.
func FirstLineBreakInRunes ¶
FirstLineBreakInRunes returns first possible line break.
func FirstLineBreakInString ¶
FirstLineBreakInString returns first possible line break.
func FirstSentence ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
GraphemeClusterBreaks computes all grapheme clusters and returns all breaks.
func GraphemeClusterBreaksInRunes ¶
GraphemeClusterBreaksInRunes computes all grapheme clusters and returns all breaks.
func GraphemeClusterBreaksInString ¶
GraphemeClusterBreaksInString computes all grapheme clusters and returns all breaks.
func GraphemeClusterEnd ¶
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 ¶
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 ¶
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 ¶
LastGraphemeCluster computes last grapheme cluster. Returns index of cluster's first rune. Last grapheme cluster may retrieved by "bytes[r:]".
func LastGraphemeClusterInRunes ¶
LastGraphemeClusterInRunes computes last grapheme cluster. Returns index of cluster's first rune. Last grapheme cluster may retrieved by "runes[r:]".
func LastGraphemeClusterInString ¶
LastGraphemeClusterInString computes last grapheme cluster. Returns index of cluster's first rune. Last grapheme cluster may retrieved by "s[r:]".
func LastLineBreak ¶
LastLineBreak returns last possible line break (except line break at end of string).
func LastLineBreakInRunes ¶
LastLineBreakInRunes returns last possible line break (except line break at end of string).
func LastLineBreakInString ¶
LastLineBreakInString returns last possible line break (except line break at end of string).
func LastSentence ¶
LastSentence computes last sentence. Returns index of sentence's first rune. Last sentence may retrieved by "bytes[r:]".
func LastSentenceInRunes ¶
LastSentenceInRunes computes last sentence. Returns index of sentence's first rune. Last sentence may retrieved by "runes[r:]".
func LastSentenceInString ¶
LastSentenceInString computes last sentence. Returns index of sentence's first rune. Last sentence may retrieved by "s[r:]".
func LastWord ¶
LastWord computes last word. Returns index of word's first rune. Last word may retrieved by "bytes[r:]".
func LastWordInRunes ¶
LastWordInRunes computes last word. Returns index of word's first rune. Last word may retrieved by "runes[r:]".
func LastWordInString ¶
LastWordInString computes last word. Returns index of word's first rune. Last word may retrieved by "s[r:]".
func LineBreakAfter ¶
LineBreakAfter returns first possible line break on the right side of pos-th rune.
func LineBreakAfterInRunes ¶
LineBreakAfterInRunes returns first possible line break on the right side of pos-th rune.
func LineBreakAfterInString ¶
LineBreakAfterInString returns first possible line break on the right side of pos-th rune.
func LineBreakBefore ¶
LineBreakBefore returns first (nearest) possible line break on the left side of pos-th rune.
func LineBreakBeforeInRunes ¶
LineBreakBeforeInRunes returns first (nearest) possible line break on the left side of pos-th rune.
func LineBreakBeforeInString ¶
LineBreakBeforeInString returns first (nearest) possible line break on the left side of pos-th rune.
func LineBreaks ¶
LineBreaks returns all possible line breaks.
func LineBreaksInRunes ¶
LineBreaksInRunes returns all possible line breaks.
func LineBreaksInString ¶
LineBreaksInString returns all possible line breaks.
func SentenceBegin ¶
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 ¶
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 ¶
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 ¶
SentenceBreaks computes all sentences and returns all breaks.
func SentenceBreaksInRunes ¶
SentenceBreaksInRunes computes all sentences and returns all breaks.
func SentenceBreaksInString ¶
SentenceBreaksInString computes all sentences and returns all breaks.
func SentenceEnd ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
WordBreaks computes all words and returns all breaks.
func WordBreaksInRunes ¶
WordBreaksInRunes computes all words and returns all breaks.
func WordBreaksInString ¶
WordBreaksInString computes all words and returns all breaks.
func WordEnd ¶
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 ¶
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 ¶
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 ¶
Boundary represents subslice by its indexes. Subslice can be retrieved by "s[b.From:b.To]".
func GraphemeClusterAt ¶
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 ¶
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 ¶
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 ¶
GraphemeClusters computes all grapheme clusters and returns theirs boundaries.
func GraphemeClustersInRunes ¶
GraphemeClustersInRunes computes all grapheme clusters and returns theirs boundaries.
func GraphemeClustersInString ¶
GraphemeClustersInString computes all grapheme clusters and returns theirs boundaries.
func SentenceAt ¶
SentenceAt computes sentence which contains pos-th rune and return their boundary. Sentence may retrieved by "bytes[r.From:r.To]".
func SentenceAtInRunes ¶
SentenceAtInRunes computes sentence which contains pos-th rune and return their boundary. Sentence may retrieved by "runes[r.From:r.To]".
func SentenceAtInString ¶
SentenceAtInString computes sentence which contains pos-th rune and return their boundary. Sentence may retrieved by "s[r.From:r.To]".
func SentencesInRunes ¶
SentencesInRunes computes all sentences and returns theirs boundaries.
func SentencesInString ¶
SentencesInString computes all sentences and returns theirs boundaries.
func WordAt ¶
WordAt computes word which contains pos-th rune and return their boundary. word may retrieved by "bytes[r.From:r.To]".
func WordAtInRunes ¶
WordAtInRunes computes word which contains pos-th rune and return their boundary. word may retrieved by "runes[r.From:r.To]".
func WordAtInString ¶
WordAtInString computes word which contains pos-th rune and return their boundary. word may retrieved by "s[r.From:r.To]".
func WordsInRunes ¶
WordsInRunes computes all words and returns theirs boundaries.
func WordsInString ¶
WordsInString computes all words and returns theirs boundaries.
func (Boundary) IsInvalid ¶
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().