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
|
//========================================================================
//
// UGooString.cc
//
// Unicode string
//
// Copyright 2005 Albert Astals Cid <aacid@kde.org>
//
//========================================================================
#include <string.h>
#include "goo/gmem.h"
#include "goo/GooString.h"
#include "PDFDocEncoding.h"
#include "UGooString.h"
UGooString::UGooString(Unicode *u, int l)
{
s = u;
length = l;
}
UGooString::UGooString(GooString &str)
{
if ((str.getChar(0) & 0xff) == 0xfe && (str.getChar(1) & 0xff) == 0xff)
{
length = (str.getLength() - 2) / 2;
s = (Unicode *)gmallocn(length, sizeof(Unicode));
for (int j = 0; j < length; ++j) {
s[j] = ((str.getChar(2 + 2*j) & 0xff) << 8) | (str.getChar(3 + 2*j) & 0xff);
}
} else
initChar(str);
}
UGooString::UGooString(const UGooString &str)
{
length = str.length;
s = (Unicode *)gmallocn(length, sizeof(Unicode));
memcpy(s, str.s, length * sizeof(Unicode));
}
UGooString::UGooString(const char *str)
{
GooString aux(str);
initChar(aux);
}
void UGooString::initChar(GooString &str)
{
length = str.getLength();
s = (Unicode *)gmallocn(length, sizeof(Unicode));
for (int j = 0; j < length; ++j) {
s[j] = pdfDocEncoding[str.getChar(j) & 0xff];
}
}
UGooString::~UGooString()
{
gfree(s);
}
int UGooString::cmp(UGooString *str) const
{
int n1, n2, i, x;
Unicode *p1, *p2;
n1 = length;
n2 = str->length;
for (i = 0, p1 = s, p2 = str->s; i < n1 && i < n2; ++i, ++p1, ++p2) {
x = *p1 - *p2;
if (x != 0) {
return x;
}
}
return n1 - n2;
}
char *UGooString::getCString() const
{
char *res = new char[length + 1];
for (int i = 0; i < length; i++) res[i] = s[i];
res[length] = '\0';
return res;
}
|