]>
Commit | Line | Data |
---|---|---|
65ec6247 RD |
1 | // Scintilla source code edit control |
2 | /** @file PropSet.h | |
3 | ** A Java style properties file module. | |
4 | **/ | |
5 | // Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org> | |
9ce192d4 RD |
6 | // The License.txt file describes the conditions under which this software may be distributed. |
7 | ||
8 | #ifndef PROPSET_H | |
9 | #define PROPSET_H | |
65ec6247 | 10 | #include "SString.h" |
9ce192d4 RD |
11 | |
12 | bool EqualCaseInsensitive(const char *a, const char *b); | |
13 | ||
65ec6247 | 14 | bool isprefix(const char *target, const char *prefix); |
d134f170 RD |
15 | |
16 | struct Property { | |
17 | unsigned int hash; | |
18 | char *key; | |
19 | char *val; | |
20 | Property *next; | |
21 | Property() : hash(0), key(0), val(0), next(0) {} | |
9ce192d4 RD |
22 | }; |
23 | ||
65ec6247 RD |
24 | /** |
25 | */ | |
9ce192d4 RD |
26 | class PropSet { |
27 | private: | |
d134f170 RD |
28 | enum { hashRoots=31 }; |
29 | Property *props[hashRoots]; | |
65ec6247 RD |
30 | Property *enumnext; |
31 | int enumhash; | |
9ce192d4 RD |
32 | public: |
33 | PropSet *superPS; | |
34 | PropSet(); | |
35 | ~PropSet(); | |
65ec6247 RD |
36 | void Set(const char *key, const char *val, int lenKey=-1, int lenVal=-1); |
37 | void Set(const char *keyVal); | |
38 | void SetMultiple(const char *s); | |
9ce192d4 | 39 | SString Get(const char *key); |
d134f170 | 40 | SString GetExpanded(const char *key); |
65ec6247 | 41 | SString Expand(const char *withVars); |
9ce192d4 RD |
42 | int GetInt(const char *key, int defaultValue=0); |
43 | SString GetWild(const char *keybase, const char *filename); | |
44 | SString GetNewExpand(const char *keybase, const char *filename); | |
45 | void Clear(); | |
65ec6247 RD |
46 | char *ToString(); // Caller must delete[] the return value |
47 | bool GetFirst(char **key, char **val); | |
48 | bool GetNext(char **key, char **val); | |
9ce192d4 RD |
49 | }; |
50 | ||
65ec6247 RD |
51 | /** |
52 | */ | |
9ce192d4 RD |
53 | class WordList { |
54 | public: | |
65ec6247 | 55 | // Each word contains at least one character - a empty word acts as sentinel at the end. |
9ce192d4 | 56 | char **words; |
d134f170 | 57 | char **wordsNoCase; |
9ce192d4 RD |
58 | char *list; |
59 | int len; | |
65ec6247 | 60 | bool onlyLineEnds; ///< Delimited by any white space or only line ends |
d134f170 | 61 | bool sorted; |
9ce192d4 | 62 | int starts[256]; |
65ec6247 | 63 | WordList(bool onlyLineEnds_ = false) : |
d134f170 | 64 | words(0), wordsNoCase(0), list(0), len(0), onlyLineEnds(onlyLineEnds_), sorted(false) {} |
9ce192d4 | 65 | ~WordList() { Clear(); } |
65ec6247 RD |
66 | operator bool() { return len ? true : false; } |
67 | char *operator[](int ind) { return words[ind]; } | |
9ce192d4 RD |
68 | void Clear(); |
69 | void Set(const char *s); | |
70 | char *Allocate(int size); | |
71 | void SetFromAllocated(); | |
72 | bool InList(const char *s); | |
d134f170 | 73 | const char *GetNearestWord(const char *wordStart, int searchLen = -1, bool ignoreCase = false); |
65ec6247 RD |
74 | char *GetNearestWords(const char *wordStart, int searchLen=-1, |
75 | bool ignoreCase=false, char otherSeparator='\0'); | |
9ce192d4 RD |
76 | }; |
77 | ||
d134f170 RD |
78 | inline bool nonFuncChar(char ch) { |
79 | return strchr("\t\n\r !\"#$%&'()*+,-./:;<=>?@[\\]^`{|}~", ch) != NULL; | |
80 | } | |
81 | ||
65ec6247 RD |
82 | inline bool IsAlphabetic(unsigned int ch) { |
83 | return ((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z')); | |
84 | } | |
85 | ||
9ce192d4 | 86 | #endif |