23 const QChar *ptr = string.unicode();
24 if (*ptr == extraCommentAnotation && ptr[1].isSpace()) {
26 m_extracomment += string;
27 if (!m_extracomment.endsWith(u'\n'))
28 m_extracomment.push_back(u'\n');
29 m_extracomment.detach();
30 }
else if (*ptr == idAnotation && ptr[1].isSpace()) {
32 m_msgid = string.simplified();
35 "Setting translation IDs using //= or #= is deprecated and will be removed in the upcoming versions.\n"_L1;
36 }
else if (*ptr == extraAnotation && ptr[1].isSpace()) {
38 const QString trimmed = string.trimmed();
39 int k = trimmed.indexOf(u' ');
41 QString commentvalue = trimmed.mid(k + 1).trimmed();
42 if (commentvalue.startsWith(u'"') && commentvalue.endsWith(u'"')
43 && commentvalue.size() != 1) {
44 commentvalue = commentvalue.sliced(1, commentvalue.size() - 2);
46 m_extra.insert(trimmed.left(k), commentvalue);
48 }
else if (*ptr == sourceTextAnotation && ptr[1].isSpace()) {
49 m_sourcetext.reserve(m_sourcetext.size() + string.size() - 2);
50 ushort *ptr = (ushort *)m_sourcetext.data() + m_sourcetext.size();
53 if (p >= string.size())
55 c = string.unicode()[p++].unicode();
59 m_error =
"Unexpected character in meta string\n"_L1;
63 if (p >= string.size()) {
65 m_error =
"Unterminated meta string\n"_L1;
68 c = string.unicode()[p++].unicode();
72 if (p >= string.size())
74 c = string.unicode()[p++].unicode();
82 m_sourcetext.resize(ptr - (ushort *)m_sourcetext.data());
83 }
else if (*ptr == labelAnotation && ptr[1].isSpace()) {
85 m_label = string.trimmed().simplified();
87 }
else if (
const QString trimmed = string.trimmed(); trimmed.startsWith(CppMagicComment)) {
88 qsizetype idx = CppMagicComment.size();
90 QString::fromRawData(trimmed.unicode() + idx, trimmed.size() - idx).simplified();
91 if (
int k = comment.indexOf(u' '); k != -1) {
92 QString context = comment.left(k);
93 comment.remove(0, k + 1);
94 m_magicComment.emplace(MagicComment{ std::move(context), std::move(comment) });
98 return m_error.isEmpty();
102 const QString &className)
104 if (m_label.contains(PlaceholderClass)) {
105 QString classStr = className;
106 if (classStr.isEmpty()) {
107 classStr = UnnamedPlaceholder;
109 "Label placeholder <class> used, but no class available. Using <unnamed>.\n"_L1;
111 m_label.replace(PlaceholderClass, classStr);
114 if (m_label.contains(PlaceholderContext)) {
115 QString contextStr = context;
116 if (contextStr.isEmpty()) {
117 contextStr = UnnamedPlaceholder;
119 "Label placeholder <context> used, but no context available. Using <unnamed>.\n"_L1;
121 m_label.replace(PlaceholderContext, contextStr);
124 if (m_label.contains(PlaceholderFile))
125 m_label.replace(PlaceholderFile, QFileInfo(filename).fileName());
127 return m_error.isEmpty();