Documentation ¶
Overview ¶
Package clmconv converts spreadsheet column alphabet to integer and vice versa.
Example ¶
package main import ( "fmt" "github.com/takuoki/clmconv" ) func main() { // Default converter i, _ := clmconv.Atoi("A") a := clmconv.Itoa(0) fmt.Printf("i=%d, a='%s'\n", i, a) // Custom converter converter := clmconv.New(clmconv.WithStartFromOne(), clmconv.WithLowercase()) i, _ = converter.Atoi("A") a = converter.Itoa(1) fmt.Printf("i=%d, a='%s'\n", i, a) }
Output: i=0, a='A' i=1, a='a'
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Atoi ¶
Atoi converts alphabet to number.
Example ¶
package main import ( "fmt" "github.com/takuoki/clmconv" ) func main() { ai, _ := clmconv.Atoi("A") bi, _ := clmconv.Atoi("B") _, err := clmconv.Atoi("error!") fmt.Printf("ai=%d, bi=%d, err='%v'", ai, bi, err) }
Output: ai=0, bi=1, err='must not contain non-alphabetic characters'
func Itoa ¶
Itoa converts number to alphabet. If argument is negative, returns empty string.
Example ¶
package main import ( "fmt" "github.com/takuoki/clmconv" ) func main() { a0 := clmconv.Itoa(0) a1 := clmconv.Itoa(1) an := clmconv.Itoa(-1) fmt.Printf("a0='%s', a1='%s', an='%s'", a0, a1, an) }
Output: a0='A', a1='B', an=''
func MustAtoi ¶
MustAtoi converts alphabet to number. In case of invalid argument, throws panic.
Example ¶
package main import ( "fmt" "github.com/takuoki/clmconv" ) func main() { ai := clmconv.MustAtoi("A") v := func() (v interface{}) { defer func() { if p := recover(); p != nil { v = p } }() clmconv.MustAtoi("panic!") return nil }() fmt.Printf("ai=%d, v='%v'", ai, v) }
Output: ai=0, v='must not contain non-alphabetic characters'
Types ¶
type Converter ¶ added in v1.1.0
type Converter struct {
// contains filtered or unexported fields
}
Converter represents a conversion object. If you need a conversion other than the default, you need create a new conversion object.
type Option ¶ added in v1.1.0
type Option interface {
// contains filtered or unexported methods
}
Option is an option that configures Converter.
func WithLowercase ¶ added in v1.1.0
func WithLowercase() Option
WithLowercase is an option to use lowercase letters as the output alphabet. This option works only with `Itoa`.
func WithStartFromOne ¶ added in v1.1.0
func WithStartFromOne() Option
WithStartFromOne is an option to start the index from one. This option works for both `Atoi` and `Itoa`.