Documentation
¶
Overview ¶
Package textutil provide some extra text handle util
Index ¶
- func IsMatchAll(s string, keywords []string) bool
- func ParseInlineINI(tagVal string, keys ...string) (mp maputil.SMap, err error)
- func RenderSMap(text string, vars map[string]string, format string) string
- func ReplaceVars(text string, vars map[string]any, format string) string
- type FallbackFn
- type VarReplacer
- func (r *VarReplacer) DisableFlatten() *VarReplacer
- func (r *VarReplacer) Init() *VarReplacer
- func (r *VarReplacer) KeepMissingVars() *VarReplacer
- func (r *VarReplacer) MissVars() []string
- func (r *VarReplacer) OnNotFound(fn FallbackFn) *VarReplacer
- func (r *VarReplacer) ParseVars(s string) []string
- func (r *VarReplacer) Render(s string, tplVars map[string]any) string
- func (r *VarReplacer) RenderSimple(s string, varMap map[string]string) string
- func (r *VarReplacer) Replace(s string, tplVars map[string]any) string
- func (r *VarReplacer) ReplaceSMap(s string, varMap map[string]string) string
- func (r *VarReplacer) ResetMissVars()
- func (r *VarReplacer) WithFormat(format string) *VarReplacer
- func (r *VarReplacer) WithParseDefault() *VarReplacer
- func (r *VarReplacer) WithParseEnv() *VarReplacer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseInlineINI ¶ added in v0.6.5
ParseInlineINI parse config string to string-map. it's like INI format contents.
Examples:
eg: "name=val0;shorts=i;required=true;desc=a message"
=>
{name: val0, shorts: i, required: true, desc: a message}
func RenderSMap ¶ added in v0.6.7
RenderSMap by regex replace given tpl vars.
If format is empty, will use {const defaultVarFormat}
Types ¶
type FallbackFn ¶ added in v0.6.8
FallbackFn type
type VarReplacer ¶
type VarReplacer struct {
Left, Right string
// NotFound handler
NotFound FallbackFn
// contains filtered or unexported fields
}
VarReplacer struct
func NewFullReplacer ¶ added in v0.6.8
func NewFullReplacer(format string) *VarReplacer
NewFullReplacer instance
func NewVarReplacer ¶
func NewVarReplacer(format string, opFns ...func(vp *VarReplacer)) *VarReplacer
NewVarReplacer instance
func (*VarReplacer) DisableFlatten ¶ added in v0.6.8
func (r *VarReplacer) DisableFlatten() *VarReplacer
DisableFlatten on the input vars map
func (*VarReplacer) KeepMissingVars ¶ added in v0.6.8
func (r *VarReplacer) KeepMissingVars() *VarReplacer
KeepMissingVars on the replacement handle
func (*VarReplacer) MissVars ¶ added in v0.6.8
func (r *VarReplacer) MissVars() []string
MissVars list
func (*VarReplacer) OnNotFound ¶ added in v0.6.8
func (r *VarReplacer) OnNotFound(fn FallbackFn) *VarReplacer
OnNotFound var handle
func (*VarReplacer) ParseVars ¶ added in v0.6.8
func (r *VarReplacer) ParseVars(s string) []string
ParseVars the text contents and collect vars
func (*VarReplacer) Render ¶ added in v0.6.8
func (r *VarReplacer) Render(s string, tplVars map[string]any) string
Render any-map vars in the text contents
func (*VarReplacer) RenderSimple ¶ added in v0.6.7
func (r *VarReplacer) RenderSimple(s string, varMap map[string]string) string
RenderSimple string-map vars in the text contents. alias of ReplaceSMap()
func (*VarReplacer) Replace ¶
func (r *VarReplacer) Replace(s string, tplVars map[string]any) string
Replace any-map vars in the text contents
func (*VarReplacer) ReplaceSMap ¶ added in v0.6.8
func (r *VarReplacer) ReplaceSMap(s string, varMap map[string]string) string
ReplaceSMap string-map vars in the text contents
func (*VarReplacer) ResetMissVars ¶ added in v0.6.8
func (r *VarReplacer) ResetMissVars()
ResetMissVars list
func (*VarReplacer) WithFormat ¶
func (r *VarReplacer) WithFormat(format string) *VarReplacer
WithFormat custom var template
func (*VarReplacer) WithParseDefault ¶ added in v0.6.8
func (r *VarReplacer) WithParseDefault() *VarReplacer
WithParseDefault value on the input template contents
func (*VarReplacer) WithParseEnv ¶ added in v0.6.8
func (r *VarReplacer) WithParseEnv() *VarReplacer
WithParseEnv on the input vars value