* @brief Encodes a QString to raw bytes using the given text encoding. */
| 1044 | * @brief Encodes a QString to raw bytes using the given text encoding. |
| 1045 | */ |
| 1046 | QByteArray SerialStudio::encodeText(const QString& text, SerialStudio::TextEncoding enc) |
| 1047 | { |
| 1048 | if (text.isEmpty()) |
| 1049 | return {}; |
| 1050 | |
| 1051 | if (const auto native = nativeEncoding(enc); native.has_value()) { |
| 1052 | QStringEncoder encoder(*native); |
| 1053 | return QByteArray(encoder.encode(text)); |
| 1054 | } |
| 1055 | |
| 1056 | auto* codec = legacyCodec(enc); |
| 1057 | Q_ASSERT(codec != nullptr); |
| 1058 | return codec->fromUnicode(text); |
| 1059 | } |
| 1060 | |
| 1061 | /** |
| 1062 | * @brief Decodes raw bytes to a QString using the given text encoding. |
nothing calls this directly
no test coverage detected