From 4e5e89b32854b9b6f542c45fad2dd9d6a2b54884 Mon Sep 17 00:00:00 2001
From: ilor <kailoran@gmail.com>
Date: Wed, 23 Feb 2011 12:27:51 +0100
Subject: [PATCH] plural functions in pwrutils

---
 libpwrutils/CMakeLists.txt |  1 +
 libpwrutils/plural.cpp     | 80 ++++++++++++++++++++++++++++++++++++++
 libpwrutils/plural.h       | 43 ++++++++++++++++++++
 3 files changed, 124 insertions(+)
 create mode 100644 libpwrutils/plural.cpp
 create mode 100644 libpwrutils/plural.h

diff --git a/libpwrutils/CMakeLists.txt b/libpwrutils/CMakeLists.txt
index 515e79b..56f110e 100644
--- a/libpwrutils/CMakeLists.txt
+++ b/libpwrutils/CMakeLists.txt
@@ -29,6 +29,7 @@ SET(libpwrutils_STAT_SRC
 	exception.cpp
 	whitespace.cpp
 	pathsearch.cpp
+	plural.cpp
 	util.cpp
 )
 
diff --git a/libpwrutils/plural.cpp b/libpwrutils/plural.cpp
new file mode 100644
index 0000000..092f5c7
--- /dev/null
+++ b/libpwrutils/plural.cpp
@@ -0,0 +1,80 @@
+/*
+    Copyright (C) 2010 Tomasz Åšniatowski, Adam Radziszewski
+
+    This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3 of the License, or (at your option)
+any later version.
+
+    This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. 
+
+    See the LICENSE and COPYING files for more details.
+*/
+
+#include <libpwrutils/plural.h>
+#include <sstream>
+
+namespace PwrNlp {
+
+std::string enpl(int amount, const std::string& sg)
+{
+	if (amount == 1) {
+		return sg;
+	} else {
+		return sg + "s";
+	}
+}
+
+std::string enpln(int amount, const std::string& sg)
+{
+	std::stringstream ss;
+	ss << amount << " " << enpl(amount, sg);
+	return ss.str();
+}
+
+std::string enpl(int amount, const std::string& sg, const std::string& pl)
+{
+	if (amount == 1) {
+		return sg;
+	} else {
+		return pl;
+	}
+}
+
+std::string enpln(int amount, const std::string& sg, const std::string& pl)
+{
+	std::stringstream ss;
+	ss << amount << " " << enpl(amount, sg, pl);
+	return ss.str();
+}
+
+
+std::string plpl(int amount, const std::string& gen0, const std::string& nom1, const std::string& acc2)
+{
+	if (amount == 1) {
+		return nom1;
+	} else {
+		amount %= 100;
+		if (amount > 10 && amount < 20) {
+			return gen0;
+		} else {
+			amount %= 10;
+			if (amount == 2 || amount == 3 || amount == 4) {
+				return acc2;
+			} else {
+				return gen0;
+			}
+		}
+	}
+}
+
+std::string plpln(int amount, const std::string& gen0, const std::string& nom1, const std::string& acc2)
+{
+	std::stringstream ss;
+	ss << amount << " " << plpl(amount, gen0, nom1, acc2);
+	return ss.str();
+}
+
+} /* end namespace PwrNlp */
diff --git a/libpwrutils/plural.h b/libpwrutils/plural.h
new file mode 100644
index 0000000..17a0ab6
--- /dev/null
+++ b/libpwrutils/plural.h
@@ -0,0 +1,43 @@
+/*
+    Copyright (C) 2010 Tomasz Åšniatowski, Adam Radziszewski
+
+    This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3 of the License, or (at your option)
+any later version.
+
+    This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. 
+
+    See the LICENSE and COPYING files for more details.
+*/
+
+#ifndef PWRNLP_PLURAL_H
+#define PWRNLP_PLURAL_H
+
+#include <string>
+
+namespace PwrNlp {
+
+/// Pluralize sg according to amount, regular English plural
+std::string enpl(int amount, const std::string& sg);
+
+/// Pluralize (English), output the number and the pluralized word
+std::string enpln(int amount, const std::string& sg);
+
+/// Pluralize according to amount, custom English-style plural
+std::string enpl(int amount, const std::string& sg, const std::string& pl);
+
+/// Pluralize (English), output the number and the pluralized word
+std::string enpln(int amount, const std::string& sg, const std::string& pl);
+
+/// Pluralize according to amount, Polish plural
+std::string plpl(int amount, const std::string& gen0, const std::string& nom1, const std::string& acc2);
+
+/// Pluralize (Polish) output the number and the pluralized word
+std::string plpln(int amount, const std::string& gen0, const std::string& nom1, const std::string& acc2);
+
+} /* end ns PwrNlp */
+
+#endif // PWRNLP_PATHSEARCH_H
-- 
GitLab