Source File
scripts.go
Belonging Package
github.com/go-text/typesetting/language
package languageimport ()// Script identifies different writing systems.// It is represented as the binary encoding of a script tag of 4 (case sensitive) letters,// as specified by ISO 15924.// Note that the default value is usually the Unknown script, not the 0 value (which is invalid)type Script uint32// ParseScript converts a 4 bytes string into its binary encoding,// enforcing the conventional capitalized case.// If [script] is longer, only its 4 first bytes are used.func ( string) (Script, error) {if len() < 4 {return 0, fmt.Errorf("invalid script string: %s", )}:= binary.BigEndian.Uint32([]byte())// ensure capitalized case : make first letter upper, others lowerconst uint32 = 0x20000000return Script( & ^ | 0x00202020), nil}// LookupScript looks up the script for a particular character (as defined by// Unicode Standard Annex #24), and returns Unknown if not found.func ( rune) Script {// binary searchfor , := 0, len(ScriptRanges); < ; {:= + (-)/2:= ScriptRanges[]if < .Start {=} else if .End < {= + 1} else {return .Script}}return Unknown}// String returns the ISO 4 lower letters code of the scriptfunc ( Script) () string {var [4]bytebinary.BigEndian.PutUint32([:], uint32())return string([:])}// Strong returns true if the script is not Common or Inheritedfunc ( Script) () bool {return != Common && != Inherited}
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |