func TrimToNumber(text string) string {
	leftTrimmed := strings.TrimLeftFunc(text, func(r rune) bool {
		return (r < '0' || r > '9') && r != '-'
	})
	return strings.TrimRightFunc(leftTrimmed, func(r rune) bool {
		return r < '0' || r > '9'
	})
}
TrimToNumber removes all characters from the left and right of the string
that are not in the set [\-0-9] on the left or [0-9] on the right
package tstrings
import (
	"encoding/json"
	"fmt"
	"math"
	"reflect"
	"strconv"
	"strings"
	"unsafe"
)
var simpleEscapeChars = strings.NewReplacer("\\n", "\n", "\\r", "\r", "\\t", "\t", "\\f", "\f", "\\b", "\b")
var jsonEscapeChars = strings.NewReplacer("\\", "\\\\", "\"", "\\\"", "\\n", "\n", "\\r", "\r", "\\t", "\t", "\\f", "\f", "\\b", "\b")
func Unescape(text string) string {
	return simpleEscapeChars.Replace(text)
}
func EscapeJSON(text string) string {
	return jsonEscapeChars.Replace(text)
}
func ItoLen(number uint64) int {
	switch {
	case number < 10:
		return 1
	default:
		return int(math.Log10(float64(number)) + 1)
	}
}
func Itob(number uint64, buffer []byte) error {
	numberLen := ItoLen(number)
	bufferLen := len(buffer)
	if numberLen > bufferLen {
		return fmt.Errorf("Number too large for buffer")
	}
	for i := numberLen - 1; i >= 0; i-- {
		buffer[i] = '0' + byte(number%10)
		number /= 10
	}
	return nil
}
func Itobe(number uint64, buffer []byte) error {
	for i := len(buffer) - 1; i >= 0; i-- {
		buffer[i] = '0' + byte(number%10)
		number /= 10
		if number == 0 {
			return nil
		}
	}
	return fmt.Errorf("Number too large for buffer")
}
func Btoi(buffer []byte) (uint64, int) {
	number := uint64(0)
	index := 0
	bufferLen := len(buffer)
	for index < bufferLen && buffer[index] >= '0' && buffer[index] <= '9' {
		parsed := uint64(buffer[index] - '0')
		number = number*10 + parsed
		index++
	}
	return number, index
}
func IndexN(s, sep string, n int) int {
	sepIdx := 0
	for i := 0; i < n; i++ {
		nextIdx := strings.Index(s[sepIdx:], sep)
		if nextIdx == -1 {
			return -1  
		}
		sepIdx += nextIdx + 1
	}
	return sepIdx - 1
}
func LastIndexN(s, sep string, n int) int {
	if n == 0 {
		return -1  
	}
	sepIdx := len(s)
	for i := 0; i < n; i++ {
		sepIdx = strings.LastIndex(s[:sepIdx], sep)
		if sepIdx == -1 {
			return -1  
		}
	}
	return sepIdx
}
func IsInt(s string) bool {
	for i, c := range s {
		if (c < '0' || c > '9') && (c != '-' || i != 0) {
			return false
		}
	}
	return true
}
func IsJSON(data []byte) (bool, error, *json.RawMessage) {
	delayedResult := new(json.RawMessage)
	err := json.Unmarshal(data, delayedResult)
	return err == nil, err, delayedResult
}
type ByteRef []byte
func NewByteRef(a string) ByteRef {
	stringHeader := (*reflect.StringHeader)(unsafe.Pointer(&a))
	sliceHeader := &reflect.SliceHeader{
		Data: stringHeader.Data,
		Len:  stringHeader.Len,
		Cap:  stringHeader.Len,
	}
	return *(*ByteRef)(unsafe.Pointer(sliceHeader))
}
type StringRef string
func NewStringRef(a []byte) StringRef {
	sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&a))
	stringHeader := &reflect.StringHeader{
		Data: sliceHeader.Data,
		Len:  sliceHeader.Len,
	}
	return *(*StringRef)(unsafe.Pointer(stringHeader))
}
func JoinStringers(a []fmt.Stringer, sep string) string {
	if len(a) == 0 {
		return ""
	}
	if len(a) == 1 {
		return a[0].String()
	}
	str := make([]string, len(a))
	for i, s := range a {
		str[i] = s.String()
	}
	return strings.Join(str, sep)
}