Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 54c729c973fa1336f9a36e66c2041d48b3e52423 1 parent 887e287
Sean Grove authored
Showing with 26 additions and 23 deletions.
  1. +19 −2 README.md
  2. +7 −21 inflector.lisp
21 README.md
View
@@ -12,9 +12,20 @@ Installation
Usage
-----------
-Basic Usage, `plural-of` and `singular-of`:
+Example Usage:
(use-package :vana-inflector)
+ > (let ((dollars 1.7)
+ (users 34)
+ (purchases 1))
+ (format nil "The site has ~D ~A, with a total of ~D ~A and $~D ~A"
+ users (pluralize users "user")
+ purchases (pluralize purchases "purchase")
+ dollars (pluralize dollars "dollar")))
+ "The site has 34 users, with a total of 1 purchase and $1.7 dollars"
+
+Basic Usage, `plural-of` and `singular-of`:
+
> (plural-of "octopus")
"octopi"
> (plural-of "datum")
@@ -28,12 +39,18 @@ Basic Usage, `plural-of` and `singular-of`:
Basic Usage, `pluralize`:
- (use-package :vana-inflector)
> (pluralize 2 "octopus")
"octopi"
> (pluralize 1 "octopus")
"octopus"
+You can pass in the default plural to be used. If not, the inflector is used to determine the plural.
+
+ > (pluralize 2 "tooth" "teeth")
+ "teeth"
+ > (pluralize 2 "tooth")
+ "tooths"
+
Use `irregular` to add an irregular:
> (singular-of "feet")
28 inflector.lisp
View
@@ -15,7 +15,7 @@
;; Adapted *cough*ripped*cough* from rails inflector.rb
;;; singular->plurals regular expressions
-(defvar **plurals**
+(setf **plurals**
(reverse (list (list "$" "s")
(list "s$" "s")
(list "(ax|test)is$" "\\1es")
@@ -25,7 +25,7 @@
(list "(buffal|tomat)o$" "\\1oes")
(list "([ti])um$" "\\1a")
(list "sis$" "ses")
- (list "(?:([^f])fe|([lr])f)$" "\\1\2ves")
+ (list "(?:([^f])fe|([lr])f)$" "\\1\\2ves")
(list "(hive)$" "\\1s")
(list "([^aeiouy]|qu)y$" "\\1ies")
(list "(x|ch|ss|sh)$" "\\1es")
@@ -121,11 +121,6 @@
((irregular? word) (get-irregular-singular word))
(t (inflector-helper word **singulars**))))
-(defun pluralize (count word)
- (if (not (= count 1))
- (plural-of word)
- word))
-
(defun inflector-helper (word regexes)
(if (null regexes)
word
@@ -135,17 +130,8 @@
string
(inflector-helper word (rest regexes))))))
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+(defun pluralize (count word &optional plural)
+ (if (not (= count 1))
+ (or plural
+ (plural-of word))
+ word))
Please sign in to comment.
Something went wrong with that request. Please try again.