blob: 626c6b86852b698f831a28d754610b8123b82f47 (
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
#include <QvString.h>
#include <ctype.h>
#define CHUNK_SIZE 4000
struct QvNameChunk {
char mem[CHUNK_SIZE];
char *curByte;
int bytesLeft;
struct QvNameChunk *next;
};
int QvNameEntry::nameTableSize;
QvNameEntry ** QvNameEntry::nameTable;
struct QvNameChunk *QvNameEntry::chunk;
void
QvNameEntry::initClass()
{
int i;
nameTableSize = 1999;
nameTable = new QvNameEntry *[nameTableSize];
for (i = 0; i < nameTableSize; i++)
nameTable[i] = NULL;
chunk = NULL;
}
const QvNameEntry *
QvNameEntry::insert(const char *s)
{
u_long h = QvString::hash(s);
u_long i;
QvNameEntry *entry;
QvNameEntry *head;
if (nameTableSize == 0)
initClass();
i = h % nameTableSize;
entry = head = nameTable[i];
while (entry != NULL) {
if (entry->hashValue == h && entry->isEqual(s))
break;
entry = entry->next;
}
if (entry == NULL) {
int len = strlen(s) + 1;
if (len >= CHUNK_SIZE)
s = strdup(s);
else {
if (chunk == NULL || chunk->bytesLeft < len) {
struct QvNameChunk *newChunk = new QvNameChunk;
newChunk->curByte = newChunk->mem;
newChunk->bytesLeft = CHUNK_SIZE;
newChunk->next = chunk;
chunk = newChunk;
}
strcpy(chunk->curByte, s);
s = chunk->curByte;
chunk->curByte += len;
chunk->bytesLeft -= len;
}
entry = new QvNameEntry(s, h, head);
nameTable[i] = entry;
}
return entry;
}
QvName::QvName()
{
entry = QvNameEntry::insert("");
}
QvBool
QvName::isIdentStartChar(char c)
{
if (isdigit(c)) return FALSE;
return isIdentChar(c);
}
QvBool
QvName::isIdentChar(char c)
{
if (isalnum(c) || c == '_') return TRUE;
return FALSE;
}
QvBool
QvName::isNodeNameStartChar(char c)
{
if (isdigit(c)) return FALSE;
return isIdentChar(c);
}
static const char
badCharacters[] = "+\'\"\\{}";
QvBool
QvName::isNodeNameChar(char c)
{
if (isalnum(c)) return TRUE;
if ((strchr(badCharacters, c) != NULL) ||
isspace(c) || iscntrl(c)) return FALSE;
return TRUE;
}
|