-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommon.h
More file actions
28 lines (23 loc) · 857 Bytes
/
Copy pathCommon.h
File metadata and controls
28 lines (23 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifndef Common_Included
#define Common_Included
#include <string>
/**
* Given a number, returns a version of that number with commas separating the digits.
*
* @param number The number in question
* @return The number with commas added.
*/
std::string addCommasTo(int number);
/* Given a quantity, returns a string of that quantity plus an appropriately-pluralized
* version of what it is.
*/
template <typename ValueType>
std::string pluralize(const ValueType& value, const std::string& singular, const std::string& plural) {
return std::to_string(value) + " " + (value == 1? singular : plural);
}
/* Assume we suffix with s to pluralize unless specified otherwise. */
template <typename ValueType>
std::string pluralize(const ValueType& value, const std::string& singular) {
return pluralize(value, singular, singular + "s");
}
#endif