ascii

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2021 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package ascii provides support for ASCII strings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Quoted

func Quoted(s string) string

Quoted returns a a double-quoted string safely escaped with Go syntax. Non-ASCII characters are converted to Unicode escape sequences.

e.g. ToAscii("Θ") returns "\"\u0398\""

func ToASCII added in v0.3.1

func ToASCII(s string) string

ToASCII returns the string with non-ascii characters escaped. This converts any non-ASCII characters to their respective Unicode escape sequence (in ASCII characters).

e.g. ToAscii("Θ") returns "\u0398"

func ToBinary added in v0.3.1

func ToBinary(v interface{}) string

ToBinary returns a value (int, float, bool, nil) in hexadecimal notation. Any nil value is returned as zero. Rune and byte types are already uint32 and uint8, respectively, by definition. Other types return 'NaN'

exponents are powers of two

e.g. ToBinary() returns -0x1.23abcp+20

func ToHex added in v0.3.1

func ToHex(v interface{}) string

ToHex returns a value (int, float, bool, nil) in hexadecimal notation. Any nil value is returned as zero. Rune and byte types are already uint32 and uint8, respectively, by definition. Other types return 'NaN'

exponents are powers of two

e.g. ToHex() returns -0x1.23abcp+20

Use of lowercase is the convention based on minimal research: https://twitter.com/sindresorhus/status/926521127869988864 https://meh.com/forum/topics/capital-crimes-part-1--shout-shout-let-it-all-out https://en.wikipedia.org/wiki/Hexadecimal

In addition:

echo "hexdump uses lowercase" |hexdump
0000000 68 65 78 64 75 6d 70 20 75 73 65 73 20 6c 6f 77
0000010 65 72 63 61 73 65 0a
0000017

and

echo "xxd uses lowercase" |xxd
00000000: 7878 6420 7573 6573 206c 6f77 6572 6361  xxd uses lowerca
00000010: 7365 0a                                  se.

func ToOctal added in v0.3.1

func ToOctal(v interface{}) string

ToOctal returns a value (int, float, bool, nil) in hexadecimal notation. Any nil value is returned as zero. Rune and byte types are already uint32 and uint8, respectively, by definition. Other types return 'NaN'

Types

This section is empty.

Jump to

Keyboard shortcuts

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