// Base58 returns a base58 string of the snowflake ID
346882
func (f ID) Base58() string {

	if f < 58 {
		return string(encodeBase58Map[f])
	}

	b := make([]byte, 0, 11)
	for f >= 58 {
		b = append(b, encodeBase58Map[f%58])
		f /= 58
	}
	b = append(b, encodeBase58Map[f])

	for x, y := 0, len(b)-1; x < y; x, y = x+1, y-1 {
		b[x], b[y] = b[y], b[x]
	}

	return string(b)
}
1144857
func compileBaseType(t ast.BaseType) (TypeSpec, error) {
	annots, err := compileAnnotations(t.Annotations)
	if err != nil {
		return nil, err
	}

	switch t.ID {
	case ast.BoolTypeID:
		return &BoolSpec{Annotations: annots}, nil
	case ast.I8TypeID:
		return &I8Spec{Annotations: annots}, nil
	case ast.I16TypeID:
		return &I16Spec{Annotations: annots}, nil
	case ast.I32TypeID:
		return &I32Spec{Annotations: annots}, nil
	case ast.I64TypeID:
		return &I64Spec{Annotations: annots}, nil
	case ast.DoubleTypeID:
		return &DoubleSpec{Annotations: annots}, nil
	case ast.StringTypeID:
		return &StringSpec{Annotations: annots}, nil
	case ast.BinaryTypeID:
		return &BinarySpec{Annotations: annots}, nil
	default:
		panic(fmt.Sprintf("unknown base type %v", t))
	}
}
849891
func ReadFileEncodeBase64(filename string) (string, error) {
	// read whole the file
	b, err := ioutil.ReadFile(filename)
	if err != nil {
		return "", err
	}

	return base64.StdEncoding.EncodeToString(b), nil
}
766797
func interpolationFuncBase64Decode() ast.Function {
	return ast.Function{
		ArgTypes:   []ast.Type{ast.TypeString},
		ReturnType: ast.TypeString,
		Callback: func(args []interface{}) (interface{}, error) {
			s := args[0].(string)
			sDec, err := base64.StdEncoding.DecodeString(s)
			if err != nil {
				return "", fmt.Errorf("failed to decode base64 data '%s'", s)
			}
			return string(sDec), nil
		},
	}
}
346663
func interpolationFuncBase64Encode() ast.Function {
	return ast.Function{
		ArgTypes:   []ast.Type{ast.TypeString},
		ReturnType: ast.TypeString,
		Callback: func(args []interface{}) (interface{}, error) {
			s := args[0].(string)
			return base64.StdEncoding.EncodeToString([]byte(s)), nil
		},
	}
}
859935
func ParseBase2Bytes(s string) (Base2Bytes, error) {
	n, err := ParseUnit(s, bytesUnitMap)
	if err != nil {
		n, err = ParseUnit(s, oldBytesUnitMap)
	}
	return Base2Bytes(n), err
}
573738
func (b *Buffer) Base64Decode(v []byte) error {
	enc := base64.RawURLEncoding
	out := make([]byte, enc.DecodedLen(len(v)))
	n, err := enc.Decode(out, v)
	if err != nil {
		return errors.Wrap(err, "failed to decode from base64")
	}
	out = out[:n]
	*b = Buffer(out)
	return nil
}
694246
func Decode58(inp string) (outp []byte, err error) {
	place := big.NewInt(1)
	base := big.NewInt(58)
	buf := []byte(inp)
	padlen := 0

	// Advance to first non-pad byte
	for ; padlen < len(buf); padlen++ {
		if buf[padlen] != alphabet[0] {
			break
		}
	}
	buf = buf[padlen:]
	reverseBuf(buf)

	tmp := new(big.Int)
	res := big.NewInt(0)

	for i, c := range buf {
		charIndex := alphabetMap[c]
		if charIndex == base58InvalidIndex {
			err = fmt.Errorf("Bad character '%c' found at pos %d", c, i)
			return
		}

		tmp.Mul(place, big.NewInt(int64(charIndex)))
		res.Add(res, tmp)

		if i != len(buf)-1 {
			place.Mul(place, base)
		}
	}
	buf = res.Bytes()
	pad := bytes.Repeat([]byte{0}, padlen)
	outp = append(pad, buf...)

	return
}
1080543
func interpolationFuncBasename() ast.Function {
	return ast.Function{
		ArgTypes:   []ast.Type{ast.TypeString},
		ReturnType: ast.TypeString,
		Callback: func(args []interface{}) (interface{}, error) {
			return filepath.Base(args[0].(string)), nil
		},
	}
}
1227685
func (p Protected) Base64() ([]byte, error) {
	b, err := json.Marshal(map[string]interface{}(p))
	if err != nil {
		return nil, err
	}
	return Base64Encode(b), nil
}
1265351
func (fn *Function) BaseName() string {
	if i := strings.LastIndex(fn.Name, "."); i != -1 {
		return fn.Name[i+1:]
	}
	return fn.Name
}
439854
func SafeBase64Decode(str string) (string, error) {
	str = strings.Replace(str, `-`, `/`, -1)
	str = strings.Replace(str, ` `, `+`, -1)
	var suf string
	for strings.HasSuffix(str, `_`) {
		str = strings.TrimSuffix(str, `_`)
		suf += `=`
	}
	str += suf
	return Base64Decode(str)
}
537108
func Md5Base64_32(data string) string {
	md5String := Md5Signature(data)

	return base64.StdEncoding.EncodeToString([]byte(md5String))
}
1198486
func (p *parserMixin) Float64() (target *float64) {
	target = new(float64)
	p.Float64Var(target)
	return
}
355239
func base64Decode(b []byte) []byte {
	n, _ := base64.StdEncoding.Decode(b, b)
	return b[:n]
}
436310
func (r *cmdRun) registerBaseFlags(defaultAuthOpts auth.Options) {
	r.Flags.BoolVar(&r.verbose, "verbose", false, "Enable more logging.")
	r.auth.Register(&r.Flags, defaultAuthOpts)
}
1227143
func getValidPrefix(s string, base int64) string {
	var (
		validLen int
		upper    rune
	)
	switch {
	case base >= 2 && base <= 9:
		upper = rune('0' + base)
	case base <= 36:
		upper = rune('A' + base - 10)
	default:
		return ""
	}
Loop:
	for i := 0; i < len(s); i++ {
		c := rune(s[i])
		switch {
		case unicode.IsDigit(c) || unicode.IsLower(c) || unicode.IsUpper(c):
			c = unicode.ToUpper(c)
			if c < upper {
				validLen = i + 1
			} else {
				break Loop
			}
		case c == '+' || c == '-':
			if i != 0 {
				break Loop
			}
		default:
			break Loop
		}
	}
	if validLen > 1 && s[0] == '+' {
		return s[1:validLen]
	}
	return s[:validLen]
}