localecp

package module
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 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; on a machine set to a UTF-8 system codepage, where both answer 65001, the locale's legacy codepages are used instead, as Far does).
  • Codepage Numbers: Exposes ANSICodepage and OEMCodepage (Windows codepage numbers, 0 where the platform has none) alongside the encodings.
  • 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()
	// ANSIEncoder is the deduced legacy Windows/ANSI encoder for the current system locale
	ANSIEncoder *encoding.Encoder = charmap.Windows1252.NewEncoder()
	// SystemDecoder is the default system fallback decoder
	SystemDecoder *encoding.Decoder = charmap.CodePage437.NewDecoder()
	// OEMEncoding is the deduced legacy DOS/OEM encoding for the current system locale
	OEMEncoding encoding.Encoding = charmap.CodePage437
	// ANSIEncoding is the deduced legacy Windows/ANSI encoding for the current system locale
	ANSIEncoding encoding.Encoding = charmap.Windows1252

	// ANSICodepage and OEMCodepage are the Windows codepage numbers behind
	// ANSIEncoding and OEMEncoding (1251, 866, ...), for callers that show
	// or store the number rather than the encoding. On a Windows machine
	// set to a UTF-8 system codepage they are the locale's legacy codepages
	// (what GetACP/GetOEMCP would have said without that setting), not
	// 65001. 0 where the platform gives no number, which is every non-Windows
	// platform today.
	ANSICodepage int
	OEMCodepage  int
)

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