func NewEncoding(alphabet string) (*Encoding, error) {
	runes := []rune(alphabet)
	runeMap := make(map[rune]int)

	for i := 0; i < len(runes); i++ {
		if _, ok := runeMap[runes[i]]; ok {
			return nil, errors.New("ambiguous alphabet")
		}

		runeMap[runes[i]] = i
	}

	return &Encoding{
		base:        len(runes),
		alphabet:    runes,
		alphabetMap: runeMap,
	}, nil
}
// NewEncoding returns a custom base encoder defined by the alphabet string.
// The alphabet should contain non-repeating characters.
// Ordering is important.
// Example alphabets:
//   - base2: 01
//   - base16: 0123456789abcdef
//   - base32: 0123456789ABCDEFGHJKMNPQRSTVWXYZ
//   - base62: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
NewEncoding returns a custom base encoder defined by the alphabet string.
The alphabet should contain non-repeating characters.
Ordering is important.
// NewEncoding returns a custom base encoder defined by the alphabet string . // The alphabet should contain non - repeating characters . // Ordering is important . // Example alphabets : // - base2 : 01 // - base16 : 0123456789abcdef // - base32 : 0123456789ABCDEFGHJKMNPQRSTVWXYZ // - base62 : 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
func NewEncoding(alphabet string) (*Encoding, error) {
	runes := []rune(alphabet)
	runeMap := make(map[rune]int)
	for i := 0; i < len(runes); i++ {
		if _, ok := runeMap[runes[i]]; ok {
			return nil, errors.New("ambiguous alphabet")
		}
		runeMap[runes[i]] = i
	}
	return &Encoding{
		base:        len(runes),
		alphabet:    runes,
		alphabetMap: runeMap,
	}, nil
}
func NewEncoding ( alphabet string ) ( * Encoding , error ) { runes := [ ] rune ( alphabet ) runeMap := make ( map [ rune ] int ) for i := 0 ; i < len ( runes ) ; i ++ { if _ , ok := runeMap [ runes [ i ] ] ; ok { return nil , errors . New ( " " ) } runeMap [ runes [ i ] ] = i } return & Encoding { base : len ( runes ) , alphabet : runes , alphabetMap : runeMap , } , nil }
NewEncoding returns a custom base encoder defined by the alphabet string.
NewEncoding returns a custom base encoder defined by the alphabet string .