diff options
Diffstat (limited to 'crawl-ref/source/database.cc')
-rw-r--r-- | crawl-ref/source/database.cc | 33 |
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 ®ex, + 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 ®ex) +{ + 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; |