// TranslateColumnToString converts a uint64 id to its associated string value.
// If the id is not associated with a string value then a blank string is returned.
346501
func (s *translateStore) TranslateColumnToString(index string, value uint64) (string, error) {
	s.mu.RLock()
	if idx := s.cols[index]; idx != nil {
		if ret, ok := idx.reverse[value]; ok {
			s.mu.RUnlock()
			return ret, nil
		}
	}
	s.mu.RUnlock()
	return "", nil
}
461921
func Translate(s, pat string) string {
	r := regexp.MustCompile(pat + "([0-9a-fklmnor])")
	return r.ReplaceAllString(s, "§$1")
}
210077
func (c Flags) ToString() (summary string) {
	for idx, v := range c {
		summary += "-" + v.Alias()
		if idx < len(c)-1 {
			summary += ", "
		}
	}

	if len(summary) > 0 {
		summary = "[" + summary + "]"
	}

	return
}
509160
func ToString(data interface{}) string {
	switch typed := data.(type) {
	case string:
		return typed
	case fmt.Stringer:
		return typed.String()
	default:
		return string(ToBytes(data))
	}
}
747857
func NewTranslation() *Translation {
	tr := new(Translation)
	tr.Trs = make(map[int]string)

	return tr
}
1219867
func floatStrToIntStr(validFloat string) (string, error) {
	var dotIdx = -1
	var eIdx = -1
	for i := 0; i < len(validFloat); i++ {
		switch validFloat[i] {
		case '.':
			dotIdx = i
		case 'e', 'E':
			eIdx = i
		}
	}
	if eIdx == -1 {
		if dotIdx == -1 {
			return validFloat, nil
		}
		return validFloat[:dotIdx], nil
	}
	var intCnt int
	digits := make([]byte, 0, len(validFloat))
	if dotIdx == -1 {
		digits = append(digits, validFloat[:eIdx]...)
		intCnt = len(digits)
	} else {
		digits = append(digits, validFloat[:dotIdx]...)
		intCnt = len(digits)
		digits = append(digits, validFloat[dotIdx+1:eIdx]...)
	}
	exp, err := strconv.Atoi(validFloat[eIdx+1:])
	if err != nil {
		return validFloat, errors.Trace(err)
	}
	if exp > 0 && intCnt > (math.MaxInt64-exp) {
		// (exp + incCnt) overflows MaxInt64.
		return validFloat, errors.Trace(ErrOverflow)
	}
	intCnt += exp
	if intCnt <= 0 {
		return "0", nil
	}
	if intCnt == 1 && (digits[0] == '-' || digits[0] == '+') {
		return "0", nil
	}
	var validInt string
	if intCnt <= len(digits) {
		validInt = string(digits[:intCnt])
	} else {
		extraZeroCount := intCnt - len(digits)
		if extraZeroCount > 20 {
			// Return overflow to avoid allocating too much memory.
			return validFloat, errors.Trace(ErrOverflow)
		}
		validInt = string(digits) + strings.Repeat("0", extraZeroCount)
	}
	return validInt, nil
}
652869
func (s *TranslateFile) TranslateRowToString(index, field string, id uint64) (string, error) {
	s.mu.RLock()
	if idx := s.rows[fieldKey{index, field}]; idx != nil {
		if ret, ok := idx.keyByID(id); ok {
			s.mu.RUnlock()
			return string(ret), nil
		}
	}
	s.mu.RUnlock()
	return "", nil
}
658598
func (r *Resp) ToString() (string, error) {
	data, err := r.ToBytes()
	return string(data), err
}
941321
func ToString(value interface{}) (string, error) {
	switch v := value.(type) {
	case bool:
		if v {
			return "1", nil
		}
		return "0", nil
	case int:
		return strconv.FormatInt(int64(v), 10), nil
	case int64:
		return strconv.FormatInt(int64(v), 10), nil
	case uint64:
		return strconv.FormatUint(uint64(v), 10), nil
	case float32:
		return strconv.FormatFloat(float64(v), 'f', -1, 32), nil
	case float64:
		return strconv.FormatFloat(float64(v), 'f', -1, 64), nil
	case string:
		return v, nil
	case []byte:
		return string(v), nil
	case Time:
		return v.String(), nil
	case Duration:
		return v.String(), nil
	case *MyDecimal:
		return v.String(), nil
	case Hex:
		return v.ToString(), nil
	case Bit:
		return v.ToString(), nil
	case Enum:
		return v.String(), nil
	case Set:
		return v.String(), nil
	default:
		return "", errors.Errorf("cannot convert %v(type %T) to string", value, value)
	}
}
140708
func (stmt InsertStmt) String() string {
	compiled, _ := stmt.Compile(&defaultDialect{}, Params())
	return compiled
}
1085901
func (version SVGVersion) ToString() string {
	ret := C.GoString(C.cairo_svg_version_to_string(C.cairo_svg_version_t(version)))
	return ret
}
683061
func (d *Document) TranslateIndexToPosition(index int) (row int, col int) {
	row, rowIndex := d.findLineStartIndex(index)
	col = index - rowIndex
	return
}
538337
func ToString(rcode int) string {
	if str, ok := dns.RcodeToString[rcode]; ok {
		return str
	}
	return "RCODE" + strconv.Itoa(rcode)
}
845348
func (t *queryTable) translateRowsToColumns() error {
	t.cols = make([]array.Interface, len(t.Cols()))
	for i := range t.row.Columns {
		col := t.Cols()[i]
		switch col.Type {
		case flux.TFloat:
			b := arrow.NewFloatBuilder(&memory.Allocator{})
			b.Reserve(t.Len())
			for _, row := range t.row.Values {
				val, ok := row[i].(float64)
				if !ok {
					return fmt.Errorf("unsupported type %T found in column %s of type %s", val, col.Label, col.Type)
				}
				b.Append(val)
			}
			t.cols[i] = b.NewArray()
			b.Release()
		case flux.TInt:
			b := arrow.NewIntBuilder(&memory.Allocator{})
			b.Reserve(t.Len())
			for _, row := range t.row.Values {
				val, ok := row[i].(int64)
				if !ok {
					return fmt.Errorf("unsupported type %T found in column %s of type %s", val, col.Label, col.Type)
				}
				b.Append(val)
			}
			t.cols[i] = b.NewArray()
			b.Release()
		case flux.TUInt:
			b := arrow.NewUintBuilder(&memory.Allocator{})
			b.Reserve(t.Len())
			for _, row := range t.row.Values {
				val, ok := row[i].(uint64)
				if !ok {
					return fmt.Errorf("unsupported type %T found in column %s of type %s", val, col.Label, col.Type)
				}
				b.Append(val)
			}
			t.cols[i] = b.NewArray()
			b.Release()
		case flux.TString:
			b := arrow.NewStringBuilder(&memory.Allocator{})
			b.Reserve(t.Len())
			for _, row := range t.row.Values {
				val, ok := row[i].(string)
				if !ok {
					return fmt.Errorf("unsupported type %T found in column %s of type %s", val, col.Label, col.Type)
				}
				b.AppendString(val)
			}
			t.cols[i] = b.NewArray()
			b.Release()
		case flux.TBool:
			b := arrow.NewBoolBuilder(&memory.Allocator{})
			b.Reserve(t.Len())
			for _, row := range t.row.Values {
				val, ok := row[i].(bool)
				if !ok {
					return fmt.Errorf("unsupported type %T found in column %s of type %s", val, col.Label, col.Type)
				}
				b.Append(val)
			}
			t.cols[i] = b.NewArray()
			b.Release()
		case flux.TTime:
			b := arrow.NewIntBuilder(&memory.Allocator{})
			b.Reserve(t.Len())
			for _, row := range t.row.Values {
				switch val := row[i].(type) {
				case int64:
					b.Append(val)
				case float64:
					b.Append(int64(val))
				case string:
					tm, err := time.Parse(time.RFC3339, val)
					if err != nil {
						return fmt.Errorf("could not parse string %q as time: %v", val, err)
					}
					b.Append(tm.UnixNano())
				default:
					return fmt.Errorf("unsupported type %T found in column %s", val, col.Label)
				}
			}
			t.cols[i] = b.NewArray()
			b.Release()
		default:
			return fmt.Errorf("invalid type %T found in column %s", col.Type, col.Label)
		}
	}

	for j := len(t.row.Columns); j < len(t.Cols()); j++ {
		b := arrow.NewStringBuilder(&memory.Allocator{})
		b.Reserve(t.Len())

		var value string
		if key := t.Cols()[j].Label; key == "_measurement" {
			value = t.row.Name
		} else {
			value = t.row.Tags[key]
		}

		for i := 0; i < t.Len(); i++ {
			b.AppendString(value)
		}
		t.cols[j] = b.NewArray()
		b.Release()
	}
	return nil
}
279658
func (s *TranslateFile) TranslateColumnsToUint64(index string, values []string) ([]uint64, error) {
	ret := make([]uint64, len(values))

	// Read value under read lock.
	s.mu.RLock()
	if idx := s.cols[index]; idx != nil {
		var writeRequired bool
		for i := range values {
			v, ok := idx.idByKey([]byte(values[i]))
			if !ok {
				writeRequired = true
			}
			ret[i] = v
		}
		if !writeRequired {
			s.mu.RUnlock()
			return ret, nil
		}
	}
	s.mu.RUnlock()

	// Return error if not all values could be translated and this store is read-only.
	if s.isReadOnly() {
		return ret, ErrTranslateStoreReadOnly
	}

	// If any values not found then recheck and then add under a write lock.
	s.mu.Lock()
	defer s.mu.Unlock()

	// Recheck if value was created between the read lock and write lock.
	idx := s.cols[index]
	if idx != nil {
		var writeRequired bool
		for i := range values {
			if ret[i] != 0 {
				continue
			}
			v, ok := idx.idByKey([]byte(values[i]))
			if !ok {
				writeRequired = true
				continue
			}
			ret[i] = v
		}
		if !writeRequired {
			return ret, nil
		}
	}

	// Create index map if it doesn't exists.
	if idx == nil {
		idx = newIndex(s.data)
		s.cols[index] = idx
	}

	// Append new identifiers to log.
	entry := &LogEntry{
		Type:  LogEntryTypeInsertColumn,
		Index: []byte(index),
		IDs:   make([]uint64, 0, len(values)),
		Keys:  make([][]byte, 0, len(values)),
	}

	check := make(map[string]uint64)
	for i := range values {
		if ret[i] != 0 {
			continue
		}
		v, found := check[values[i]]
		if !found {
			idx.seq++
			v = idx.seq
			check[values[i]] = v
		}

		ret[i] = v

		entry.IDs = append(entry.IDs, v)
		entry.Keys = append(entry.Keys, []byte(values[i]))
	}

	// Write entry.
	if err := s.appendEntry(entry); err != nil {
		return nil, err
	}

	return ret, nil
}
1355658
func (api *API) TranslateKeys(body io.Reader) ([]byte, error) {
	reqBytes, err := ioutil.ReadAll(body)
	if err != nil {
		return nil, NewBadRequestError(errors.Wrap(err, "read body error"))
	}
	var req TranslateKeysRequest
	if err := api.Serializer.Unmarshal(reqBytes, &req); err != nil {
		return nil, NewBadRequestError(errors.Wrap(err, "unmarshal body error"))
	}
	var ids []uint64
	if req.Field == "" {
		ids, err = api.holder.translateFile.TranslateColumnsToUint64(req.Index, req.Keys)
	} else {
		ids, err = api.holder.translateFile.TranslateRowsToUint64(req.Index, req.Field, req.Keys)
	}
	if err != nil {
		return nil, err
	}

	resp := TranslateKeysResponse{
		IDs: ids,
	}
	// Encode response.
	buf, err := api.Serializer.Marshal(&resp)
	if err != nil {
		return nil, errors.Wrap(err, "translate keys response encoding error")
	}
	return buf, nil
}
512203
func getCoordsFromCellIDString(cellIDString string) (x, y int, error error) {
	var letterPart string = strings.Map(letterOnlyMapF, cellIDString)
	y, error = strconv.Atoi(strings.Map(intOnlyMapF, cellIDString))
	if error != nil {
		return x, y, error
	}
	y -= 1 // Zero based
	x = lettersToNumeric(letterPart)
	return x, y, error
}