cesu8

package module
v0.0.0-...-270517b Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2019 License: Apache-2.0 Imports: 4 Imported by: 2

README

go-cesu8

Package cesu8 implements functions and constants to support text encoded in CESU-8. It implements functions comparable to the unicode/utf8 package for UTF-8 de- and encoding.

Extracted from https://github.com/SAP/go-hdb/blob/master/internal/unicode/cesu8.

utf8Encoded := "Hello 👋"
// 48 65 6C 6C 6F 20 F0 9F 91 8B

cesu8Encoded := cesu8.EncodeString(utf8Encoded)
// 48 65 6C 6C 6F 20 ED A0 BD ED B1 8B

utf8Encoded = cesu8.DecodeString(cesu8Encoded)
// 48 65 6C 6C 6F 20 F0 9F 91 8B

Documentation

Overview

Package cesu8 implements functions and constants to support text encoded in CESU-8. It implements functions comparable to the unicode/utf8 package for UTF-8 de- and encoding.

Index

Constants

View Source
const (
	// CESUMax is the maximum amount of bytes used by an CESU-8 codepoint encoding.
	CESUMax = 6
)

Variables

This section is empty.

Functions

func DecodeRune

func DecodeRune(p []byte) (rune, int)

DecodeRune unpacks the first CESU-8 encoding in p and returns the rune and its width in bytes.

func DecodeString

func DecodeString(p []byte) string

DecodeString decodes a CESU-8 encoded slice of bytes into a string.

func EncodeRune

func EncodeRune(p []byte, r rune) int

EncodeRune writes into p (which must be large enough) the CESU-8 encoding of the rune. It returns the number of bytes written.

func EncodeString

func EncodeString(s string) []byte

EncodeString encodes a string into a slice of CESU-8 encoded bytes.

func FullRune

func FullRune(p []byte) bool

FullRune reports whether the bytes in p begin with a full CESU-8 encoding of a rune.

func RuneLen

func RuneLen(r rune) int

RuneLen returns the number of bytes required to encode the rune.

func Size

func Size(p []byte) int

Size returns the amount of bytes needed to encode an UTF-8 byte slice to CESU-8.

func StringSize

func StringSize(s string) int

StringSize is like Size with a string as parameter.

Types

This section is empty.

Jump to

Keyboard shortcuts

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