// ConvertString converts a string from d's encoding to UTF-8.
179856
func (d Decoder) ConvertString(s string) string {
	bytes := []byte(s)
	runes := make([]rune, len(s))
	destPos := 0

	for len(bytes) > 0 {
		c, size, status := d(bytes)

		if status == STATE_ONLY {
			bytes = bytes[size:]
			continue
		}

		if status == NO_ROOM {
			c = 0xfffd
			size = len(bytes)
			status = INVALID_CHAR
		}

		bytes = bytes[size:]
		runes[destPos] = c
		destPos++
	}

	return string(runes[:destPos])
}
1176476
func Int64ToString(from int64) (string, error) {
	return strconv.FormatInt(int64(from), DefeultNumericBase), nil
}
224340
func (p *Parser) ParseString(src string) (model.Stmts, error) {
	return p.Parse([]byte(src))
}
41842
func (d *Diskv) ReadString(key string) string {
	value, _ := d.Read(key)
	return string(value)
}
153853
func (p *Buffer) DecodeStringBytes() (s string, err error) {
	buf, err := p.DecodeRawBytes(false)
	if err != nil {
		return
	}
	return string(buf), nil
}
283134
func ConvertToString(b []byte) string {
	s := make([]string, len(b))
	for i := range b {
		s[i] = strconv.Itoa(int(b[i]))
	}
	return strings.Join(s, ",")
}
874577
func (e *Encoding) EncodeToString(src []byte) string {
	dst := make([]byte, EncodedLen(len(src)))
	e.Encode(dst, src)
	return string(dst)
}
196531
func (s Slice) GetString() (string, error) {
	bytes, err := s.GetStringUTF8()
	if err != nil {
		return "", WithStack(err)
	}
	return string(bytes), nil
}
1180560
func (wd *WeightDevice) WeightString() string {
	return fmt.Sprintf("%d:%d %d", wd.Major, wd.Minor, wd.Weight)
}
607603
func (enc *Encoding) DecodeString(s string) ([]byte, error) {
	dbuf := make([]byte, enc.DecodedLen(len(s)))
	n, _, err := enc.decode(dbuf, []byte(s))
	return dbuf[:n], err
}
660704
func utf8ToString(iso8859_1_buf []byte) string {
	buf := make([]rune, len(iso8859_1_buf))
	for i, b := range iso8859_1_buf {
		buf[i] = rune(b)
	}
	return string(buf)
}
367413
func decodeBinaryString(s string) ([]byte, error) {
	if len(s)&7 != 0 {
		// prepend the padding
		s = strings.Repeat("0", 8-len(s)&7) + s
	}

	data := make([]byte, len(s)>>3)

	for i, dstIndex := 0, 0; i < len(s); i = i + 8 {
		value, err := strconv.ParseInt(s[i:i+8], 2, 0)
		if err != nil {
			return nil, fmt.Errorf("error while conversion: %s", err)
		}

		data[dstIndex] = byte(value)
		dstIndex++
	}

	return data, nil
}
1171443
func DecryptString(str, key string) (string, error) {
	k := []byte(key)
	b64 := base64.StdEncoding
	decodeStr, err := b64.DecodeString(str)
	if err != nil {
		return "", err
	}
	result := Decrypt([]byte(decodeStr), k)
	return string(result), nil
}
1032687
func DataToString(i interface{}) string {
	switch v := i.(type) {
	case string:
		return v
	case fmt.Stringer:
		return v.String()
	case uint8, int8, uint16, int16, uint32, int32, uint64, int64, int, uint:
		return fmt.Sprintf("%d", v)
	case []byte:
		return string(v)
	default:
		panic("unknown type")
	}
}
307918
func (l *Literal) ToComparableString() string {
	s := ""
	switch l.t {
	case Int64:
		s = fmt.Sprintf("\"%032d\"^^type:%v", l.Interface(), l.Type())
	case Float64:
		s = fmt.Sprintf("\"%032f\"^^type:%v", l.Interface(), l.Type())
	default:
		s = l.String()
	}
	return s
}
1141702
func DecodeString(src string) (body []byte, err error) {
	body, err = Encoding.DecodeString(src)
	return
}
764193
func (b *builtinConvertSig) evalString(row chunk.Row) (string, bool, error) {
	expr, isNull, err := b.args[0].EvalString(b.ctx, row)
	if isNull || err != nil {
		return "", true, err
	}

	// Since charset is already validated and set from getFunction(), there's no
	// need to get charset from args again.
	encoding, _ := charset.Lookup(b.tp.Charset)
	// However, if `b.tp.Charset` is abnormally set to a wrong charset, we still
	// return with error.
	if encoding == nil {
		return "", true, errUnknownCharacterSet.GenWithStackByArgs(b.tp.Charset)
	}

	target, _, err := transform.String(encoding.NewDecoder(), expr)
	return target, err != nil, err
}