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

Function _call_recursive_replacement

crawl-ref/source/database.cc:692–736  ·  view source on GitHub ↗

Replace any "@foo@" markers that can be found in this database. Those that can't be found are left alone for the caller to deal with.

Source from the content-addressed store, hash-verified

690// Replace any "@foo@" markers that can be found in this database.
691// Those that can't be found are left alone for the caller to deal with.
692static void _call_recursive_replacement(string &str, TextDB &db,
693 const string &suffix,
694 int &num_replacements,
695 int recursion_depth)
696{
697 string::size_type pos = str.find("@");
698 while (pos != string::npos)
699 {
700 num_replacements++;
701 if (num_replacements > MAX_REPLACEMENTS)
702 {
703 mprf(MSGCH_DIAGNOSTICS, "Too many string replacements, bailing.");
704 return;
705 }
706
707 string::size_type end = str.find("@", pos + 1);
708 if (end == string::npos)
709 {
710 mprf(MSGCH_DIAGNOSTICS, "Unbalanced @, bailing.");
711 break;
712 }
713
714 string marker_full = str.substr(pos, end - pos + 1);
715 string marker = str.substr(pos + 1, end - pos - 1);
716
717 string replacement =
718 _getRandomisedStr(db, marker, suffix, num_replacements,
719 recursion_depth);
720
721 if (replacement.empty())
722 {
723 // Nothing in database, leave it alone and go onto next @foo@
724 pos = str.find("@", end + 1);
725 }
726 else
727 {
728 str.replace(pos, marker_full.length(), replacement);
729
730 // Start search from pos rather than end + 1, so that if
731 // the replacement contains its own @foo@, we can replace
732 // that too.
733 pos = str.find("@", pos);
734 }
735 } // while (pos != string::npos)
736}
737
738static string _query_database(TextDB &db, string key, bool canonicalise_key,
739 bool run_lua, bool untranslated)

Callers 1

_getRandomisedStrFunction · 0.85

Calls 6

mprfFunction · 0.85
_getRandomisedStrFunction · 0.85
substrMethod · 0.80
replaceMethod · 0.80
findMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected