prefixmapper

package
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Port of java/internal/prefixmapper/src/com/google/i18n/phonenumbers/prefixmapper/* (shared prefix lookup).

A Mapper resolves the value (carrier name, geocoding description, …) mapped to the longest matching numeric prefix of an E164 number. It is shared by the carrier and geocoding packages, each of which constructs one over its own embedded per-language data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mapper

type Mapper struct {
	// contains filtered or unexported fields
}

Mapper loads "<dir>/<language>.txt.gz" prefix maps from an embedded filesystem on demand, caching them per language. It is safe for concurrent use.

func New

func New(dataFS embed.FS, dir string) *Mapper

New returns a Mapper backed by dataFS, reading language files from dir.

func (*Mapper) ValueForNumber

func (m *Mapper) ValueForNumber(language string, maxLength int, e164 string) (string, int, error)

ValueForNumber returns the value mapped to the longest matching prefix of the given E164 string (as produced by Format with E164, leading + included), along with the matched prefix, trying prefixes from maxLength digits downward. It returns "" and 0 if no prefix matches or the language has no data.

Jump to

Keyboard shortcuts

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