summaryrefslogtreecommitdiffstats
path: root/Source/CTest
diff options
context:
space:
mode:
authorFrank Winklmeier <frank.winklmeier@cern.ch>2022-02-17 12:26:55 (GMT)
committerBrad King <brad.king@kitware.com>2022-03-08 13:08:20 (GMT)
commit4634de335bdf2c23659e84195ededc4ef4702ba4 (patch)
tree5fdfc5712dd1ade21819d4396f8606539dfc7e42 /Source/CTest
parent2ac3db2d42482c70631d8be5badc44e61298afd5 (diff)
downloadCMake-4634de335bdf2c23659e84195ededc4ef4702ba4.zip
CMake-4634de335bdf2c23659e84195ededc4ef4702ba4.tar.gz
CMake-4634de335bdf2c23659e84195ededc4ef4702ba4.tar.bz2
cmCTestTestHandler: refactor CleanTestOutput method
Refactor the code to skip over UTF-8 multi-bytes into its own lambda function so it can more easily be re-used.
Diffstat (limited to 'Source/CTest')
-rw-r--r--Source/CTest/cmCTestTestHandler.cxx39
1 files changed, 23 insertions, 16 deletions
diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx
index 5a3a8d0..958c51c 100644
--- a/Source/CTest/cmCTestTestHandler.cxx
+++ b/Source/CTest/cmCTestTestHandler.cxx
@@ -2101,24 +2101,31 @@ void cmCTestTestHandler::CleanTestOutput(std::string& output, size_t length)
return;
}
- // Truncate at given length but do not break in the middle of a multi-byte
- // UTF-8 encoding.
- char const* const begin = output.c_str();
- char const* const end = begin + output.size();
- char const* const truncate = begin + length;
- char const* current = begin;
- while (current < truncate) {
- unsigned int ch;
- if (const char* next = cm_utf8_decode_character(current, end, &ch)) {
- if (next > truncate) {
- break;
+ // Advance n bytes in string delimited by begin/end but do not break in the
+ // middle of a multi-byte UTF-8 encoding.
+ auto utf8_advance = [](char const* const begin, char const* const end,
+ size_t n) -> const char* {
+ char const* const stop = begin + n;
+ char const* current = begin;
+ while (current < stop) {
+ unsigned int ch;
+ if (const char* next = cm_utf8_decode_character(current, end, &ch)) {
+ if (next > stop) {
+ break;
+ }
+ current = next;
+ } else // Bad byte will be handled by cmXMLWriter.
+ {
+ ++current;
}
- current = next;
- } else // Bad byte will be handled by cmXMLWriter.
- {
- ++current;
}
- }
+ return current;
+ };
+
+ // Truncate at given length respecting UTF-8 words
+ char const* const begin = output.c_str();
+ char const* const end = begin + output.size();
+ char const* current = utf8_advance(begin, end, length);
output.erase(current - begin);
// Append truncation message.