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!
| 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! |
| 433 | string 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 | |
| 450 | int count_occurrences(const string &text, const string &s) |
| 451 | { |
no test coverage detected