Skip to content

Commit

Permalink
Convert std::vector<uchar> -> std::string using ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-fedin authored and john-preston committed Mar 9, 2024
1 parent 96543c1 commit 9b52030
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions spellcheck/third_party/hunspell_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,13 @@ class CharsetConverter final {
[[nodiscard]] std::string fromUnicode(const QString &data) {
#if __has_include(<glib/glib.hpp>)
const auto utf8 = data.toStdString();
const auto result = GLib::convert(
return GLib::convert(
reinterpret_cast<const uchar*>(utf8.data()),
utf8.size(),
_charset,
"UTF-8",
nullptr,
nullptr);
return { result.begin(), result.end() };
nullptr) | ranges::to<std::string>;
#elif QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // __has_include(<glib/glib.hpp>)
return _codec->fromUnicode(data).toStdString();
#else // Qt < 6.0.0
Expand All @@ -136,14 +135,13 @@ class CharsetConverter final {

[[nodiscard]] QString toUnicode(const std::string &data) {
#if __has_include(<glib/glib.hpp>)
const auto result = GLib::convert(
return QString::fromStdString(GLib::convert(
reinterpret_cast<const uchar*>(data.data()),
data.size(),
"UTF-8",
_charset,
nullptr,
nullptr);
return QString::fromStdString({ result.begin(), result.end() });
nullptr) | ranges::to<std::string>);
#elif QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // __has_include(<glib/glib.hpp>)
return _codec->toUnicode(data.data(), data.size());
#else // Qt < 6.0.0
Expand Down

0 comments on commit 9b52030

Please sign in to comment.