Skip to content

Commit

Permalink
👔 up(str/text): update the replacement format parse logic, allow one …
Browse files Browse the repository at this point in the history
…left char
  • Loading branch information
inhere committed Mar 5, 2023
1 parent b40b237 commit ccf2430
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion strutil/textutil/textutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestRenderSMap(t *testing.T) {

// custom format
assert.Equal(t, "hi inhere", textutil.RenderSMap("hi {$name}", tplVars, "{$,}"))
assert.Equal(t, "hi inhere age is 234", textutil.RenderSMap("hi $name age is $age", tplVars, "$,"))
assert.Equal(t, "hi inhere age is 234", textutil.RenderSMap("hi $name age is $age", tplVars, "$"))
assert.Equal(t, "hi inhere age is 234.", textutil.RenderSMap("hi $name age is $age.", tplVars, "$,"))
assert.Equal(t, "hi {$name}", textutil.RenderSMap("hi {$name}", nil, "{$,}"))
}
Expand Down
2 changes: 1 addition & 1 deletion strutil/textutil/var_replacer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewVarReplacer(format string) *VarReplacer {

// WithFormat custom var template
func (r *VarReplacer) WithFormat(format string) *VarReplacer {
r.Left, r.Right = strutil.MustCut(strutil.OrElse(format, defaultVarFormat), ",")
r.Left, r.Right = strutil.QuietCut(strutil.OrElse(format, defaultVarFormat), ",")
r.Init()
return r
}
Expand Down

0 comments on commit ccf2430

Please sign in to comment.