bidi

package module
v0.0.0-...-215e47c Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2020 License: LGPL-3.0 Imports: 6 Imported by: 1

README

go-bidi

GoDoc codecov Go

go-bidi is a Go implementation of the bidi logical-to-visual algorithm. It is a go port of https://github.com/MeirKriheli/python-bidi.

Documentation

Overview

Package bidi implements the bidi algorithm for converting logical-order strings to visual-order strings, using the Unicode algorithm. This is a complementary package to golang.org/x/text/unicode, which does not yet contain this functionality.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Display

func Display(str string) (string, error)

Display returns the visual order for str, which should be in logical order.

Example
visual, _ := Display("Hello, עולם")
fmt.Println(visual)
Output:

Hello, םלוע

Types

type Displayer

type Displayer struct {
	// Treat uppercase characters as RTL
	UpperIsRTL bool

	// Base direction. Default is bidi.Neutral
	BaseDir bidi.Direction

	// If not nil, debug output will be written here
	Debug io.Writer
}

Displayer provides a configurable object for running Display. For typical usage, use the ordinary Display function instead.

func (Displayer) Display

func (d Displayer) Display(str string) (string, error)

Display returns the visual order for str, which should be in logical order, using the configuration in d.

Example
d := Displayer{
	UpperIsRTL: true,
	Debug:      os.Stdout,
}
visual, _ := d.Display("hello, WORLD")
fmt.Println(visual)
Output:

in getEmbeddingLevels
  base level  : 0
  base dir    : L
  Chars       : hello, WORLD
  Res. levels : 000000000000
  Res. types  :[LLLLLCWRRRRR]
               [     SS     ]

in explicitEmbedAndOverrides
  runs        : [{sor:0 eor:0 start:0 length:12 Type:1}]
  Chars       : hello, WORLD
  Res. levels : 000000000000
  Res. types  :[LLLLLCWRRRRR]
               [     SS     ]

in resolveWeakTypes
  runs        : [{sor:0 eor:0 start:0 length:12 Type:1}]
  Chars       : hello, WORLD
  Res. levels : 000000000000
  Res. types  :[LLLLLOWRRRRR]
               [     NS     ]

in resolveNeutralTypes
  Chars       : hello, WORLD
  Res. levels : 000000000000
  Res. types  :[LLLLLLLRRRRR]

in resolveImplicitLevels
  runs        : [{sor:0 eor:0 start:0 length:12 Type:1}]
  Chars       : hello, WORLD
  Res. levels : 000000011111
  Res. types  :[LLLLLLLRRRRR]

in reorderResolvedLevels
  Chars       : hello, DLROW
  Res. levels : 000000011111
  Res. types  :[LLLLLLLRRRRR]

in applyMirroring
  Chars       : hello, DLROW
  Res. levels : 000000011111
  Res. types  :[LLLLLLLRRRRR]

hello, DLROW

Jump to

Keyboard shortcuts

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