MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / plainTextStr

Method plainTextStr

app/src/Console/Handler.cpp:1108–1149  ·  view source on GitHub ↗

* @brief Converts raw received bytes to a display string. */

Source from the content-addressed store, hash-verified

1106 * @brief Converts raw received bytes to a display string.
1107 */
1108QString Console::Handler::plainTextStr(QByteArrayView data)
1109{
1110 QString utf8Data = SerialStudio::decodeText(data, m_encoding);
1111 if (vt100Emulation())
1112 return utf8Data;
1113
1114 QString filteredData;
1115 filteredData.reserve(utf8Data.size());
1116
1117 int i = 0;
1118 while (i < utf8Data.size()) {
1119 const int runStart = i;
1120 while (i < utf8Data.size()) {
1121 const ushort unicode = utf8Data[i].unicode();
1122
1123 // clang-format off
1124 const bool printable = (unicode != '\0')
1125 && ((unicode >= 0x20 && unicode < 0x7F)
1126 || (unicode >= 0x80)
1127 || (unicode == '\r')
1128 || (unicode == '\n')
1129 || (unicode == '\t')
1130 || (unicode == 0x1B));
1131 // clang-format on
1132
1133 if (!printable)
1134 break;
1135
1136 ++i;
1137 }
1138
1139 if (i > runStart)
1140 filteredData.append(QStringView(utf8Data).mid(runStart, i - runStart));
1141
1142 if (i < utf8Data.size()) {
1143 filteredData.append('.');
1144 ++i;
1145 }
1146 }
1147
1148 return filteredData;
1149}
1150
1151/**
1152 * @brief Converts @a data into a HEX dump string with direct nibble writes into a

Callers

nothing calls this directly

Calls 2

sizeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected