package misc

import (
	"bytes"
	"strconv"
	"strings"
)

// TwoSpotValue returns value from "key:value" line
func TwoSpotValue(line string) string {
	return strings.TrimSpace(strings.SplitN(line, ":", 2)[1])
}

// RemoveQuoteMark removes quote marks
func RemoveQuoteMark(line string) string {
	return strings.ReplaceAll(strings.ReplaceAll(line, "\"", ""), "'", "")
}

// IntExtractor returns inv value from string represents of int
func IntExtractor(val string) int {
	res, err := strconv.Atoi(val)
	if err != nil {
		return -1
	}
	return res
}

// RemoveBraces remove braces from line
func RemoveBraces(line string) string {
	line = strings.ReplaceAll(strings.ReplaceAll(line, "(", ""), ")", "")
	line = strings.ReplaceAll(strings.ReplaceAll(line, "{", ""), "}", "")
	line = strings.ReplaceAll(strings.ReplaceAll(line, "[", ""), "]", "")
	return line
}

func TrimOut(out []byte, err error) ([]byte, error) {
	out = bytes.TrimSpace(out)
	return out, err
}
