package language

import (
	
	
)

// 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 lower
	const  uint32 = 0x20000000
	return 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 search
	for ,  := 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 script
func ( Script) () string {
	var  [4]byte
	binary.BigEndian.PutUint32([:], uint32())
	return string([:])
}

// Strong returns true if the script is not Common or Inherited
func ( Script) () bool {
	return  != Common &&  != Inherited
}