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

Function maybe_pick_random_substring

crawl-ref/source/stringutil.cc:433–448  ·  view source on GitHub ↗

For each set of [phrase|term|word] contained in the string, replace the set with a random subphrase. NOTE: Doesn't work for nested patterns!

Source from the content-addressed store, hash-verified

431// For each set of [phrase|term|word] contained in the string, replace the set with a random subphrase.
432// NOTE: Doesn't work for nested patterns!
433string maybe_pick_random_substring(string s)
434{
435 string::size_type start = 0;
436 while ((start = s.find("[", start)) != string::npos)
437 {
438 string::size_type end = s.find("]", start);
439 if (end == string::npos)
440 break;
441
442 string substring = s.substr(start + 1, end - start - 1);
443 vector<string> split = split_string("|", substring, false, true);
444 int index = random2(split.size());
445 s.replace(start, end + 1 - start, split[index]);
446 }
447 return s;
448}
449
450int count_occurrences(const string &text, const string &s)
451{

Callers 6

_xom_pseudo_miscastFunction · 0.85
_xom_brain_drainFunction · 0.85
_do_msgFunction · 0.85
_walk_on_decorFunction · 0.85
do_mon_str_replacementsFunction · 0.85
item_noiseFunction · 0.85

Calls 6

split_stringFunction · 0.85
random2Function · 0.85
substrMethod · 0.80
replaceMethod · 0.80
findMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected