]>
Commit | Line | Data |
---|---|---|
65ec6247 RD |
1 | // Scintilla source code edit control |
2 | /** @file PropSet.h | |
3 | ** A Java style properties file module. | |
4 | **/ | |
1a2fb4cd | 5 | // Copyright 1998-2002 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 | 26 | class PropSet { |
88a8b04e | 27 | protected: |
d134f170 RD |
28 | enum { hashRoots=31 }; |
29 | Property *props[hashRoots]; | |
65ec6247 RD |
30 | Property *enumnext; |
31 | int enumhash; | |
88a8b04e RD |
32 | static unsigned int HashString(const char *s, size_t len) { |
33 | unsigned int ret = 0; | |
34 | while (len--) { | |
35 | ret <<= 4; | |
36 | ret ^= *s; | |
37 | s++; | |
38 | } | |
39 | return ret; | |
40 | } | |
41 | static bool IncludesVar(const char *value, const char *key); | |
9ce192d4 RD |
42 | public: |
43 | PropSet *superPS; | |
44 | PropSet(); | |
45 | ~PropSet(); | |
65ec6247 RD |
46 | void Set(const char *key, const char *val, int lenKey=-1, int lenVal=-1); |
47 | void Set(const char *keyVal); | |
48 | void SetMultiple(const char *s); | |
9ce192d4 | 49 | SString Get(const char *key); |
d134f170 | 50 | SString GetExpanded(const char *key); |
e14d10b0 | 51 | SString Expand(const char *withVars, int maxExpands=100); |
9ce192d4 RD |
52 | int GetInt(const char *key, int defaultValue=0); |
53 | SString GetWild(const char *keybase, const char *filename); | |
1a2fb4cd | 54 | SString GetNewExpand(const char *keybase, const char *filename=""); |
9ce192d4 | 55 | void Clear(); |
65ec6247 RD |
56 | char *ToString(); // Caller must delete[] the return value |
57 | bool GetFirst(char **key, char **val); | |
58 | bool GetNext(char **key, char **val); | |
591d01be RD |
59 | |
60 | private: | |
61 | // copy-value semantics not implemented | |
62 | PropSet(const PropSet ©); | |
63 | void operator=(const PropSet &assign); | |
9ce192d4 RD |
64 | }; |
65 | ||
65ec6247 RD |
66 | /** |
67 | */ | |
9ce192d4 RD |
68 | class WordList { |
69 | public: | |
65ec6247 | 70 | // Each word contains at least one character - a empty word acts as sentinel at the end. |
9ce192d4 | 71 | char **words; |
d134f170 | 72 | char **wordsNoCase; |
9ce192d4 RD |
73 | char *list; |
74 | int len; | |
65ec6247 | 75 | bool onlyLineEnds; ///< Delimited by any white space or only line ends |
d134f170 | 76 | bool sorted; |
9ce192d4 | 77 | int starts[256]; |
9e730a78 | 78 | WordList(bool onlyLineEnds_ = false) : |
d134f170 | 79 | words(0), wordsNoCase(0), list(0), len(0), onlyLineEnds(onlyLineEnds_), sorted(false) {} |
9ce192d4 | 80 | ~WordList() { Clear(); } |
65ec6247 RD |
81 | operator bool() { return len ? true : false; } |
82 | char *operator[](int ind) { return words[ind]; } | |
9ce192d4 RD |
83 | void Clear(); |
84 | void Set(const char *s); | |
85 | char *Allocate(int size); | |
86 | void SetFromAllocated(); | |
87 | bool InList(const char *s); | |
9e730a78 | 88 | const char *GetNearestWord(const char *wordStart, int searchLen = -1, |
8e54aaed | 89 | bool ignoreCase = false, SString wordCharacters="", int wordIndex = -1); |
9e730a78 | 90 | char *GetNearestWords(const char *wordStart, int searchLen=-1, |
591d01be | 91 | bool ignoreCase=false, char otherSeparator='\0', bool exactLen=false); |
9ce192d4 RD |
92 | }; |
93 | ||
65ec6247 RD |
94 | inline bool IsAlphabetic(unsigned int ch) { |
95 | return ((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z')); | |
96 | } | |
97 | ||
591d01be RD |
98 | |
99 | #ifdef _MSC_VER | |
100 | // Visual C++ doesn't like the private copy idiom for disabling | |
101 | // the default copy constructor and operator=, but it's fine. | |
102 | #pragma warning(disable: 4511 4512) | |
103 | #endif | |
104 | ||
9ce192d4 | 105 | #endif |