feat(eventsub): use custom String type (#5968)

This commit is contained in:
nerix
2025-02-22 11:37:39 +01:00
committed by GitHub
parent 5ae6ffccc5
commit 10ac88e38b
7 changed files with 681 additions and 42 deletions
+8 -7
View File
@@ -1,10 +1,10 @@
#include "twitch-eventsub-ws/string.hpp"
#include "twitch-eventsub-ws/errors.hpp"
#include <boost/json.hpp>
#include <QString>
#include <string>
namespace chatterino::eventsub::lib {
boost::json::result_for<String, boost::json::value>::type tag_invoke(
@@ -14,16 +14,17 @@ boost::json::result_for<String, boost::json::value>::type tag_invoke(
if (jvRoot.is_null())
{
// We treat null "strings" as empty strings
return String("");
return String();
}
auto v = boost::json::try_value_to<std::string>(jvRoot);
if (v.has_error())
if (!jvRoot.is_string())
{
return v.error();
// we don't need a source_location - it doesn't tell us much
return lib::error::makeCode(error::Kind::ExpectedString, nullptr);
}
return String(std::move(v.value()));
const auto &str = jvRoot.get_string();
return String(str);
}
} // namespace chatterino::eventsub::lib