-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvertpinyin.cpp
More file actions
96 lines (90 loc) · 3.77 KB
/
convertpinyin.cpp
File metadata and controls
96 lines (90 loc) · 3.77 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
#include "convertpinyin.h"
#include <QMap>
#include <qstringlist.h>
ConvertPinyin::ConvertPinyin()
{
}
/*static*/ QString ConvertPinyin::ConvertNumericalPinYinToAccented(QString input)
{
// TODO port regex
// QMap<int, QString> pinyinToneMark;
// pinyinToneMark.insert(0, "aoeiuv\u00fc");
// pinyinToneMark.insert(1, "\u0101\u014d\u0113\u012b\u016b\u01d6\u01d6");
// pinyinToneMark.insert(2, "\u00e1\u00f3\u00e9\u00ed\u00fa\u01d8\u01d8");
// pinyinToneMark.insert(3, "\u01ce\u01d2\u011b\u01d0\u01d4\u01da\u01da");
// pinyinToneMark.insert(4, "\u00e0\u00f2\u00e8\u00ec\u00f9\u01dc\u01dc");
// QStringList words = input.split(' ');
QString accented = "";
// QString t = "";
// foreach (QString pinyin, words)
// {
// for(QString::ConstIterator it = pinyin.begin(); it< pinyin.end(); ++it)
// {
// QChar c = *it;
// if (c >= 'a' && c <= 'z')
// {
// t += c;
// }
// else if (c == ':')
// {
// if (t[t.length() - 1] == 'u')
// {
// t = t.left(t.length() - 2) + "\u00fc";
// }
// }
// else
// {
// if (c >= '0' && c <= '5')
// {
// int tone = c.toAscii() % 5;
// if (tone != 0)
// {
// Match match = Regex.Match(t, "[aoeiuv\u00fc]+");
// if (!match.Success)
// {
// t += c;
// }
// else if (match.Groups[0].length() == 1)
// {
// t = t.left(match.Groups[0].Index) +
// pinyinToneMark[tone][pinyinToneMark[0].indexOf(match.Groups[0].Value[0])] // TODO use QRegexp::capturedTexts
// + t.left(match.Groups[0].Index + match.Groups[0].length());
// }
// else
// {
// if (t.contains("a"))
// {
// t = t.replace("a", QChar(pinyinToneMark[tone][0]));
// }
// else if (t.contains("o"))
// {
// t = t.replace("o", QChar(pinyinToneMark[tone][1]));
// }
// else if (t.contains("e"))
// {
// t = t.replace("e", QChar(pinyinToneMark[tone][2]));
// }
// else if (t.contains("ui"))
// {
// t = t.replace("i", QChar(pinyinToneMark[tone][3]));
// }
// else if (t.contains("iu"))
// {
// t = t.replace("u", QChar(pinyinToneMark[tone][4]));
// }
// else
// {
// t += "!";
// }
// }
// }
// }
// accented += t;
// t = "";
// }
// }
// accented += t + " ";
// }
// accented = accented.trimmed();
return accented;
}