Debian Codegraph @

src/bin/geomutil/vrml2oogl/lib/QvName.c++

raw
1 #include <QvString.h>
2 #include <ctype.h>
3
4 #define CHUNK_SIZE 4000
5
6 struct QvNameChunk {
7 char mem[CHUNK_SIZE];
8 char *curByte;
9 int bytesLeft;
10 struct QvNameChunk *next;
11 };
12
13 int QvNameEntry::nameTableSize;
14 QvNameEntry ** QvNameEntry::nameTable;
15 struct QvNameChunk *QvNameEntry::chunk;
16
17 void
18 QvNameEntry::initClass()
19 {
20 int i;
21
22
23 nameTableSize = 1999;
24 nameTable = new QvNameEntry *[nameTableSize];
25
26 for (i = 0; i < nameTableSize; i++)
27 nameTable[i] = NULL;
28
29 chunk = NULL;
30 }
31
32 const QvNameEntry *
33 QvNameEntry::insert(const char *s)
34 {
35 u_long h = QvString::hash(s);
36 u_long i;
37 QvNameEntry *entry;
38 QvNameEntry *head;
39
40 if (nameTableSize == 0)
41 initClass();
42
43 i = h % nameTableSize;
44 entry = head = nameTable[i];
45
46 while (entry != NULL) {
47 if (entry->hashValue == h && entry->isEqual(s))
48 break;
49 entry = entry->next;
50 }
51
52 if (entry == NULL) {
53
54 int len = strlen(s) + 1;
55
56 if (len >= CHUNK_SIZE)
57 s = strdup(s);
58
59 else {
60
61 if (chunk == NULL || chunk->bytesLeft < len) {
62 struct QvNameChunk *newChunk = new QvNameChunk;
63
64 newChunk->curByte = newChunk->mem;
65 newChunk->bytesLeft = CHUNK_SIZE;
66 newChunk->next = chunk;
67
68 chunk = newChunk;
69 }
70
71 strcpy(chunk->curByte, s);
72 s = chunk->curByte;
73
74 chunk->curByte += len;
75 chunk->bytesLeft -= len;
76 }
77
78 entry = new QvNameEntry(s, h, head);
79 nameTable[i] = entry;
80 }
81
82 return entry;
83 }
84
85 QvName::QvName()
86 {
87 entry = QvNameEntry::insert("");
88 }
89
90 QvBool
91 QvName::isIdentStartChar(char c)
92 {
93 if (isdigit(c)) return FALSE;
94
95 return isIdentChar(c);
96 }
97
98 QvBool
99 QvName::isIdentChar(char c)
100 {
101 if (isalnum(c) || c == '_') return TRUE;
102
103 return FALSE;
104 }
105
106 QvBool
107 QvName::isNodeNameStartChar(char c)
108 {
109 if (isdigit(c)) return FALSE;
110
111 return isIdentChar(c);
112 }
113
114 static const char
115 badCharacters[] = "+\'\"\\{}";
116
117 QvBool
118 QvName::isNodeNameChar(char c)
119 {
120 if (isalnum(c)) return TRUE;
121
122 if ((strchr(badCharacters, c) != NULL) ||
123 isspace(c) || iscntrl(c)) return FALSE;
124
125 return TRUE;
126 }