singular_rules.go 750 B

1234567891011121314151617181920212223242526
  1. package flect
  2. var singularRules = []rule{}
  3. // AddSingular adds a rule that will replace the given suffix with the replacement suffix.
  4. // The name is confusing. This function will be deprecated in the next release.
  5. func AddSingular(ext string, repl string) {
  6. InsertSingularRule(ext, repl)
  7. }
  8. // InsertSingularRule inserts a rule that will replace the given suffix with
  9. // the repl(acement) at the beginning of the list of the singularize rules.
  10. func InsertSingularRule(suffix, repl string) {
  11. singularMoot.Lock()
  12. defer singularMoot.Unlock()
  13. singularRules = append([]rule{{
  14. suffix: suffix,
  15. fn: simpleRuleFunc(suffix, repl),
  16. }}, singularRules...)
  17. singularRules = append([]rule{{
  18. suffix: repl,
  19. fn: noop,
  20. }}, singularRules...)
  21. }