Documentation ¶
Overview ¶
Package bidi contains functionality for bidirectional text support.
See http://www.unicode.org/reports/tr9.
NOTE: UNDER CONSTRUCTION. This API may change in backwards incompatible ways and without notice.
Index ¶
- Constants
- func AppendReverse(out, in []byte) []byte
- func ReverseString(s string) string
- type Class
- type Direction
- type Option
- type Ordering
- type Paragraph
- func (p *Paragraph) Direction() Direction
- func (p *Paragraph) IsLeftToRight() bool
- func (p *Paragraph) Line(start, end int) (Ordering, error)
- func (p *Paragraph) Order() (Ordering, error)
- func (p *Paragraph) RunAt(pos int) Run
- func (p *Paragraph) SetBytes(b []byte, opts ...Option) (n int, err error)
- func (p *Paragraph) SetString(s string, opts ...Option) (n int, err error)
- type Properties
- type Run
Constants ¶
const UnicodeVersion = "9.0.0"
UnicodeVersion is the Unicode version from which the tables in this package are derived.
Variables ¶
This section is empty.
Functions ¶
func AppendReverse ¶
AppendReverse reverses the order of characters of in, appends them to out, and returns the result. Modifiers will still follow the runes they modify. Brackets are replaced with their counterparts.
func ReverseString ¶
ReverseString reverses the order of characters in s and returns a new string. Modifiers will still follow the runes they modify. Brackets are replaced with their counterparts.
Types ¶
type Class ¶
type Class uint
Class is the Unicode BiDi class. Each rune has a single class.
const ( L Class = iota // LeftToRight R // RightToLeft EN // EuropeanNumber ES // EuropeanSeparator ET // EuropeanTerminator AN // ArabicNumber CS // CommonSeparator B // ParagraphSeparator S // SegmentSeparator WS // WhiteSpace ON // OtherNeutral BN // BoundaryNeutral NSM // NonspacingMark AL // ArabicLetter Control // Control LRO - PDI LRO // LeftToRightOverride RLO // RightToLeftOverride LRE // LeftToRightEmbedding RLE // RightToLeftEmbedding PDF // PopDirectionalFormat LRI // LeftToRightIsolate RLI // RightToLeftIsolate FSI // FirstStrongIsolate PDI // PopDirectionalIsolate )
type Direction ¶
type Direction int
A Direction indicates the overall flow of text.
const ( // LeftToRight indicates the text contains no right-to-left characters and // that either there are some left-to-right characters or the option // DefaultDirection(LeftToRight) was passed. LeftToRight Direction = iota // RightToLeft indicates the text contains no left-to-right characters and // that either there are some right-to-left characters or the option // DefaultDirection(RightToLeft) was passed. RightToLeft // Mixed indicates text contains both left-to-right and right-to-left // characters. Mixed // Neutral means that text contains no left-to-right and right-to-left // characters and that no default direction has been set. Neutral )
type Option ¶
type Option func(*options)
An Option is an option for Bidi processing.
func DefaultDirection ¶
DefaultDirection sets the default direction for a Paragraph. The direction is overridden if the text contains directional characters.
type Ordering ¶
type Ordering struct{}
An Ordering holds the computed visual order of runs of a Paragraph. Calling SetBytes or SetString on the originating Paragraph invalidates an Ordering. The methods of an Ordering should only be called by one goroutine at a time.
type Paragraph ¶
type Paragraph struct { }
A Paragraph holds a single Paragraph for Bidi processing.
func (*Paragraph) Direction ¶
Direction returns the direction of the text of this paragraph.
The direction may be LeftToRight, RightToLeft, Mixed, or Neutral.
func (*Paragraph) IsLeftToRight ¶
IsLeftToRight reports whether the principle direction of rendering for this paragraphs is left-to-right. If this returns false, the principle direction of rendering is right-to-left.
func (*Paragraph) Line ¶
Line computes the visual ordering of runs for a single line starting and ending at the given positions in the original text.
func (*Paragraph) RunAt ¶
RunAt reports the Run at the given position of the input text.
This method can be used for computing line breaks on paragraphs.
func (*Paragraph) SetBytes ¶
SetBytes configures p for the given paragraph text. It replaces text previously set by SetBytes or SetString. If b contains a paragraph separator it will only process the first paragraph and report the number of bytes consumed from b including this separator. Error may be non-nil if options are given.
func (*Paragraph) SetString ¶
SetString configures p for the given paragraph text. It replaces text previously set by SetBytes or SetString. If b contains a paragraph separator it will only process the first paragraph and report the number of bytes consumed from b including this separator. Error may be non-nil if options are given.
type Properties ¶
type Properties struct {
// contains filtered or unexported fields
}
Properties provides access to BiDi properties of runes.
func Lookup ¶
func Lookup(s []byte) (p Properties, sz int)
Lookup returns properties for the first rune in s and the width in bytes of its encoding. The size will be 0 if s does not hold enough bytes to complete the encoding.
func LookupRune ¶
func LookupRune(r rune) (p Properties, size int)
LookupRune returns properties for r.
func LookupString ¶
func LookupString(s string) (p Properties, sz int)
LookupString returns properties for the first rune in s and the width in bytes of its encoding. The size will be 0 if s does not hold enough bytes to complete the encoding.
func (Properties) IsBracket ¶
func (p Properties) IsBracket() bool
IsBracket reports whether the rune is a bracket.
func (Properties) IsOpeningBracket ¶
func (p Properties) IsOpeningBracket() bool
IsOpeningBracket reports whether the rune is an opening bracket. IsBracket must return true.
type Run ¶
type Run struct { }
A Run is a continuous sequence of characters of a single direction.