]> git.saurik.com Git - wxWidgets.git/blame - src/stc/scintilla/include/PropSet.h
A fix for attribrute sorting, but it's still broken if there are
[wxWidgets.git] / src / stc / scintilla / include / PropSet.h
CommitLineData
9ce192d4
RD
1// SciTE - Scintilla based Text Editor
2// PropSet.h - a java style properties file module
3// Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org>
4// The License.txt file describes the conditions under which this software may be distributed.
5
6#ifndef PROPSET_H
7#define PROPSET_H
8
9bool EqualCaseInsensitive(const char *a, const char *b);
10
d134f170
RD
11#if PLAT_WIN
12#define strcasecmp stricmp
13#define strncasecmp strnicmp
14#endif
15
16#ifdef __WXMSW__
17#define strcasecmp stricmp
18#define strncasecmp strnicmp
19#endif
20
9ce192d4
RD
21// Define another string class.
22// While it would be 'better' to use std::string, that doubles the executable size.
23
d134f170 24inline char *StringDup(const char *s, int len=-1) {
9ce192d4
RD
25 if (!s)
26 return 0;
d134f170
RD
27 if (len == -1)
28 len = strlen(s);
29 char *sNew = new char[len + 1];
30 if (sNew) {
31 strncpy(sNew, s, len);
32 sNew[len] = '\0';
33 }
9ce192d4
RD
34 return sNew;
35}
36
37class SString {
38 char *s;
d134f170 39 int ssize;
9ce192d4 40public:
d134f170
RD
41 typedef const char* const_iterator;
42 typedef int size_type;
43 static size_type npos;
44 const char* begin(void) const {
45 return s;
46 }
47 const char* end(void) const {
48 return &s[ssize];
49 }
50 size_type size(void) const {
51 if (s)
52 return ssize;
53 else
54 return 0;
55 }
56 SString &assign(const char* sother, int size_ = -1) {
57 char *t = s;
58 s = StringDup(sother,size_);
59 ssize = (s) ? strlen(s) : 0;
60 delete []t;
61 return *this;
62 }
63 SString &assign(const SString& sother, int size_ = -1) {
64 return assign(sother.s,size_);
65 }
66 SString &assign(const_iterator ibeg, const_iterator iend) {
67 return assign(ibeg,iend - ibeg);
68 }
9ce192d4
RD
69 SString() {
70 s = 0;
d134f170 71 ssize = 0;
9ce192d4
RD
72 }
73 SString(const SString &source) {
74 s = StringDup(source.s);
d134f170 75 ssize = (s) ? strlen(s) : 0;
9ce192d4
RD
76 }
77 SString(const char *s_) {
78 s = StringDup(s_);
d134f170 79 ssize = (s) ? strlen(s) : 0;
9ce192d4
RD
80 }
81 SString(int i) {
82 char number[100];
83 sprintf(number, "%0d", i);
9ce192d4 84 s = StringDup(number);
d134f170 85 ssize = (s) ? strlen(s) : 0;
9ce192d4
RD
86 }
87 ~SString() {
88 delete []s;
89 s = 0;
d134f170 90 ssize = 0;
9ce192d4
RD
91 }
92 SString &operator=(const SString &source) {
93 if (this != &source) {
94 delete []s;
95 s = StringDup(source.s);
d134f170 96 ssize = (s) ? strlen(s) : 0;
9ce192d4
RD
97 }
98 return *this;
99 }
100 bool operator==(const SString &other) const {
101 if ((s == 0) && (other.s == 0))
102 return true;
103 if ((s == 0) || (other.s == 0))
104 return false;
105 return strcmp(s, other.s) == 0;
106 }
d134f170
RD
107 bool operator!=(const SString &other) const {
108 return !operator==(other);
109 }
9ce192d4
RD
110 bool operator==(const char *sother) const {
111 if ((s == 0) && (sother == 0))
112 return true;
113 if ((s == 0) || (sother == 0))
114 return false;
115 return strcmp(s, sother) == 0;
116 }
d134f170
RD
117 bool operator!=(const char *sother) const {
118 return !operator==(sother);
119 }
9ce192d4
RD
120 const char *c_str() const {
121 if (s)
122 return s;
123 else
124 return "";
125 }
126 int length() const {
127 if (s)
128 return strlen(s);
129 else
130 return 0;
131 }
f6bcfd97 132 char operator[](int i) const {
9ce192d4
RD
133 if (s)
134 return s[i];
135 else
136 return '\0';
137 }
138 SString &operator +=(const char *sother) {
d134f170
RD
139 return append(sother,-1);
140 }
141 SString &operator +=(const SString &sother) {
142 return append(sother.s,sother.ssize);
143 }
144 SString &operator +=(char ch) {
145 return append(&ch,1);
146 }
147 SString &append(const char* sother, int lenOther) {
9ce192d4 148 int len = length();
d134f170
RD
149 if(lenOther < 0)
150 lenOther = strlen(sother);
9ce192d4
RD
151 char *sNew = new char[len + lenOther + 1];
152 if (sNew) {
153 if (s)
154 memcpy(sNew, s, len);
d134f170 155 strncpy(&sNew[len], sother, lenOther);
9ce192d4
RD
156 sNew[len + lenOther] = '\0';
157 delete []s;
158 s = sNew;
d134f170 159 ssize = (s) ? strlen(s) : 0;
9ce192d4
RD
160 }
161 return *this;
162 }
f6bcfd97 163 int value() const {
9ce192d4
RD
164 if (s)
165 return atoi(s);
d134f170 166 else
9ce192d4
RD
167 return 0;
168 }
d134f170
RD
169 void substitute(char find, char replace) {
170 char *t = s;
171 while (t) {
172 t = strchr(t, find);
173 if (t)
174 *t = replace;
175 }
176 }
177 // I don't think this really belongs here -- Neil
178 void correctPath() {
179#ifdef unix
180 substitute('\\', '/');
181#else
182 substitute('/', '\\');
183#endif
184 }
185};
186
187struct Property {
188 unsigned int hash;
189 char *key;
190 char *val;
191 Property *next;
192 Property() : hash(0), key(0), val(0), next(0) {}
9ce192d4
RD
193};
194
195class PropSet {
196private:
d134f170
RD
197 enum { hashRoots=31 };
198 Property *props[hashRoots];
9ce192d4
RD
199public:
200 PropSet *superPS;
201 PropSet();
202 ~PropSet();
9ce192d4
RD
203 void Set(const char *key, const char *val);
204 void Set(char *keyval);
205 SString Get(const char *key);
d134f170
RD
206 SString GetExpanded(const char *key);
207 SString Expand(const char *withvars);
9ce192d4
RD
208 int GetInt(const char *key, int defaultValue=0);
209 SString GetWild(const char *keybase, const char *filename);
210 SString GetNewExpand(const char *keybase, const char *filename);
211 void Clear();
d134f170
RD
212 void ReadFromMemory(const char *data, int len, const char *directoryForImports=0);
213 void Read(const char *filename, const char *directoryForImports);
9ce192d4
RD
214};
215
216class WordList {
217public:
218 // Each word contains at least one character - a empty word acts as sentinal at the end.
219 char **words;
d134f170 220 char **wordsNoCase;
9ce192d4
RD
221 char *list;
222 int len;
223 bool onlyLineEnds; // Delimited by any white space or only line ends
d134f170 224 bool sorted;
9ce192d4 225 int starts[256];
d134f170
RD
226 WordList(bool onlyLineEnds_ = false) :
227 words(0), wordsNoCase(0), list(0), len(0), onlyLineEnds(onlyLineEnds_), sorted(false) {}
9ce192d4 228 ~WordList() { Clear(); }
d134f170 229 operator bool() { return words ? true : false; }
9ce192d4
RD
230 const char *operator[](int ind) { return words[ind]; }
231 void Clear();
232 void Set(const char *s);
233 char *Allocate(int size);
234 void SetFromAllocated();
235 bool InList(const char *s);
d134f170
RD
236 const char *GetNearestWord(const char *wordStart, int searchLen = -1, bool ignoreCase = false);
237 char *GetNearestWords(const char *wordStart, int searchLen = -1, bool ignoreCase = false);
9ce192d4
RD
238};
239
d134f170
RD
240inline bool nonFuncChar(char ch) {
241 return strchr("\t\n\r !\"#$%&'()*+,-./:;<=>?@[\\]^`{|}~", ch) != NULL;
242}
243
9ce192d4 244#endif