Skip to content

Commit

Permalink
Better case for Script (#153)
Browse files Browse the repository at this point in the history
* [language] use a better convention for scripts constants

* [fontscan] bump format version since the Script binary encoding has changed
  • Loading branch information
benoitkugler authored Apr 2, 2024
1 parent 3a5fea0 commit ced1d68
Show file tree
Hide file tree
Showing 4 changed files with 1,342 additions and 1,333 deletions.
2 changes: 1 addition & 1 deletion fontscan/serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (ff *fileFootprints) deserializeFrom(src []byte) error {
return nil
}

const cacheFormatVersion = 3
const cacheFormatVersion = 4

func max(i, j int) int {
if i > j {
Expand Down
8 changes: 6 additions & 2 deletions language/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ import (
// Note that the default value is usually the Unknown script, not the 0 value (which is invalid)
type Script uint32

// ParseScript simply converts a 4 bytes string into its binary encoding.
// 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 ParseScript(script string) (Script, error) {
if len(script) < 4 {
return 0, fmt.Errorf("invalid script string: %s", script)
}
return Script(binary.BigEndian.Uint32([]byte(script))), nil
s := binary.BigEndian.Uint32([]byte(script))
// ensure capitalized case : make first letter upper, others lower
const mask uint32 = 0x20000000
return Script(s & ^mask | 0x00202020), nil
}

// LookupScript looks up the script for a particular character (as defined by
Expand Down
Loading

0 comments on commit ced1d68

Please sign in to comment.