gonverter

package module
v0.0.0-...-4d8d0c3 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2013 License: MIT Imports: 3 Imported by: 1

README

gonverter Build Status Documentation online

===== Easy, straightforward type conversion for Go.

gonverter package provides a homogeneous conversion interface for Go basic types, based on a type names initials pattern:

´int´ -> I
´string´ -> S
´bool´ -> B
...

This pattern makes possible to achieve conversions easily:

´int´ to ´string´: ItoS
´bool´ to ´int´: BtoS
...

Disclaimer: Go already provides simple native conversions. This package does not aim to replace them, just to put all of them together, making easier to the Go developer to find the right conversion way without digging in multiple doc sources.

TODO:

´int8´ -> I8
´int16´ -> I16
´int32´ -> I32
´int64´ -> I64

´uint´ -> U
´uint8´ -> U8
´byte´ -> B // alias for uint8
´uint16´ -> U16
´uint32´ -> U32
´rune´ -> R // alias for int32
´uint64´ -> U64
´uintptr´ -> Uptr

´float32´ -> F
´float64´ -> F64

´complex64´ -> C
´complex128´ -> C128

##Install

go get github.com/fern4lvarez/gonverter

##Usage

// gonversions.go

package main

import (
    "fmt"
    gnv "github.com/fern4lvarez/gonverter"
)

func main() {
    var i, n int
    var s string
    var b bool

    i = gnv.StoI("38")
    // 38

    n = i + 3
    // 41

    s = gnv.ItoS(n)
    if s == "41" {
        b = gnv.StoB(s)
        // true

        i = gnv.BtoI(b)
        // 1

        res := n + i
        // 42

        b = gnv.ItoB(res)
        if b { // true
            fmt.Printf("It's %s, the answer is %s.", gnv.BtoS(b), gnv.ItoS(res))
        }
    }
}

$ go run gonversions.go
It's true, the answer is 42.

##License gonverter is MIT licensed, see here

Documentation

Overview

gonverter package provides a homogeneous conversion interface for Go basic types, based on a type names initials pattern:

´int´ -> I
´string´ -> S
´bool´ -> B
...

This pattern makes possible to achieve conversions easily:

´int´ to ´string´: ItoS
´bool´ to ´int´: BtoS
...

Disclaimer: Go already provides simple native conversions. This package does not aim to replace them, just to put all of them together, making easier to the Go developer to find the right conversion way without digging in multiple doc sources.

TODO:

´int8´ -> I8
´int16´ -> I16
´int32´ -> I32
´int64´ -> I64

´uint´ -> U
´uint8´ -> U8
´byte´ -> BY // alias for uint8
´uint16´ -> U16
´uint32´ -> U32
´rune´ -> R // alias for int32
´uint64´ -> U64
´uintptr´ -> Uptr

´float32´ -> F
´float64´ -> F64

´complex64´ -> C
´complex128´ -> C128

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BtoI

func BtoI(b bool) int

BtoI `bool` => `int` If b is true returns 1, if false returns 0

func BtoS

func BtoS(b bool) string

BtoS `bool` => `string` If `bool` is true return "true", if false returns "false" Note: It is not reciprocal to StoB

func ItoB

func ItoB(i int) bool

ItoB `int` => `bool` If `int` is 0, returns false, otherwise returns true

func ItoS

func ItoS(i int) string

ItoS `int` => `string`

func StoB

func StoB(s string) bool

StoB `string` => `bool` If ´string´ is empty, return false, otherwise returns true

func StoI

func StoI(s string) int

StoI `string` => `int` If the string is not convertable it returns 0

func Version

func Version() string

Version of the package

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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