langcode

package
v0.0.0-...-dfc3f65 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package langcode holds the encoding the generated language table is written in. The generator and the runtime lookup both depend on it, so it lives in one place where they cannot drift apart. See the language package README for the reasoning.

Index

Constants

View Source
const (

	// Max is the highest packed code. Anything above it is not three letters.
	Max uint16 = alphabetSize * alphabetSize * alphabetSize
)

Variables

This section is empty.

Functions

func FNV32a

func FNV32a(s string) uint32

FNV32a is the 32 bit FNV-1a hash of s, which is what the lookup names are matched on. The hasher does not escape, so this does not allocate.

func Pack

func Pack(code string) (uint16, error)

Pack encodes an ISO 639-3 code written as text, lowercasing and skipping what is not a letter, so "NLD" and "n.l.d" both give nld. What survives has to be exactly three letters: padding or truncating "n/a" would quietly produce a different real language.

func PackBytes

func PackBytes(code [3]byte) (uint16, bool)

PackBytes encodes a 3 letter ISO 639-3 code, lowercasing as it goes. Anything that is not a letter reports false: skipping one of three fixed bytes would leave a two letter code.

func Unpack

func Unpack(packed uint16) ([3]byte, bool)

Unpack is the inverse of PackBytes, and reports false for a value that spells no code.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL