text/segment.go

Functions Structs Interfaces

Functions

func IsPunctuation

func IsPunctuation(r rune) bool {
	return unicode.IsPunct(r)
}

func IsWhitespace

func IsWhitespace(r rune) bool {
	return unicode.IsSpace(r)
}

func NewBuiltinSegmenter

func NewBuiltinSegmenter() *BuiltinSegmenter {
	return &BuiltinSegmenter{BaseDirection: DirectionLTR}
}

func NewBuiltinSegmenterWithDirection

func NewBuiltinSegmenterWithDirection(dir Direction) *BuiltinSegmenter {
	return &BuiltinSegmenter{BaseDirection: dir}
}

func RuneCount

func (s Segment) RuneCount() int {
	count := 0
	for range s.Text {
		count++
	}
	return count
}

func Segment

func (s *BuiltinSegmenter) Segment(text string) []Segment {
	if text == "" {
		return nil
	}
	runes := []rune(text)
	if len(runes) == 0 {
		return nil
	}
	levels := s.computeBidiLevels(text)
	scripts := s.detectScripts(runes)
	scripts = s.resolveInheritedScripts(scripts)
	return s.buildSegments(text, runes, levels, scripts)
}

func SegmentText

func SegmentText(text string) []Segment {
	return NewBuiltinSegmenter().Segment(text)
}

func SegmentTextRTL

func SegmentTextRTL(text string) []Segment {
	return NewBuiltinSegmenterWithDirection(DirectionRTL).Segment(text)
}

Structs

type Segment struct

Segment represents a contiguous run of text with the same direction and script.

type Segment struct {
	Text		string
	Start		int
	End		int
	Direction	Direction
	Script		Script
	Level		int
}

type BuiltinSegmenter struct

type BuiltinSegmenter struct {
	BaseDirection Direction
}

Interfaces

type Segmenter interface

type Segmenter interface {
	Segment(text string) []Segment
}