14bool MetaStrings::parse(QString &string)
16 const QChar *ptr = string.unicode();
17 if (*ptr == u':' && ptr[1].isSpace()) {
19 m_extracomment += string;
20 if (!m_extracomment.endsWith(u'\n'))
21 m_extracomment.push_back(u'\n');
22 m_extracomment.detach();
23 }
else if (*ptr == u'=' && ptr[1].isSpace()) {
25 m_msgid = string.simplified();
28 "Setting translation IDs using //= or #= is deprecated and will be removed in the upcoming versions.\n"_L1;
29 }
else if (*ptr == u'~' && ptr[1].isSpace()) {
31 const QString trimmed = string.trimmed();
32 int k = trimmed.indexOf(u' ');
34 QString commentvalue = trimmed.mid(k + 1).trimmed();
35 if (commentvalue.startsWith(u'"') && commentvalue.endsWith(u'"')
36 && commentvalue.size() != 1) {
37 commentvalue = commentvalue.sliced(1, commentvalue.size() - 2);
39 m_extra.insert(trimmed.left(k), commentvalue);
41 }
else if (*ptr == u'%' && ptr[1].isSpace()) {
42 m_sourcetext.reserve(m_sourcetext.size() + string.size() - 2);
43 ushort *ptr = (ushort *)m_sourcetext.data() + m_sourcetext.size();
46 if (p >= string.size())
48 c = string.unicode()[p++].unicode();
52 m_error =
"Unexpected character in meta string\n"_L1;
56 if (p >= string.size()) {
58 m_error =
"Unterminated meta string\n"_L1;
61 c = string.unicode()[p++].unicode();
65 if (p >= string.size())
67 c = string.unicode()[p++].unicode();
75 m_sourcetext.resize(ptr - (ushort *)m_sourcetext.data());
76 }
else if (*ptr == u'@' && ptr[1].isSpace()) {
78 m_label = string.trimmed().simplified();
80 }
else if (
const QString trimmed = string.trimmed(); trimmed.startsWith(CppMagicComment)) {
81 qsizetype idx = CppMagicComment.size();
83 QString::fromRawData(trimmed.unicode() + idx, trimmed.size() - idx).simplified();
84 if (
int k = comment.indexOf(u' '); k != -1) {
85 QString context = comment.left(k);
86 comment.remove(0, k + 1);
87 m_magicComment.emplace(MagicComment{ std::move(context), std::move(comment) });
91 return m_error.isEmpty();