blob: a5562a338ea7ef8002d5cb862a36bedc78b356ef (
plain)
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
|
#include <QvString.h>
QvString::~QvString()
{
if (string != staticStorage)
delete [] string;
}
void
QvString::expand(int bySize)
{
int newSize = strlen(string) + bySize + 1;
if (newSize >= QV_STRING_STATIC_STORAGE_SIZE &&
(string == staticStorage || newSize > storageSize)) {
char *newString = new char[newSize];
strcpy(newString, string);
if (string != staticStorage)
delete [] string;
string = newString;
storageSize = newSize;
}
}
u_long
QvString::hash(const char *s)
{
u_long total, shift;
total = shift = 0;
while (*s) {
total = total ^ ((*s) << shift);
shift+=5;
if (shift>24) shift -= 24;
s++;
}
return( total );
}
void
QvString::makeEmpty(QvBool freeOld)
{
if (string != staticStorage) {
if (freeOld)
delete [] string;
string = staticStorage;
}
string[0] = '\0';
}
QvString &
QvString::operator =(const char *str)
{
int size = strlen(str) + 1;
if (str >= string &&
str < string + (string != staticStorage ? storageSize :
QV_STRING_STATIC_STORAGE_SIZE)) {
QvString tmp = str;
*this = tmp;
return *this;
}
if (size < QV_STRING_STATIC_STORAGE_SIZE) {
if (string != staticStorage)
makeEmpty();
}
else if (string == staticStorage)
string = new char[size];
else if (size > storageSize) {
delete [] string;
string = new char[size];
}
strcpy(string, str);
storageSize = size;
return *this;
}
QvString &
QvString::operator +=(const char *str)
{
expand(strlen(str));
strcat(string, str);
return *this;
}
int
operator ==(const QvString &str, const char *s)
{
return (str.string[0] == s[0] && ! strcmp(str.string, s));
}
int
operator !=(const QvString &str, const char *s)
{
return (str.string[0] != s[0] || strcmp(str.string, s));
}
|