Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrTypeSupported = errors.New("zstrconv: unsupported type")
)
Functions ¶
func FormatAny ¶
FormatAny returns formatted string of any primitive data type. For given value v=a.(type), following format is applied.
- nil : "<nil>"
- string : v
- []byte : string(v)
- bool : strconv.FormatBool(v)
- int,int8,int16,int32,int64 : strconv.FormatInt(int64(v), 10)
- uint,uint8,uint16,uint32,uint64 : strconv.FormatUint(uint64(v), 10)
- float32 : strconv.FormatFloat(float64(v), 'g', -1, 32)
- float64 : strconv.FormatFloat(float64(v), 'g', -1, 64)
- complex64 : strconv.FormatComplex(complex128(v), 'g', -1, 64)
- complex128 : strconv.FormatComplex(complex128(v), 'g', -1, 128)
- fmt.Stringer : v.String()
- others : fmt.Sprint(v)
func ParseNum ¶
ParseNum parses primitive numbers and return the parsed value. If some error had occurred while parsing s, it is returned with the zero value of T. ParseNum should not be used when performance is important.
Example ¶
package main
import (
"fmt"
"github.com/aileron-projects/go/zerrors"
"github.com/aileron-projects/go/zstrconv"
)
func main() {
fmt.Printf("%T\n", zerrors.Must(zstrconv.ParseNum[int]("-123")))
fmt.Printf("%T\n", zerrors.Must(zstrconv.ParseNum[int8]("-123")))
fmt.Printf("%T\n", zerrors.Must(zstrconv.ParseNum[int16]("-123")))
fmt.Printf("%T\n", zerrors.Must(zstrconv.ParseNum[int32]("-123")))
fmt.Printf("%T\n", zerrors.Must(zstrconv.ParseNum[int64]("-123")))
fmt.Printf("%T\n", zerrors.Must(zstrconv.ParseNum[uint]("123")))
fmt.Printf("%T\n", zerrors.Must(zstrconv.ParseNum[uint8]("123")))
fmt.Printf("%T\n", zerrors.Must(zstrconv.ParseNum[uint16]("123")))
fmt.Printf("%T\n", zerrors.Must(zstrconv.ParseNum[uint32]("123")))
fmt.Printf("%T\n", zerrors.Must(zstrconv.ParseNum[uint64]("123")))
fmt.Printf("%T\n", zerrors.Must(zstrconv.ParseNum[uintptr]("123")))
fmt.Printf("%T\n", zerrors.Must(zstrconv.ParseNum[float32]("1.23")))
fmt.Printf("%T\n", zerrors.Must(zstrconv.ParseNum[float64]("1.23")))
}
Output: int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 uintptr float32 float64
Types ¶
Click to show internal directories.
Click to hide internal directories.