Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Updated README, and also escaped a backslash in one of the regexes

  • Loading branch information...
commit 54c729c973fa1336f9a36e66c2041d48b3e52423 1 parent 887e287
Sean Grove authored

Showing 2 changed files with 26 additions and 23 deletions. Show diff stats Hide diff stats

  1. +19 2 README.md
  2. +7 21 inflector.lisp
21 README.md
Source Rendered
@@ -12,9 +12,20 @@ Installation
12 12
13 13 Usage
14 14 -----------
15   -Basic Usage, `plural-of` and `singular-of`:
  15 +Example Usage:
16 16
17 17 (use-package :vana-inflector)
  18 + > (let ((dollars 1.7)
  19 + (users 34)
  20 + (purchases 1))
  21 + (format nil "The site has ~D ~A, with a total of ~D ~A and $~D ~A"
  22 + users (pluralize users "user")
  23 + purchases (pluralize purchases "purchase")
  24 + dollars (pluralize dollars "dollar")))
  25 + "The site has 34 users, with a total of 1 purchase and $1.7 dollars"
  26 +
  27 +Basic Usage, `plural-of` and `singular-of`:
  28 +
18 29 > (plural-of "octopus")
19 30 "octopi"
20 31 > (plural-of "datum")
@@ -28,12 +39,18 @@ Basic Usage, `plural-of` and `singular-of`:
28 39
29 40 Basic Usage, `pluralize`:
30 41
31   - (use-package :vana-inflector)
32 42 > (pluralize 2 "octopus")
33 43 "octopi"
34 44 > (pluralize 1 "octopus")
35 45 "octopus"
36 46
  47 +You can pass in the default plural to be used. If not, the inflector is used to determine the plural.
  48 +
  49 + > (pluralize 2 "tooth" "teeth")
  50 + "teeth"
  51 + > (pluralize 2 "tooth")
  52 + "tooths"
  53 +
37 54 Use `irregular` to add an irregular:
38 55
39 56 > (singular-of "feet")
28 inflector.lisp
@@ -15,7 +15,7 @@
15 15
16 16 ;; Adapted *cough*ripped*cough* from rails inflector.rb
17 17 ;;; singular->plurals regular expressions
18   -(defvar **plurals**
  18 +(setf **plurals**
19 19 (reverse (list (list "$" "s")
20 20 (list "s$" "s")
21 21 (list "(ax|test)is$" "\\1es")
@@ -25,7 +25,7 @@
25 25 (list "(buffal|tomat)o$" "\\1oes")
26 26 (list "([ti])um$" "\\1a")
27 27 (list "sis$" "ses")
28   - (list "(?:([^f])fe|([lr])f)$" "\\1\2ves")
  28 + (list "(?:([^f])fe|([lr])f)$" "\\1\\2ves")
29 29 (list "(hive)$" "\\1s")
30 30 (list "([^aeiouy]|qu)y$" "\\1ies")
31 31 (list "(x|ch|ss|sh)$" "\\1es")
@@ -121,11 +121,6 @@
121 121 ((irregular? word) (get-irregular-singular word))
122 122 (t (inflector-helper word **singulars**))))
123 123
124   -(defun pluralize (count word)
125   - (if (not (= count 1))
126   - (plural-of word)
127   - word))
128   -
129 124 (defun inflector-helper (word regexes)
130 125 (if (null regexes)
131 126 word
@@ -135,17 +130,8 @@
135 130 string
136 131 (inflector-helper word (rest regexes))))))
137 132
138   -
139   -
140   -
141   -
142   -
143   -
144   -
145   -
146   -
147   -
148   -
149   -
150   -
151   -
  133 +(defun pluralize (count word &optional plural)
  134 + (if (not (= count 1))
  135 + (or plural
  136 + (plural-of word))
  137 + word))

0 comments on commit 54c729c

Please sign in to comment.
Something went wrong with that request. Please try again.