-
Notifications
You must be signed in to change notification settings - Fork 1
/
Util.cpp
67 lines (60 loc) · 1.48 KB
/
Util.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
#include "Util.h"
Util::Util(){}
string Util::toStdString(QString str)
{
return str.toStdString();
}
QString Util::toQString(string str)
{
return QString::fromStdString(str);
}
string Util::convert(const unsigned char* bits,int len) {
string res = "";
for (int i = 0; i < len; i++)
{
int bit = (int)bits[i] % 128;
/*
0 - 9;
10 - 99;
100 - 127;*/
//目标字符串长度判断
res+=Util::stringValue(bit);
}
return res;
}
string Util::stringValue(int number) {
string res="";
string temp = "";
//将数字转换成字符串
do{
temp += number % 10 + '0';
number /= 10;
} while (0 != number);
//cout << "temp:" << temp.c_str();
//字符串反转,取得数字原始顺序
int len=temp.length();
//对齐长度
switch (len) {
case 1:res+="00"; break;
case 2:res+="0"; break;
}
for (int i = len-1; i >= 0; i--) {
res+=temp[i];
}
return res;
}
string Util::calStrUId(const unsigned char *u, const int len)
{
return convert(u,len);
}
void Util::setRecords(QTextBrowser *obj, list<Record> records, string strRecord)
{
list<Record>::iterator ite=records.begin();
Record record;
while(ite!=records.end()){
record=*ite++;
strRecord.append(record.toString());
strRecord.append("\r\n");
}
obj->setText(Util::toQString(strRecord));
}