types

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2016 License: BSD-2-Clause, BSD-3-Clause, GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package types defines helpers for type conversions.

The API for this package is not finalized yet.

Index

Constants

This section is empty.

Variables

View Source
var BoolValues = map[string]interface{}{
	"true": true, "yes": true, "on": true, "1": true,
	"false": false, "no": false, "off": false, "0": false,
}

BoolValues defines the name and value mappings for ParseBool.

Functions

func ParseBool

func ParseBool(s string) (bool, error)

ParseBool parses bool values according to the definitions in BoolValues. Parsing is case-insensitive.

func ParseInt

func ParseInt(intptr interface{}, val string, mode IntMode) error

ParseInt parses val using mode into intptr, which must be a pointer to an integer kind type. Non-decimal value require prefix `0` or `0x` in the cases when mode permits ambiguity of base; otherwise the prefix can be omitted.

func ScanFully

func ScanFully(ptr interface{}, val string, verb byte) error

ScanFully uses fmt.Sscanf with verb to fully scan val into ptr.

Types

type EnumParser

type EnumParser struct {
	Type      string // type name; if not set, use type of first value added
	CaseMatch bool   // if true, matching of strings is case-sensitive
	// contains filtered or unexported fields
}

EnumParser parses "enum" values; i.e. a predefined set of strings to predefined values.

func (*EnumParser) AddVals

func (ep *EnumParser) AddVals(vals map[string]interface{})

AddVals adds strings and values to an EnumParser.

func (EnumParser) Parse

func (ep EnumParser) Parse(s string) (interface{}, error)

Parse parses the string and returns the value or an error.

type IntMode

type IntMode uint8

An IntMode is a mode for parsing integer values, representing a set of accepted bases.

const (
	Dec IntMode = 1 << iota
	Hex
	Oct
)

IntMode values for ParseInt; can be combined using binary or.

func (IntMode) String

func (m IntMode) String() string

String returns a string representation of IntMode; e.g. `IntMode(Dec|Hex)`.

Jump to

Keyboard shortcuts

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