stash/pkg/utils/strings.go
departure18 776c7e6c35
Add penis length and circumcision stats to performers. (#3627)
* Add penis length stat to performers.
* Modified the UI to display and edit the stat.
* Added the ability to filter floats to allow filtering by penis length.
* Add circumcision stat to performer.
* Refactor enum filtering
* Change boolean filter to radio buttons
* Return null for empty enum values
---------
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
2023-05-24 13:19:35 +10:00

43 lines
892 B
Go

package utils
import (
"fmt"
"strings"
)
type StrFormatMap map[string]interface{}
// StrFormat formats the provided format string, replacing placeholders
// in the form of "{fieldName}" with the values in the provided
// StrFormatMap.
//
// For example,
//
// StrFormat("{foo} bar {baz}", StrFormatMap{
// "foo": "bar",
// "baz": "abc",
// })
//
// would return: "bar bar abc"
func StrFormat(format string, m StrFormatMap) string {
args := make([]string, len(m)*2)
i := 0
for k, v := range m {
args[i] = fmt.Sprintf("{%s}", k)
args[i+1] = fmt.Sprint(v)
i += 2
}
return strings.NewReplacer(args...).Replace(format)
}
// StringerSliceToStringSlice converts a slice of fmt.Stringers to a slice of strings.
func StringerSliceToStringSlice[V fmt.Stringer](v []V) []string {
ret := make([]string, len(v))
for i, vv := range v {
ret[i] = vv.String()
}
return ret
}