text/script.go

Functions

Functions

func DetectScript

DetectScript returns the Unicode script for a given rune.

This uses hardcoded Unicode ranges for common scripts to avoid

external dependencies.

 

For characters that appear in multiple scripts or are shared

(like punctuation and numbers), ScriptCommon is returned.

For combining marks, ScriptInherited is returned.

func DetectScript(r rune) Script {
	// ASCII optimization for common case
	if r < 0x0080 {
		return detectASCII(r)
	}

	// Check script ranges in order of frequency/usage
	if script := detectEuropean(r); script != ScriptUnknown {
		return script
	}
	if script := detectMiddleEastern(r); script != ScriptUnknown {
		return script
	}
	if script := detectSouthAsian(r); script != ScriptUnknown {
		return script
	}
	if script := detectEastAsian(r); script != ScriptUnknown {
		return script
	}
	if script := detectSoutheastAsian(r); script != ScriptUnknown {
		return script
	}
	if script := detectOther(r); script != ScriptUnknown {
		return script
	}
	if script := detectCommonSymbols(r); script != ScriptUnknown {
		return script
	}

	return ScriptUnknown
}

func IsRTL

IsRTL returns true if the script is typically written right-to-left.

func (s Script) IsRTL() bool {
	return s == ScriptArabic || s == ScriptHebrew
}

func RequiresComplexShaping

RequiresComplexShaping returns true if the script typically needs

advanced shaping features (ligatures, contextual forms, etc.)

that are not supported by BuiltinShaper.

func (s Script) RequiresComplexShaping() bool {
	switch s {
	case ScriptArabic, ScriptHebrew, ScriptDevanagari, ScriptBengali,
		ScriptTamil, ScriptTelugu, ScriptKannada, ScriptMalayalam,
		ScriptGujarati, ScriptOriya, ScriptGurmukhi, ScriptSinhala,
		ScriptKhmer, ScriptLao, ScriptMyanmar, ScriptTibetan, ScriptThai:
		return true
	default:
		return false
	}
}

func String

String returns the name of the script.

func (s Script) String() string {
	if int(s) < len(scriptNames) {
		return scriptNames[s]
	}
	return unknownStr
}