Skip to content

Commit 3c7d398

Browse files
committed
Removing double logic
Remove some double logic: - selection of the LaTeX engine (pdflatex / xelatex) - plural / singular ; first capital letter (based on the `createNoun` function in the Danish translator, extended to use in other translators)
1 parent 0a7e798 commit 3c7d398

36 files changed

+376
-1069
lines changed

doc/translator.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ def collectPureVirtualPrototypes(self):
545545
status = 0
546546
curlyCnt = 0 # counter for the level of curly braces
547547

548+
backStatus = 2
548549
# Loop until the final state 777 is reached. The errors are processed
549550
# immediately. In this implementation, it always quits the application.
550551
while status != 777:
@@ -558,6 +559,7 @@ def collectPureVirtualPrototypes(self):
558559

559560
elif status == 1: # colon after the 'public'
560561
if tokenId == 'colon':
562+
backStatus = 2
561563
status = 2
562564
else:
563565
self.__unexpectedToken(status, tokenId, tokenLineNo)
@@ -566,12 +568,16 @@ def collectPureVirtualPrototypes(self):
566568
if tokenId == 'virtual':
567569
prototype = tokenStr # but not to unified prototype
568570
status = 3
571+
elif tokenId == 'id' and tokenStr == 'QCString' and backStatus == 3:
572+
status = 4
569573
elif tokenId == 'comment':
570574
pass
571575
elif tokenId == 'rcurly':
572576
status = 11 # expected end of class
573577
elif tokenId == 'id' and tokenStr == 'ABSTRACT_BASE_CLASS':
574578
status = 18
579+
elif tokenId == 'protected':
580+
status = 19
575581
else:
576582
self.__unexpectedToken(status, tokenId, tokenLineNo)
577583

@@ -724,6 +730,13 @@ def collectPureVirtualPrototypes(self):
724730
else:
725731
self.__unexpectedToken(status, tokenId, tokenLineNo)
726732

733+
elif status == 19: # colon after the 'protected'
734+
if tokenId == 'colon':
735+
backStatus = 3
736+
status = 3
737+
else:
738+
self.__unexpectedToken(status, tokenId, tokenLineNo)
739+
727740
# Eat the rest of the source to cause closing the file.
728741
while tokenId != 'eof':
729742
tokenId, tokenStr, tokenLineNo = next(tokenIterator)

src/translator.h

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,7 @@ class Translator
7272
*/
7373
virtual QCString latexCommandName()
7474
{
75-
QCString latex_command = Config_getString(LATEX_CMD_NAME);
76-
if (latex_command.isEmpty()) latex_command = "latex";
77-
if (Config_getBool(USE_PDFLATEX))
78-
{
79-
if (latex_command == "latex") latex_command = "pdflatex";
80-
}
81-
return latex_command;
75+
return p_latexCommandName("pdflatex");
8276
}
8377
virtual QCString trISOLang() = 0;
8478

@@ -770,6 +764,30 @@ class Translator
770764
// new since 1.11.0
771765
//////////////////////////////////////////////////////////////////////////
772766
virtual QCString trImportant() = 0;
767+
768+
protected:
769+
QCString p_latexCommandName(const QCString &latexCmd)
770+
{
771+
QCString latex_command = Config_getString(LATEX_CMD_NAME);
772+
if (latex_command.isEmpty()) latex_command = "latex";
773+
if (Config_getBool(USE_PDFLATEX))
774+
{
775+
if (latex_command == "latex") latex_command = latexCmd;
776+
}
777+
return latex_command;
778+
}
779+
/*! For easy flexible-noun implementation.
780+
* \internal
781+
*/
782+
QCString createNoun(bool first_capital, bool singular,
783+
const QCString &base,
784+
const QCString &plurSuffix, const QCString &singSuffix = "" )
785+
{
786+
QCString result(base);
787+
if (first_capital) result = result.left(1).upper() + result.mid(1);
788+
result += (singular ? singSuffix : plurSuffix);
789+
return result;
790+
}
773791
};
774792

775793
#endif

src/translator_ar.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,7 @@ class TranslatorArabic : public TranslatorAdapter_1_4_6
6666

6767
QCString latexCommandName() override
6868
{
69-
QCString latex_command = Config_getString(LATEX_CMD_NAME);
70-
if (latex_command.isEmpty()) latex_command = "latex";
71-
if (Config_getBool(USE_PDFLATEX))
72-
{
73-
if (latex_command == "latex") latex_command = "xelatex";
74-
}
75-
return latex_command;
69+
return p_latexCommandName("xelatex");
7670
}
7771

7872
QCString trISOLang() override

src/translator_br.h

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,9 +1368,7 @@ class TranslatorBrazilian : public Translator
13681368
*/
13691369
QCString trClass(bool first_capital, bool singular) override
13701370
{
1371-
QCString result((first_capital ? "Classe" : "classe"));
1372-
if (!singular) result+="s";
1373-
return result;
1371+
return createNoun(first_capital, singular, "classe", "s");
13741372
}
13751373

13761374
/*! This is used for translation of the word that will possibly
@@ -1379,9 +1377,7 @@ class TranslatorBrazilian : public Translator
13791377
*/
13801378
QCString trFile(bool first_capital, bool singular) override
13811379
{
1382-
QCString result((first_capital ? "Arquivo": "arquivo"));
1383-
if (!singular) result+="s";
1384-
return result;
1380+
return createNoun(first_capital, singular, "arquivo", "s");
13851381
}
13861382

13871383
/*! This is used for translation of the word that will possibly
@@ -1390,9 +1386,7 @@ class TranslatorBrazilian : public Translator
13901386
*/
13911387
QCString trNamespace(bool first_capital, bool singular) override
13921388
{
1393-
QCString result((first_capital ? "Namespace" : "namespace"));
1394-
if (!singular) result+="s";
1395-
return result;
1389+
return createNoun(first_capital, singular, "namespace", "s");
13961390
}
13971391

13981392
/*! This is used for translation of the word that will possibly
@@ -1401,9 +1395,7 @@ class TranslatorBrazilian : public Translator
14011395
*/
14021396
QCString trGroup(bool first_capital, bool singular) override
14031397
{
1404-
QCString result((first_capital ? "Grupo" : "grupo"));
1405-
if (!singular) result+="s";
1406-
return result;
1398+
return createNoun(first_capital, singular, "grupo", "s");
14071399
}
14081400

14091401
/*! This is used for translation of the word that will possibly
@@ -1412,9 +1404,7 @@ class TranslatorBrazilian : public Translator
14121404
*/
14131405
QCString trPage(bool first_capital, bool singular) override
14141406
{
1415-
QCString result((first_capital ? "Página" : "página"));
1416-
if (!singular) result+="s";
1417-
return result;
1407+
return createNoun(first_capital, singular, "página", "s");
14181408
}
14191409

14201410
/*! This is used for translation of the word that will possibly
@@ -1423,9 +1413,7 @@ class TranslatorBrazilian : public Translator
14231413
*/
14241414
QCString trMember(bool first_capital, bool singular) override
14251415
{
1426-
QCString result((first_capital ? "Membro" : "membro"));
1427-
if (!singular) result+="s";
1428-
return result;
1416+
return createNoun(first_capital, singular, "membro", "s");
14291417
}
14301418

14311419
/*! This is used for translation of the word that will possibly
@@ -1434,9 +1422,7 @@ class TranslatorBrazilian : public Translator
14341422
*/
14351423
QCString trGlobal(bool first_capital, bool singular) override
14361424
{
1437-
QCString result((first_capital ? "Globa" : "globa"));
1438-
result+= singular? "l" : "ais";
1439-
return result;
1425+
return createNoun(first_capital, singular, "globa", "ais", "l");
14401426
}
14411427

14421428
//////////////////////////////////////////////////////////////////////////
@@ -1447,9 +1433,7 @@ class TranslatorBrazilian : public Translator
14471433
* for the author section in man pages. */
14481434
QCString trAuthor(bool first_capital, bool singular) override
14491435
{
1450-
QCString result((first_capital ? "Autor" : "autor"));
1451-
if (!singular) result+="es";
1452-
return result;
1436+
return createNoun(first_capital, singular, "autor", "es");
14531437
}
14541438

14551439
//////////////////////////////////////////////////////////////////////////
@@ -1675,9 +1659,7 @@ class TranslatorBrazilian : public Translator
16751659
*/
16761660
QCString trDir(bool first_capital, bool singular) override
16771661
{
1678-
QCString result((first_capital ? "Diretório" : "diretório"));
1679-
if (!singular) result+="s";
1680-
return result;
1662+
return createNoun(first_capital, singular, "diretório", "s");
16811663
}
16821664

16831665
//////////////////////////////////////////////////////////////////////////
@@ -1856,9 +1838,7 @@ class TranslatorBrazilian : public Translator
18561838
*/
18571839
QCString trModule(bool first_capital, bool singular) override
18581840
{
1859-
QCString result((first_capital ? "Módulo" : "módulo"));
1860-
if (!singular) result+="s";
1861-
return result;
1841+
return createNoun(first_capital, singular, "módulo", "s");
18621842
}
18631843

18641844
/*! This is put at the bottom of a module documentation page and is
@@ -1896,9 +1876,7 @@ class TranslatorBrazilian : public Translator
18961876
*/
18971877
QCString trType(bool first_capital, bool singular) override
18981878
{
1899-
QCString result((first_capital ? "Tipo" : "tipo"));
1900-
if (!singular) result+="s";
1901-
return result;
1879+
return createNoun(first_capital, singular, "tipo", "s");
19021880
}
19031881

19041882
/*! This is used for translation of the word that will possibly
@@ -1907,9 +1885,7 @@ class TranslatorBrazilian : public Translator
19071885
*/
19081886
QCString trSubprogram(bool first_capital, bool singular) override
19091887
{
1910-
QCString result((first_capital ? "Subrotina" : "subrotina"));
1911-
if (!singular) result+="s";
1912-
return result;
1888+
return createNoun(first_capital, singular, "subrotina", "s");
19131889
}
19141890

19151891
/*! C# Type Contraint list */
@@ -2477,9 +2453,7 @@ class TranslatorBrazilian : public Translator
24772453
/** C++20 concept */
24782454
QCString trConcept(bool first_capital, bool singular) override
24792455
{
2480-
QCString result((first_capital ? "Conceito" : "conceito"));
2481-
if (!singular) result+="s";
2482-
return result;
2456+
return createNoun(first_capital, singular, "conceito", "s");
24832457
}
24842458
/*! used as the title of the HTML page of a C++20 concept page */
24852459
QCString trConceptReference(const QCString &conceptName) override

src/translator_ca.h

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,9 +1188,7 @@ class TranslatorCatalan : public TranslatorAdapter_1_8_0
11881188
*/
11891189
QCString trClass(bool first_capital, bool singular) override
11901190
{
1191-
QCString result((first_capital ? "Classe" : "classe"));
1192-
if (!singular) result+="s";
1193-
return result;
1191+
return createNoun(first_capital, singular, "classe", "s");
11941192
}
11951193

11961194
/*! This is used for translation of the word that will possibly
@@ -1199,9 +1197,7 @@ class TranslatorCatalan : public TranslatorAdapter_1_8_0
11991197
*/
12001198
QCString trFile(bool first_capital, bool singular) override
12011199
{
1202-
QCString result((first_capital ? "Fitxer" : "fitxer"));
1203-
if (!singular) result+="s";
1204-
return result;
1200+
return createNoun(first_capital, singular, "fitxer", "s");
12051201
}
12061202

12071203
/*! This is used for translation of the word that will possibly
@@ -1210,9 +1206,7 @@ class TranslatorCatalan : public TranslatorAdapter_1_8_0
12101206
*/
12111207
QCString trNamespace(bool first_capital, bool singular) override
12121208
{
1213-
QCString result((first_capital ? "Namespace" : "namespace"));
1214-
if (!singular) result+="s";
1215-
return result;
1209+
return createNoun(first_capital, singular, "namespace", "s");
12161210
}
12171211

12181212
/*! This is used for translation of the word that will possibly
@@ -1221,9 +1215,7 @@ class TranslatorCatalan : public TranslatorAdapter_1_8_0
12211215
*/
12221216
QCString trGroup(bool first_capital, bool singular) override
12231217
{
1224-
QCString result((first_capital ? "Grup" : "grup"));
1225-
if (!singular) result+="s";
1226-
return result;
1218+
return createNoun(first_capital, singular, "grup", "s");
12271219
}
12281220

12291221
/*! This is used for translation of the word that will possibly
@@ -1232,9 +1224,7 @@ class TranslatorCatalan : public TranslatorAdapter_1_8_0
12321224
*/
12331225
QCString trPage(bool first_capital, bool singular) override
12341226
{
1235-
QCString result((first_capital ? "Pàgin" : "pàgin"));
1236-
if (!singular) result+="es"; else result+="a";
1237-
return result;
1227+
return createNoun(first_capital, singular, "pàgin", "es", "a");
12381228
}
12391229

12401230
/*! This is used for translation of the word that will possibly
@@ -1243,9 +1233,7 @@ class TranslatorCatalan : public TranslatorAdapter_1_8_0
12431233
*/
12441234
QCString trMember(bool first_capital, bool singular) override
12451235
{
1246-
QCString result((first_capital ? "Membre" : "membre"));
1247-
if (!singular) result+="s";
1248-
return result;
1236+
return createNoun(first_capital, singular, "membre", "s");
12491237
}
12501238

12511239
/*! This is used for translation of the word that will possibly
@@ -1254,9 +1242,7 @@ class TranslatorCatalan : public TranslatorAdapter_1_8_0
12541242
*/
12551243
QCString trGlobal(bool first_capital, bool singular) override
12561244
{
1257-
QCString result((first_capital ? "Global" : "global"));
1258-
if (!singular) result+="s";
1259-
return result;
1245+
return createNoun(first_capital, singular, "global", "s");
12601246
}
12611247

12621248
//////////////////////////////////////////////////////////////////////////
@@ -1267,9 +1253,7 @@ class TranslatorCatalan : public TranslatorAdapter_1_8_0
12671253
* for the author section in man pages. */
12681254
QCString trAuthor(bool first_capital, bool singular) override
12691255
{
1270-
QCString result((first_capital ? "Autor" : "autor"));
1271-
if (!singular) result+="s";
1272-
return result;
1256+
return createNoun(first_capital, singular, "autor", "s");
12731257
}
12741258

12751259
//////////////////////////////////////////////////////////////////////////
@@ -1491,9 +1475,7 @@ class TranslatorCatalan : public TranslatorAdapter_1_8_0
14911475
*/
14921476
QCString trDir(bool first_capital, bool singular) override
14931477
{
1494-
QCString result((first_capital ? "Directori" : "directori"));
1495-
if (!singular) result+="s";
1496-
return result;
1478+
return createNoun(first_capital, singular, "directori", "s");
14971479
}
14981480

14991481
//////////////////////////////////////////////////////////////////////////
@@ -1675,9 +1657,7 @@ class TranslatorCatalan : public TranslatorAdapter_1_8_0
16751657
*/
16761658
QCString trModule(bool first_capital, bool singular) override
16771659
{
1678-
QCString result((first_capital ? "Mòdul" : "mòdul"));
1679-
if (!singular) result+="s";
1680-
return result;
1660+
return createNoun(first_capital, singular, "mòdul", "s");
16811661
}
16821662
/*! This is put at the bottom of a module documentation page and is
16831663
* followed by a list of files that were used to generate the page.
@@ -1713,20 +1693,15 @@ class TranslatorCatalan : public TranslatorAdapter_1_8_0
17131693
*/
17141694
QCString trType(bool first_capital, bool) override
17151695
{
1716-
QCString result((first_capital ? "Tipus" : "tipus"));
1717-
//if (!singular) result+="s";
1718-
return result;
1696+
return createNoun(first_capital, false, "tipus", "");
17191697
}
17201698
/*! This is used for translation of the word that will possibly
17211699
* be followed by a single name or by a list of names
17221700
* of the category.
17231701
*/
17241702
QCString trSubprogram(bool first_capital, bool singular) override
17251703
{
1726-
QCString result((first_capital ? "Subprogram" : "subprogram"));
1727-
if (!singular) result+="es";
1728-
else result+="a";
1729-
return result;
1704+
return createNoun(first_capital, singular, "subprogram", "es", "a");
17301705
}
17311706

17321707
/*! C# Type Constraint list */

0 commit comments

Comments
 (0)