Debian Codegraph @

tests/auto/linguist/lupdate/testdata/good/parsecpp2/main.cpp

raw
1 // Copyright (C) 2016 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 // IMPORTANT!!!! If you want to add testdata to this file,
30 // always add it to the end in order to not change the linenumbers of translations!!!
31
32 // nothing here
33
34 // sickness: multi-\
35 line c++ comment } (with brace)
36
37 #define This is a closing brace } which was ignored
38 } // complain here
39
40 #define This is another \
41 closing brace } which was ignored
42 } // complain here
43
44 #define This is another /* comment in } define */\
45 something /* comment )
46 spanning {multiple} lines */ \
47 closing brace } which was ignored
48 } // complain here
49
50 #define This is another // comment in } define \
51 something } comment
52 } // complain here
53 #include <QtCore>
54
55
56 // Nested class in same file
57 class TopLevel {
58 Q_OBJECT
59
60 class Nested;
61 };
62
63 class TopLevel::Nested {
64 void foo();
65 };
66
67 void TopLevel::Nested::foo()
68 {
69 TopLevel::tr("TopLevel");
70 }
71
72 // Nested class in other file
73 #include "main.h"
74
75 class TopLevel2::Nested {
76 void foo();
77 };
78
79 void TopLevel2::Nested::foo()
80 {
81 TopLevel2::tr("TopLevel2");
82 }
83
84
85
86 namespace NameSpace {
87 class ToBeUsed;
88 }
89
90 // using statement before class definition
91 using NameSpace::ToBeUsed;
92
93 class NameSpace::ToBeUsed {
94 Q_OBJECT
95 void caller();
96 };
97
98 void ToBeUsed::caller()
99 {
100 tr("NameSpace::ToBeUsed");
101 }
102 #include <QtWidgets/QApplication>
103
104 bool me = false;
105 // QTBUG-11818
106 //% "Foo"
107 QString s1 = QObject::tr("Hello World");
108 QString s2 = QObject::tr("Hello World");
109 //% "Bar"
110 QString s3 = QApplication::translate("QObject", "Hello World");
111 QString s4 = QApplication::translate("QObject", "Hello World");
112 //% "Baz"
113 bool clear = me;
114 QString s5 = QObject::tr("Hello World");
115
116
117
118 // QTBUG-11843: complain about missing source in id-based messages
119 QString s6 = qtTrId("no_source");
120
121 QString s7 = QObject::tr(R"(simple one)" R"delim(enter
122 )delim" R"delim(with delimiter )delim inside)delim" u8R"(with quote " inside)");
123
124 QLatin1String not_translated(R"(
125 This is a test string
126 )");
127 const char valid[] = QT_TRANSLATE_NOOP("global", R"(
128 "The time has come," the Walrus said,
129 "To talk of many things:
130 Of shoes - and ships - and sealing-wax -
131 Of cabbages - and kings -
132 And why the sea is boiling hot -
133 And whether pigs have wings."
134 )");
135
136 const QString nodelimiter(QObject::tr(R"(
137 This is a test string
138 )"));
139 const QString withdelimiter = QObject::tr(R"delim(
140 This is a test string
141 )delim");
142
143
144 // New in C++14: integer literals may contain single quotes as separator.
145 struct IntLiteralsWithSeparators {
146 long d = 10'000'000'0'00;
147 int x = 0x1'AF'FE;
148 int X = 0X2'E5E7;
149 };
150
151
152 // QTBUG-59802: prefixed string literals
153 class PrefixedStringLiterals : public QObject {
154 Q_OBJECT
155 void foo()
156 {
157 #if 0
158 tr(u8"UTF-8 string literal");
159 tr(u8R"(UTF-8 raw string literal)");
160 tr(u"UTF-16 string literal");
161 tr(uR"(UTF-16 raw string literal)");
162 tr(U"UTF-32 string literal");
163 tr(UR"(UTF-32 raw string literal)");
164 tr(L"wide string literal");
165 tr(LR"(wide raw string literal)");
166 #endif
167 }
168 };
169
170 // QTBUG-110949: trailing return types with template parameters
171 class TrailingReturnType : public QObject {
172 Q_OBJECT
173 auto f1() -> QString
174 {
175 return tr("f1: trailing return type");
176 }
177 auto f2() -> QString;
178 auto f3() -> std::vector<QString>
179 {
180 return { tr("f3: trailing return type") };
181 }
182 auto f4() -> std::vector<QString>
183 {
184 return { tr("f4: trailing return type") };
185 }
186 auto f5() -> decltype([]() { return 1; })
187 {
188 tr("f5: trailing return type");
189 }
190 auto f6() -> decltype([]() { return 1; });
191 };
192
193 auto TrailingReturnType::f2() -> QString
194 {
195 return tr("f2: trailing return type");
196 }
197
198 auto TrailingReturnType::f4() -> std::vector<QString>
199 {
200 return { tr("f4: trailing return type") };
201 }
202
203 auto TrailingReturnType::f6() -> decltype([]() { return 1; })
204 {
205 tr("f6: trailing return type");
206 return {};
207 }
208
209 // Check that our -> handling doesn't break the common cases.
210 class SomeClassWithArrowInMethods : public QObject {
211 Q_OBJECT
212 void f1()
213 {
214 mainWindow->setWindowTitle(QObject::tr("SomeClassWithArrowInMethods::f1"));
215 }
216 void f2();
217 void f3()
218 {
219 mainWindow->setWindowTitle(tr("SomeClassWithArrowInMethods::f3"));
220 }
221 void f4();
222 };
223
224 SomeClassWithArrowInMethods::f2()
225 {
226 mainWindow->setWindowTitle(QObject::tr("SomeClassWithArrowInMethods::f2"));
227 }
228
229 SomeClassWithArrowInMethods::f4()
230 {
231 mainWindow->setWindowTitle(tr("SomeClassWithArrowInMethods::f4"));
232 }