MCPcopy
hub / github.com/pocketbase/pocketbase / Singularize

Function Singularize

tools/inflector/singularize.go:64–89  ·  view source on GitHub ↗

Singularize converts the specified word into its singular version. For example: inflector.Singularize("people") // "person"

(word string)

Source from the content-addressed store, hash-verified

62//
63// inflector.Singularize("people") // "person"
64func Singularize(word string) string {
65 if word == "" {
66 return ""
67 }
68
69 for _, rule := range singularRules {
70 re := compiledPatterns.GetOrSet(rule.pattern, func() *regexp.Regexp {
71 re, err := regexp.Compile(rule.pattern)
72 if err != nil {
73 return nil
74 }
75 return re
76 })
77 if re == nil {
78 // log only for debug purposes
79 log.Println("[Singularize] failed to retrieve/compile rule pattern " + rule.pattern)
80 continue
81 }
82
83 if re.MatchString(word) {
84 return re.ReplaceAllString(word, rule.replacement)
85 }
86 }
87
88 return word
89}

Callers 1

TestSingularizeFunction · 0.92

Calls 1

GetOrSetMethod · 0.80

Tested by 1

TestSingularizeFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…