summaryrefslogtreecommitdiff
path: root/plural.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-08-12 14:05:45 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-08-12 14:05:45 +0200
commit14a6aa4c488bcd2d49103cbee1424b2769d77ce0 (patch)
tree93e3875919eeb0e60d0a8da70f5d96152a4e527a /plural.go
Initial import
Diffstat (limited to 'plural.go')
-rw-r--r--plural.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/plural.go b/plural.go
new file mode 100644
index 0000000..ba8e802
--- /dev/null
+++ b/plural.go
@@ -0,0 +1,36 @@
+package main
+
+import "strings"
+
+func Plural(s string) string {
+ l := len(s)
+ switch {
+ case strings.HasSuffix(s, "y"):
+ return s[:l-1] + "ies"
+ case strings.HasSuffix(s, "us"):
+ return s[:l-2] + "i"
+ case strings.HasSuffix(s, "ch"),
+ strings.HasSuffix(s, "x"),
+ strings.HasSuffix(s, "s"):
+ return s + "es"
+ case strings.HasSuffix(s, "f"):
+ return s[:l-1] + "ves"
+ case strings.HasSuffix(s, "man"),
+ strings.HasSuffix(s, "Man"):
+ return s[:l-2] + "en"
+ default:
+ return s + "s"
+ }
+}
+
+func Indefinite(s string, n int) string {
+ if strings.IndexByte("AEIOUÜaeiouü", s[0]) > 0 {
+ s = "an " + s
+ } else {
+ s = "a " + s
+ }
+ if n > 1 {
+ s = Plural(s)
+ }
+ return s
+}