From beafe98a63d782fccf7324bc48a5f5394b46b591 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Fri, 6 Jul 2007 10:42:29 +0000 Subject: [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 --- crawl-ref/source/libutil.cc | 47 +++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) (limited to 'crawl-ref/source/libutil.cc') 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")) -- cgit v1.2.3-54-g00ecf