| 44 | } |
| 45 | |
| 46 | bool processText(StringView text, TextCallback textFunc, CommandsCallback commandsFunc, bool includeCommandSides) { |
| 47 | std::string_view str = text.utf8(); |
| 48 | while (true) { |
| 49 | size_t escape = str.find_first_of(AllEsc); |
| 50 | if (escape != NPos) { |
| 51 | escape = str.find_first_not_of(AllEsc, escape) - 1; // jump to the last ^ |
| 52 | |
| 53 | size_t end = str.find_first_of(EndEsc, escape); |
| 54 | if (end != NPos) { |
| 55 | if (escape && !textFunc(str.substr(0, escape))) |
| 56 | return false; |
| 57 | if (commandsFunc) { |
| 58 | StringView commands = includeCommandSides |
| 59 | ? str.substr(escape, end - escape + 1) |
| 60 | : str.substr(escape + 1, end - escape - 1); |
| 61 | if (!commands.empty() && !commandsFunc(commands)) |
| 62 | return false; |
| 63 | } |
| 64 | str = str.substr(end + 1); |
| 65 | continue; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | if (!str.empty()) |
| 70 | return textFunc(str); |
| 71 | |
| 72 | return true; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | // The below two functions aren't used anymore, not bothering with StringView for them |
| 77 | String preprocessEscapeCodes(String const& s) { |
no test coverage detected