summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/database.cc
diff options
context:
space:
mode:
authorzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2007-09-21 05:11:51 +0000
committerzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2007-09-21 05:11:51 +0000
commite6f92f58fb62ddc074838485a4dac3ce5d068a8d (patch)
treeee54c4fa76b0f06d48e398e3d0faf5e1adb31880 /crawl-ref/source/database.cc
parent1640dccce5b2bab627f03607f80bfc7cd4b57327 (diff)
downloadcrawl-ref-e6f92f58fb62ddc074838485a4dac3ce5d068a8d.tar.gz
crawl-ref-e6f92f58fb62ddc074838485a4dac3ce5d068a8d.zip
Can now search the description database by name (keyword) with '?/'.
Not adding to 0.3-branch yet in case it needs some tweaks. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2170 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/database.cc')
-rw-r--r--crawl-ref/source/database.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/crawl-ref/source/database.cc b/crawl-ref/source/database.cc
index f8c97a354c..6de91c3a1e 100644
--- a/crawl-ref/source/database.cc
+++ b/crawl-ref/source/database.cc
@@ -152,6 +152,28 @@ datum database_fetch(DBM *database, const std::string &key)
return result;
}
+std::vector<std::string> database_find_keys(DBM *database,
+ const std::string &regex,
+ bool ignore_case)
+{
+ text_pattern tpat(regex, ignore_case);
+ std::vector<std::string> matches;
+
+ datum dbKey = dbm_firstkey(database);
+
+ while (dbKey.dptr != NULL)
+ {
+ std::string key((const char *)dbKey.dptr, dbKey.dsize);
+
+ if (tpat.matches(key))
+ matches.push_back(key);
+
+ dbKey = dbm_nextkey(database);
+ }
+
+ return (matches);
+}
+
///////////////////////////////////////////////////////////////////////////
// Internal DB utility functions
static void trim_right(std::string &s)
@@ -403,6 +425,17 @@ std::string getLongDescription(const std::string &key)
return std::string((const char *)result.dptr, result.dsize);
}
+std::vector<std::string> getLongDescriptionByRegex(const std::string &regex)
+{
+ if (!descriptionDB)
+ {
+ std::vector<std::string> empty;
+ return (empty);
+ }
+
+ return database_find_keys(descriptionDB, regex, true);
+}
+
static std::vector<std::string> description_txt_paths()
{
std::vector<std::string> txt_file_names;