summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/libutil.cc
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-07-06 10:42:29 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-07-06 10:42:29 +0000
commitbeafe98a63d782fccf7324bc48a5f5394b46b591 (patch)
tree16fc10f0be2ac1f18665257799def758170e8da5 /crawl-ref/source/libutil.cc
parent862f907158311aa239b0a82fa4abb4a4e398861d (diff)
downloadcrawl-ref-beafe98a63d782fccf7324bc48a5f5394b46b591.tar.gz
crawl-ref-beafe98a63d782fccf7324bc48a5f5394b46b591.zip
[1748837] Merge identical features when reporting explore discoveries,
distinguish between stairs and portals. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1770 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/libutil.cc')
-rw-r--r--crawl-ref/source/libutil.cc47
1 files changed, 35 insertions, 12 deletions
diff --git a/crawl-ref/source/libutil.cc b/crawl-ref/source/libutil.cc
index 14fe074a33..09f86ce2fd 100644
--- a/crawl-ref/source/libutil.cc
+++ b/crawl-ref/source/libutil.cc
@@ -129,23 +129,46 @@ int ends_with(const std::string &s, const char *suffixes[])
return (0);
}
+// Naively prefix A/an to a noun.
+std::string article_a(const std::string &name, bool lowercase)
+{
+ if (!name.length()) return name;
+ const char *a = lowercase? "a " : "A ";
+ const char *an = lowercase? "an " : "An ";
+ switch (name[0])
+ {
+ case 'a': case 'e': case 'i': case 'o': case 'u':
+ case 'A': case 'E': case 'I': case 'O': case 'U':
+ return an + name;
+ default:
+ return a + name;
+ }
+}
+
+const char *standard_plural_qualifiers[] =
+{
+ " of ", " labeled "
+};
+
// Pluralises a monster or item name. This'll need to be updated for
// correctness whenever new monsters/items are added.
-std::string pluralise(const std::string &name,
- const char *no_of[])
+std::string pluralise(const std::string &name,
+ const char *qualifiers[],
+ const char *no_qualifier[])
{
std::string::size_type pos;
- // Pluralise first word of names like 'eye of draining' or
- // 'scrolls labeled FOOBAR', but only if the whole name is not
- // suffixed by a supplied modifier, such as 'zombie' or 'skeleton'
- if ( (pos = name.find(" of ")) != std::string::npos
- && !ends_with(name, no_of) )
- return pluralise(name.substr(0, pos)) + name.substr(pos);
- else if ( (pos = name.find(" labeled ")) != std::string::npos
- && !ends_with(name, no_of) )
- return pluralise(name.substr(0, pos)) + name.substr(pos);
- else if (ends_with(name, "us"))
+ if (qualifiers)
+ {
+ for (int i = 0; qualifiers[i]; ++i)
+ if ((pos = name.find(qualifiers[i])) != std::string::npos
+ && !ends_with(name, no_qualifier))
+ {
+ return pluralise(name.substr(0, pos)) + name.substr(pos);
+ }
+ }
+
+ if (ends_with(name, "us"))
// Fungus, ufetubus, for instance.
return name.substr(0, name.length() - 2) + "i";
else if (ends_with(name, "larva") || ends_with(name, "amoeba"))