diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2018-11-17 13:01:20 -0500 |
|---|---|---|
| committer | Dave Henderson <dhenderson@gmail.com> | 2018-11-17 13:01:20 -0500 |
| commit | a95a25dac45df2fd04fba321eb66dbb868c1283a (patch) | |
| tree | e6e8b0d9d451b2ce5e64dfec6e08f749722940d1 /funcs/strings.go | |
| parent | 0cf7734ef776cc7701dfbb08b080cecf5066f0eb (diff) | |
Adding quote and squote functions
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'funcs/strings.go')
| -rw-r--r-- | funcs/strings.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/funcs/strings.go b/funcs/strings.go index f803a48d..fbf58dcc 100644 --- a/funcs/strings.go +++ b/funcs/strings.go @@ -6,6 +6,7 @@ package funcs // in templates easier. import ( + "fmt" "sync" "github.com/Masterminds/goutils" @@ -40,6 +41,8 @@ func AddStringFuncs(f map[string]interface{}) { f["trimSpace"] = StrNS().TrimSpace f["indent"] = StrNS().Indent f["sort"] = StrNS().Sort + f["quote"] = StrNS().Quote + f["squote"] = StrNS().Squote // these are legacy aliases with non-pipelinable arg order f["contains"] = strings.Contains @@ -208,3 +211,15 @@ func (f *StringFuncs) Indent(args ...interface{}) (string, error) { func (f *StringFuncs) Slug(in interface{}) string { return slug.Make(conv.ToString(in)) } + +// Quote - +func (f *StringFuncs) Quote(in interface{}) string { + return fmt.Sprintf("%q", conv.ToString(in)) +} + +// Squote - +func (f *StringFuncs) Squote(in interface{}) string { + s := conv.ToString(in) + s = strings.Replace(s, `'`, `''`, -1) + return fmt.Sprintf("'%s'", s) +} |
