forked from iwxyi/EasyMeeting_Desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstringutil.cpp
122 lines (109 loc) · 3 KB
/
stringutil.cpp
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
#include "stringutil.h"
QStringList getStrMids(QString text, QString l, QString r)
{
QStringList ans;
int posl = 0, posr = -r.length();
while (posl != -1 && posr != -1)
{
posl = text.indexOf(l, posr+r.length());
if (posl == -1) return ans;
posl += l.length();
posr = text.indexOf(r, posl);
if (posr == -1) return ans;
ans << text.mid(posl, posr-posl);
}
return ans;
}
QString getStrMid(QString text, QString l, QString r)
{
int posl = text.indexOf(l);
if (posl == -1) return "";
posl += l.length();
int posr = text.indexOf(r, posl);
if (posr == -1) return "";
return text.mid(posl, posr-posl);
}
QString fnEncode(QString text)
{
QString cs[] = {"\\", "/", ":", "*", "?", "\"", "<", ">", "|", "\'", "\n", "\t"};
for (int i = 0; i < 12; i++)
text.replace(cs[i], QString("[&c%1;]").arg(i));
return text;
}
QString fnDecode(QString text)
{
QString cs[] = {"\\", "/", ":", "*", "?", "\"", "<", ">", "|", "\'", "\t", "\n"};
for (int i = 0; i < 12; i++)
text.replace( QString("[&c%1;]").arg(i), cs[i]);
return text;
}
bool canRegExp(QString str, QString pat)
{
return QRegExp(pat).indexIn(str) > -1;
}
QString getXml(QString str, QString pat)
{
int pos1 = str.indexOf(QString("<%1>").arg(pat));
if (pos1 == -1) return "";
pos1 += pat.length()+2;
int pos2 = str.indexOf(QString("</%1>").arg(pat));
if (pos2 == -1) pos2 = str.length();
return str.mid(pos1, pos2-pos1);
}
QStringList getXmls(QString str, QString pat)
{
return getStrMids(str, "<"+pat+">", "</"+pat+">");
}
QString makeXml(QString str, QString pat)
{
return QString("<%1>%2</%3>").arg(pat).arg(str).arg(pat);
}
QString makeXml(int i, QString pat)
{
return QString("<%1>%2</%3>").arg(pat).arg(i).arg(pat);
}
QString ArabToCN(int num)
{
static const QString letter[] = {"零","一","二","三","四","五","六","七","八","九"};
static const QString unit[] = {"","十","百","千","万","十","百","千","亿","十"};
QString src, des;
char tmp[12];
sprintf(tmp, "%d", num);
src.append(tmp);
if ( num < 0 )
{
des.append("负");
src.remove(0, 1);
}
int len = src.length();
bool bPreZero = false;
for ( int i = 0; i < len; i++)
{
int digit = src.at(i).unicode() - '0';
int unit_index = len - i - 1;
if (i == 0 && digit == 1 && (unit_index == 1 || unit_index == 5 || unit_index == 9))
{
des.append(unit[unit_index]);
}
else if ( digit == 0 )
{
bPreZero = true;
if (unit_index == 4 ||
unit_index == 8)
{
des.append(unit[unit_index]);
}
}
else
{
if ( bPreZero )
{
des.append(letter[0]);
}
des.append(letter[digit]);
des.append(unit[unit_index]);
bPreZero = false;
}
}
return des;
}