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