MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / IsColourSafe

Function IsColourSafe

src/strings.cpp:1081–1095  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

1079 * @return True iff the string is colour safe.
1080 */
1081static 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.

Callers 1

FormatStringFunction · 0.85

Calls 1

Utf8ViewClass · 0.85

Tested by

no test coverage detected