bidi

package
v0.0.0-...-15e26ee Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2021 License: BSD-3-Clause Imports: 5 Imported by: 0

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

View Source
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

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.

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

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 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) Class

func (p Properties) Class() Class

Class returns the Bidi class for p.

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.

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.

Jump to

Keyboard shortcuts

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