Add support for titlecase transformation to strings processor (#6982)

This commit is contained in:
Manthan Sharma
2020-02-05 07:02:41 +05:30
committed by GitHub
parent 0cc71dbd51
commit ae22db4b81
3 changed files with 61 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ import (
type Strings struct {
Lowercase []converter `toml:"lowercase"`
Uppercase []converter `toml:"uppercase"`
Titlecase []converter `toml:"titlecase"`
Trim []converter `toml:"trim"`
TrimLeft []converter `toml:"trim_left"`
TrimRight []converter `toml:"trim_right"`
@@ -55,6 +56,10 @@ const sampleConfig = `
# field = "uri_stem"
# dest = "uri_stem_normalised"
## Convert a field value to titlecase
# [[processors.strings.titlecase]]
# field = "status"
## Trim leading and trailing whitespace using the default cutset
# [[processors.strings.trim]]
# field = "message"
@@ -235,6 +240,10 @@ func (s *Strings) initOnce() {
c.fn = strings.ToUpper
s.converters = append(s.converters, c)
}
for _, c := range s.Titlecase {
c.fn = strings.Title
s.converters = append(s.converters, c)
}
for _, c := range s.Trim {
c := c
if c.Cutset != "" {