]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/include/PropSet.h
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.
9 bool EqualCaseInsensitive(const char *a
, const char *b
);
12 #define strcasecmp stricmp
13 #define strncasecmp strnicmp
17 #define strcasecmp stricmp
18 #define strncasecmp strnicmp
21 // Define another string class.
22 // While it would be 'better' to use std::string, that doubles the executable size.
24 inline char *StringDup(const char *s
, int len
=-1) {
29 char *sNew
= new char[len
+ 1];
31 strncpy(sNew
, s
, len
);
41 typedef const char* const_iterator
;
42 typedef int size_type
;
43 static size_type npos
;
44 const char* begin(void) const {
47 const char* end(void) const {
50 size_type
size(void) const {
56 SString
&assign(const char* sother
, int size_
= -1) {
58 s
= StringDup(sother
,size_
);
59 ssize
= (s
) ? strlen(s
) : 0;
63 SString
&assign(const SString
& sother
, int size_
= -1) {
64 return assign(sother
.s
,size_
);
66 SString
&assign(const_iterator ibeg
, const_iterator iend
) {
67 return assign(ibeg
,iend
- ibeg
);
73 SString(const SString
&source
) {
74 s
= StringDup(source
.s
);
75 ssize
= (s
) ? strlen(s
) : 0;
77 SString(const char *s_
) {
79 ssize
= (s
) ? strlen(s
) : 0;
83 sprintf(number
, "%0d", i
);
84 s
= StringDup(number
);
85 ssize
= (s
) ? strlen(s
) : 0;
92 SString
&operator=(const SString
&source
) {
93 if (this != &source
) {
95 s
= StringDup(source
.s
);
96 ssize
= (s
) ? strlen(s
) : 0;
100 bool operator==(const SString
&other
) const {
101 if ((s
== 0) && (other
.s
== 0))
103 if ((s
== 0) || (other
.s
== 0))
105 return strcmp(s
, other
.s
) == 0;
107 bool operator!=(const SString
&other
) const {
108 return !operator==(other
);
110 bool operator==(const char *sother
) const {
111 if ((s
== 0) && (sother
== 0))
113 if ((s
== 0) || (sother
== 0))
115 return strcmp(s
, sother
) == 0;
117 bool operator!=(const char *sother
) const {
118 return !operator==(sother
);
120 const char *c_str() const {
132 char operator[](int i
) const {
138 SString
&operator +=(const char *sother
) {
139 return append(sother
,-1);
141 SString
&operator +=(const SString
&sother
) {
142 return append(sother
.s
,sother
.ssize
);
144 SString
&operator +=(char ch
) {
145 return append(&ch
,1);
147 SString
&append(const char* sother
, int lenOther
) {
150 lenOther
= strlen(sother
);
151 char *sNew
= new char[len
+ lenOther
+ 1];
154 memcpy(sNew
, s
, len
);
155 strncpy(&sNew
[len
], sother
, lenOther
);
156 sNew
[len
+ lenOther
] = '\0';
159 ssize
= (s
) ? strlen(s
) : 0;
169 void substitute(char find
, char replace
) {
177 // I don't think this really belongs here -- Neil
180 substitute('\\', '/');
182 substitute('/', '\\');
192 Property() : hash(0), key(0), val(0), next(0) {}
197 enum { hashRoots
=31 };
198 Property
*props
[hashRoots
];
203 void Set(const char *key
, const char *val
);
204 void Set(char *keyval
);
205 SString
Get(const char *key
);
206 SString
GetExpanded(const char *key
);
207 SString
Expand(const char *withvars
);
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
);
212 void ReadFromMemory(const char *data
, int len
, const char *directoryForImports
=0);
213 void Read(const char *filename
, const char *directoryForImports
);
218 // Each word contains at least one character - a empty word acts as sentinal at the end.
223 bool onlyLineEnds
; // Delimited by any white space or only line ends
226 WordList(bool onlyLineEnds_
= false) :
227 words(0), wordsNoCase(0), list(0), len(0), onlyLineEnds(onlyLineEnds_
), sorted(false) {}
228 ~WordList() { Clear(); }
229 operator bool() { return words
? true : false; }
230 const char *operator[](int ind
) { return words
[ind
]; }
232 void Set(const char *s
);
233 char *Allocate(int size
);
234 void SetFromAllocated();
235 bool InList(const char *s
);
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);
240 inline bool nonFuncChar(char ch
) {
241 return strchr("\t\n\r !\"#$%&'()*+,-./:;<=>?@[\\]^`{|}~", ch
) != NULL
;