text: golang.org/x/text/unicode/bidi Index | Files

package bidi

import "golang.org/x/text/unicode/bidi"

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

Package Files

bidi.go bracket.go core.go tables.go trieval.go

Constants

const UnicodeVersion = "8.0.0"

UnicodeVersion is the Unicode version from which the tables in this package are derived.

func AppendReverse

func AppendReverse(out, in []byte) []byte

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

func ReverseString(s string) string

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.

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

func DefaultDirection(d Direction) Option

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.

func (*Ordering) Direction

func (o *Ordering) Direction() Direction

Direction reports the directionality of the runs.

The direction may be LeftToRight, RightToLeft, Mixed, or Neutral.

func (*Ordering) NumRuns

func (o *Ordering) NumRuns() int

NumRuns returns the number of runs.

func (*Ordering) Run

func (o *Ordering) Run(i int) Run

Run returns the ith run within the ordering.

type Paragraph

type Paragraph struct {
}

A Paragraph holds a single Paragraph for Bidi processing.

func (*Paragraph) Direction

func (p *Paragraph) Direction() Direction

Direction returns the direction of the text of this paragraph.

The direction may be LeftToRight, RightToLeft, Mixed, or Neutral.

func (*Paragraph) IsLeftToRight

func (p *Paragraph) IsLeftToRight() bool

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

func (p *Paragraph) Line(start, end int) (Ordering, error)

Line computes the visual ordering of runs for a single line starting and ending at the given positions in the original text.

func (*Paragraph) Order

func (p *Paragraph) Order() (Ordering, error)

Order computes the visual ordering of all the runs in a Paragraph.

func (*Paragraph) RunAt

func (p *Paragraph) RunAt(pos int) Run

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

func (p *Paragraph) SetBytes(b []byte, opts ...Option) (n int, err error)

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

func (p *Paragraph) SetString(s string, opts ...Option) (n int, err error)

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 Run

type Run struct {
}

A Run is a continuous sequence of characters of a single direction.

func (*Run) Bytes

func (r *Run) Bytes() []byte

Bytes returns the text of the run in its original order.

func (*Run) Direction

func (r *Run) Direction() Direction

Direction reports the direction of the run.

func (*Run) Pos

func (r *Run) Pos() (start, end int)

Position of the Run within the text passed to SetBytes or SetString of the originating Paragraph value.

func (*Run) String

func (r *Run) String() string

String returns the text of the run in its original order.

Package bidi imports 4 packages (graph). Updated 6 days ago. Refresh now. Tools for package owners.