-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqunicode.cpp
81 lines (66 loc) · 1.49 KB
/
qunicode.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
#include "qunicode.h"
#include "unicode.h"
#include <stdio.h>
#include <stdlib.h>
int
toMB(QCString &buf, QString st, const char *enc_name)
{
char buff[5];
int idx, result, enc;
enc = Unicode::getEncoding(enc_name, NEED_WC_TO_MB);
if (enc<0 ) return -1;
//printf("SRC:%s\n", (const char*)st);
buf = "";
for (idx=0 ; idx<st.length() ; idx++) {
result = Unicode::wctomb(buff, st.at(idx).unicode(), 4, enc);
if (result<0) {
continue;
} else {
buff[result] = 0;
buf.append(buff);
}
}
return buf.length();
}
QString
toWC(const char *st, int st_len, const char *enc_name)
{
QString st_buf;
toWC(st_buf, st, st_len, enc_name);
return st_buf;
}
QString
toWC(const char *st, const char *enc_name)
{
QString st_buf;
toWC(st_buf, st, -1, enc_name);
return st_buf;
}
int
toWC(QString &buf, const char *st, const char *enc_name)
{
return toWC(buf, st, -1, enc_name);
}
int
toWC(QString &buf, const char *st, int st_len, const char *enc_name)
{
int enc;
enc = Unicode::getEncoding(enc_name, NEED_MB_TO_WC);
//printf("ENCODING:%s,%d\n", enc_name, enc);
if (enc<0 ) return -1;
buf = "";
const char *st_src = st;
int idx=0, result;
wchar_t wch;
if (st_len<0) st_len = strlen(st);
while (idx<st_len) {
result = Unicode::mbtowc(&wch, st_src+idx, st_len-idx, enc);
if (result<0) {
idx++;
} else {
idx += result;
buf.append(QChar((ushort)wch));
}
}
return buf.length();
}