localecp

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0

README

localecp

localecp (Locale Codepage) is a zero-dependency Go micro-library that deduces active legacy system codepages (OEM and ANSI) based on the host operating system's locale.

Features

  • Platform-Aware: Detects system locales on Unix/macOS (via LANG/LC_ALL variables) and Windows (using GetACP and GetOEMCP API calls).
  • Pre-configured Decoders: Exposes active OEMDecoder, ANSIDecoder, and SystemDecoder ready to use with standard text processing.
  • No Heavy Dependencies: Relies solely on golang.org/x/text.

Installation

go get github.com/unxed/localecp

Usage

package main

import (
	"fmt"
	"github.com/unxed/localecp"
)

func main() {
	rawBytes := []byte{0x8f, 0xe0, 0xa8, 0xa2, 0xa5, 0xe2} // "Привет" in CP866

	// Decode using the automatically initialized OEM decoder
	decoded, _ := localecp.OEMDecoder.Bytes(rawBytes)
	fmt.Println(string(decoded))
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// OEMDecoder is the deduced legacy DOS/OEM decoder for the current system locale
	OEMDecoder *encoding.Decoder = charmap.CodePage437.NewDecoder()
	// ANSIDecoder is the deduced legacy Windows/ANSI decoder for the current system locale
	ANSIDecoder *encoding.Decoder = charmap.Windows1252.NewDecoder()
	// SystemDecoder is the default system fallback decoder
	SystemDecoder *encoding.Decoder = charmap.CodePage437.NewDecoder()
)

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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