8 #include <QStringBuilder>
9 #include <QThreadStorage>
15 static QThreadStorage<std::vector<const CJsonScope *>> g_stack;
18 auto &jsonStack() noexcept {
return g_stack.localData(); }
21 void CJsonException::anchor() {}
25 if (prefix.isEmpty()) {
return QStringLiteral(
"%1 in '%2'").arg(what()).arg(
getStackTrace()); }
26 return QStringLiteral(
"%1: %2 in '%3'").arg(prefix).arg(what()).arg(
getStackTrace());
29 QString CJsonException::stackString()
32 for (
const auto scope : std::as_const(jsonStack()))
34 list.push_back(scope->m_string ? *scope->m_string : scope->m_latin1);
35 if (scope->m_index >= 0) { list.back() += u
'[' % QString::number(scope->m_index) % u
']'; }
37 return list.isEmpty() ? QStringLiteral(
"<document root>") : list.join(
'.');
40 void CJsonScope::push() const noexcept { jsonStack().push_back(
this); }
42 void CJsonScope::pop() const noexcept
44 Q_ASSERT(jsonStack().back() ==
this);
45 jsonStack().pop_back();
QString toString(const QString &prefix) const
As string info.
const QString & getStackTrace() const
Get a stack trace of where in the JSON object tree the error occurred.
Free functions in swift::misc.