MCPcopy Create free account
hub / github.com/crawl/crawl / _getWeightedString

Function _getWeightedString

crawl-ref/source/database.cc:626–662  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

624#define MAX_REPLACEMENTS 100
625
626static string _getWeightedString(TextDB &db, const string &key,
627 const string &suffix, int fixed_weight = -1)
628{
629 // We have to canonicalise the key (in case the user typed it
630 // in and got the case wrong.)
631 string canonical_key = key + suffix;
632 lowercase(canonical_key);
633
634 // Query the DB.
635 datum result;
636
637 if (db.translation)
638 result = _database_fetch(db.translation->get(), canonical_key);
639 if (result.dsize <= 0)
640 result = _database_fetch(db.get(), canonical_key);
641
642 if (result.dsize <= 0)
643 {
644 // Try ignoring the suffix.
645 canonical_key = key;
646 lowercase(canonical_key);
647
648 // Query the DB.
649 if (db.translation)
650 result = _database_fetch(db.translation->get(), canonical_key);
651 if (result.dsize <= 0)
652 result = _database_fetch(db.get(), canonical_key);
653
654 if (result.dsize <= 0)
655 return "";
656 }
657
658 // Cons up a (C++) string to return. The caller must release it.
659 string str = string((const char *)result.dptr, result.dsize);
660
661 return _chooseStrByWeight(str, fixed_weight);
662}
663
664static void _call_recursive_replacement(string &str, TextDB &db,
665 const string &suffix,

Callers 1

_getRandomisedStrFunction · 0.85

Calls 3

_database_fetchFunction · 0.85
_chooseStrByWeightFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected