-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathctranslit.cpp
More file actions
156 lines (142 loc) · 4.56 KB
/
ctranslit.cpp
File metadata and controls
156 lines (142 loc) · 4.56 KB
1
2
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*********************** Information *************************\
| $HeadURL$
|
| Author: Jo2003
|
| Begin: 08.02.2010 / 10:50:35
|
| Last edited by: $Author$
|
| $Id$
\*************************************************************/
#include "ctranslit.h"
#include "mdtitle.h"
/********************************************************************\
* This translit stuff only works, if you save this file in *
* UTF-8 format! *
* *
* !!! Using another coding will break the functionality !!! *
* *
* Make sure that your project uses UTF-8 encoding for text! *
* To do this, check out the project settings! *
\********************************************************************/
/* -----------------------------------------------------------------\
| Method: CTranslit / constructor
| Begin: 08.02.2010 / 11:05:00
| Author: Jo2003
| Description: init translation tables
|
| Parameters: pointer to parent object
|
| Returns: --
\----------------------------------------------------------------- */
CTranslit::CTranslit()
{
// fill map (cyrillic -> latin) ...
mCyr2Lat[QString::fromUtf8("а")] = "a";
mCyr2Lat[QString::fromUtf8("б")] = "b";
mCyr2Lat[QString::fromUtf8("в")] = "v";
mCyr2Lat[QString::fromUtf8("г")] = "g";
mCyr2Lat[QString::fromUtf8("д")] = "d";
mCyr2Lat[QString::fromUtf8("е")] = "e";
mCyr2Lat[QString::fromUtf8("ё")] = "e";
mCyr2Lat[QString::fromUtf8("ж")] = "zh";
mCyr2Lat[QString::fromUtf8("з")] = "z";
mCyr2Lat[QString::fromUtf8("и")] = "i";
mCyr2Lat[QString::fromUtf8("й")] = "j";
mCyr2Lat[QString::fromUtf8("к")] = "k";
mCyr2Lat[QString::fromUtf8("л")] = "l";
mCyr2Lat[QString::fromUtf8("м")] = "m";
mCyr2Lat[QString::fromUtf8("н")] = "n";
mCyr2Lat[QString::fromUtf8("о")] = "o";
mCyr2Lat[QString::fromUtf8("п")] = "p";
mCyr2Lat[QString::fromUtf8("р")] = "r";
mCyr2Lat[QString::fromUtf8("с")] = "s";
mCyr2Lat[QString::fromUtf8("т")] = "t";
mCyr2Lat[QString::fromUtf8("у")] = "u";
mCyr2Lat[QString::fromUtf8("ф")] = "f";
mCyr2Lat[QString::fromUtf8("х")] = "h";
mCyr2Lat[QString::fromUtf8("ц")] = "c";
mCyr2Lat[QString::fromUtf8("ш")] = "sh";
mCyr2Lat[QString::fromUtf8("щ")] = "sch";
mCyr2Lat[QString::fromUtf8("ч")] = "ch";
mCyr2Lat[QString::fromUtf8("ы")] = "y";
mCyr2Lat[QString::fromUtf8("ъ")] = "´";
mCyr2Lat[QString::fromUtf8("ь")] = "'";
mCyr2Lat[QString::fromUtf8("э")] = "e'";
mCyr2Lat[QString::fromUtf8("ю")] = "yu";
mCyr2Lat[QString::fromUtf8("я")] = "ya";
// upper case
QMap<QString, QString> tmpMap;
for (auto key : mCyr2Lat.keys())
{
QString val = mCyr2Lat.value(key);
val[0] = val[0].toUpper();
key[0] = key[0].toUpper();
tmpMap.insert(key, val);
}
for (const auto& k : tmpMap.keys())
{
mCyr2Lat.insert(k, tmpMap.value(k));
}
}
/* -----------------------------------------------------------------\
| Method: CyrToLat
| Begin: 08.02.2010 / 11:05:00
| Author: Jo2003
| Description: make translit cyrillic --> latin
|
| Parameters: ref. to cyrillic string
|
| Returns: latin string
\----------------------------------------------------------------- */
QString CTranslit::CyrToLat(const QString &str, bool fileName)
{
QString sOut = str;
auto uniCodeToks = unicodeSplit(str);
for (const auto& c : uniCodeToks)
{
if (mCyr2Lat.keys().contains(c))
{
sOut.replace(c, mCyr2Lat.value(c));
}
}
if (fileName)
{
sOut.replace(" ", "_");
sOut.replace("'", "");
sOut.replace("´", "");
sOut = sOut.toUpper();
}
return sOut;
}
/* -----------------------------------------------------------------\
| Method: LatToCyr
| Begin: 08.02.2010 / 11:05:00
| Author: Jo2003
| Description: make translit latin --> cyrillic
|
| Parameters: ref. to latin string
|
| Returns: cyrillic string
\----------------------------------------------------------------- */
QString CTranslit::LatToCyr(const QString &str, bool fileName)
{
QString sOut = str;
auto toks = mCyr2Lat.values();
for (const auto& tok : toks)
{
if (sOut.contains(tok))
{
sOut.replace(tok, mCyr2Lat.key(tok));
}
}
if (fileName)
{
sOut.replace(" ", "_");
sOut.replace("'", "");
sOut.replace("´", "");
sOut = sOut.toUpper();
}
return sOut;
}