MCPcopy Create free account
hub / github.com/IJHack/QtPass / decodeAssumingUtf8

Function decodeAssumingUtf8

src/executor.cpp:188–208  ·  view source on GitHub ↗

* @brief decodes the input into a string assuming UTF-8 encoding. * If this fails (which is likely if it is not actually UTF-8) * it will then fall back to Qt's decoding function, which * will try based on BOM and if that fails fall back to local encoding. * This should not be needed in Qt6 * * @param in input data * @return Input bytes decoded to string */

Source from the content-addressed store, hash-verified

186 * @return Input bytes decoded to string
187 */
188static auto decodeAssumingUtf8(const QByteArray &in) -> QString {
189#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
190 QTextCodec *codec = QTextCodec::codecForName("UTF-8");
191 QTextCodec::ConverterState state;
192 QString out = codec->toUnicode(in.constData(), in.size(), &state);
193 if (state.invalidChars == 0) {
194 return out;
195 }
196 codec = QTextCodec::codecForUtfText(in);
197 return codec->toUnicode(in);
198#else
199 auto converter = QStringDecoder(QStringDecoder::Utf8);
200 QString out = converter(in);
201 if (!converter.hasError()) {
202 return out;
203 }
204 // Fallback if UTF-8 decoding failed - try system encoding
205 auto fallback = QStringDecoder(QStringDecoder::System);
206 return fallback(in);
207#endif
208}
209
210/**
211 * @brief Executor::executeBlocking blocking version of the executor,

Callers 2

executeBlockingMethod · 0.85
finishedMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected