* Test if a string contains colour codes, and is not wrapped by push/pop codes. * @param buffer String to test. * @return True iff the string is colour safe. */
| 1079 | * @return True iff the string is colour safe. |
| 1080 | */ |
| 1081 | static bool IsColourSafe(std::string_view buffer) |
| 1082 | { |
| 1083 | int safety = 0; |
| 1084 | for (char32_t ch : Utf8View(buffer)) { |
| 1085 | if (ch == SCC_PUSH_COLOUR) { |
| 1086 | ++safety; |
| 1087 | } else if (ch == SCC_POP_COLOUR) { |
| 1088 | --safety; |
| 1089 | if (safety < 0) return false; |
| 1090 | } else if ((ch >= SCC_BLUE && ch <= SCC_BLACK) || ch == SCC_COLOUR) { |
| 1091 | if (safety == 0) return false; |
| 1092 | } |
| 1093 | } |
| 1094 | return true; |
| 1095 | } |
| 1096 | |
| 1097 | /** |
| 1098 | * Parse most format codes within a string and write the result to a buffer. |