num

package module
v0.0.0-...-458eb27 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2021 License: ISC Imports: 3 Imported by: 2

README

num

An over-engineered package for adding thousands separators to numbers that supports streaming.

For example:
BenchmarkNum-4       20    62281610  ns/op  1161200  B/op  1  allocs/op
BenchmarkStream-4    20    62111283  ns/op  6572     B/op  0  allocs/op
Becomes:
BenchmarkNum-4       20    61,777,611  ns/op  1,161,200  B/op  1  allocs/op
BenchmarkStream-4    20    62,340,974  ns/op  6,572      B/op  0  allocs/op

Documentation

Overview

Package num provides tools for adding thousands separators to numbers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendFormat

func AppendFormat(dst, b []byte) []byte

AppendFormat, adds thousands separators to byte slice b and appends the results to dst. If b is not a number it is not appended to dst.

func Format

func Format(s string) (string, error)

Format, adds thousands separators to string s. An error is returned is s is not a number.

func FormatInt

func FormatInt(val int64) string

func FormatUint

func FormatUint(val uint64) string

Types

type Encoder

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

An Encoder is a stream formatter.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder, returns an Encoder that writes to w.

func (*Encoder) Encode

func (e *Encoder) Encode(r io.Reader) error

Encode, reads from r formatting any numbers and writes the results to the underlying io.Writer.

type Num

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

func New

func New() *Num

func (*Num) Flush

func (n *Num) Flush() error

Flush, formats any partially read numbers and flushes them into the internal buffer.

func (*Num) Read

func (n *Num) Read(p []byte) (int, error)

Read, flushes any partial numbers and reads up to len(p) bytes from the internal buffer into p.

func (*Num) Reset

func (n *Num) Reset()

Reset, resets the internal state of Num.

func (*Num) Write

func (n *Num) Write(p []byte) (int, error)

Write, writes formats any numbers in p and writes the results to the internal buffer. A state machine is used to keep track of the format state - so if a write ends partially through a number the number will be formatted on the next call to Write or Flush.

func (*Num) WriteTo

func (n *Num) WriteTo(w io.Writer) (int64, error)

WriteTo, flushes any partial numbers and writes the contents of Num's internal buffer to w.

type ScannerError

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

func (ScannerError) Bytes

func (s ScannerError) Bytes() int64

func (ScannerError) Error

func (s ScannerError) Error() string

Directories

Path Synopsis
cmd
num

Jump to

Keyboard shortcuts

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