diff options
Diffstat (limited to 'crawl-ref/source/database.cc')
-rw-r--r-- | crawl-ref/source/database.cc | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/crawl-ref/source/database.cc b/crawl-ref/source/database.cc index 6de91c3a1e..86ae4b098c 100644 --- a/crawl-ref/source/database.cc +++ b/crawl-ref/source/database.cc @@ -165,6 +165,12 @@ std::vector<std::string> database_find_keys(DBM *database, { std::string key((const char *)dbKey.dptr, dbKey.dsize); + if (key.find("__") != std::string::npos) + { + dbKey = dbm_nextkey(database); + continue; + } + if (tpat.matches(key)) matches.push_back(key); @@ -174,6 +180,37 @@ std::vector<std::string> database_find_keys(DBM *database, return (matches); } +std::vector<std::string> database_find_bodies(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 (key.find("__") != std::string::npos) + { + dbKey = dbm_nextkey(database); + continue; + } + + datum dbBody = dbm_fetch(database, dbKey); + std::string body((const char *)dbBody.dptr, dbBody.dsize); + + if (tpat.matches(body)) + matches.push_back(key); + + dbKey = dbm_nextkey(database); + } + + return (matches); +} + /////////////////////////////////////////////////////////////////////////// // Internal DB utility functions static void trim_right(std::string &s) @@ -425,7 +462,7 @@ 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) +std::vector<std::string> getLongDescKeysByRegex(const std::string ®ex) { if (!descriptionDB) { @@ -436,6 +473,17 @@ std::vector<std::string> getLongDescriptionByRegex(const std::string ®ex) return database_find_keys(descriptionDB, regex, true); } +std::vector<std::string> getLongDescBodiesByRegex(const std::string ®ex) +{ + if (!descriptionDB) + { + std::vector<std::string> empty; + return (empty); + } + + return database_find_bodies(descriptionDB, regex, true); +} + static std::vector<std::string> description_txt_paths() { std::vector<std::string> txt_file_names; |