]>
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 | 15 | |
7e0c58e9 RD |
16 | #ifdef SCI_NAMESPACE |
17 | namespace Scintilla { | |
18 | #endif | |
19 | ||
d134f170 RD |
20 | struct Property { |
21 | unsigned int hash; | |
22 | char *key; | |
23 | char *val; | |
24 | Property *next; | |
25 | Property() : hash(0), key(0), val(0), next(0) {} | |
9ce192d4 RD |
26 | }; |
27 | ||
65ec6247 RD |
28 | /** |
29 | */ | |
9ce192d4 | 30 | class PropSet { |
88a8b04e | 31 | protected: |
d134f170 RD |
32 | enum { hashRoots=31 }; |
33 | Property *props[hashRoots]; | |
65ec6247 RD |
34 | Property *enumnext; |
35 | int enumhash; | |
88a8b04e RD |
36 | static unsigned int HashString(const char *s, size_t len) { |
37 | unsigned int ret = 0; | |
38 | while (len--) { | |
39 | ret <<= 4; | |
40 | ret ^= *s; | |
41 | s++; | |
42 | } | |
43 | return ret; | |
44 | } | |
a33203cb | 45 | |
9ce192d4 RD |
46 | public: |
47 | PropSet *superPS; | |
48 | PropSet(); | |
49 | ~PropSet(); | |
65ec6247 RD |
50 | void Set(const char *key, const char *val, int lenKey=-1, int lenVal=-1); |
51 | void Set(const char *keyVal); | |
a33203cb | 52 | void Unset(const char *key, int lenKey=-1); |
65ec6247 | 53 | void SetMultiple(const char *s); |
7e0c58e9 RD |
54 | SString Get(const char *key) const; |
55 | SString GetExpanded(const char *key) const; | |
56 | SString Expand(const char *withVars, int maxExpands=100) const; | |
57 | int GetInt(const char *key, int defaultValue=0) const; | |
9ce192d4 | 58 | void Clear(); |
7e0c58e9 | 59 | char *ToString() const; // Caller must delete[] the return value |
591d01be RD |
60 | |
61 | private: | |
1e9bafca | 62 | // copy-value semantics not implemented |
591d01be RD |
63 | PropSet(const PropSet ©); |
64 | void operator=(const PropSet &assign); | |
9ce192d4 RD |
65 | }; |
66 | ||
65ec6247 RD |
67 | /** |
68 | */ | |
9ce192d4 RD |
69 | class WordList { |
70 | public: | |
65ec6247 | 71 | // Each word contains at least one character - a empty word acts as sentinel at the end. |
9ce192d4 RD |
72 | char **words; |
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) : |
7e0c58e9 RD |
79 | words(0), list(0), len(0), onlyLineEnds(onlyLineEnds_), |
80 | sorted(false) | |
81 | {} | |
9ce192d4 | 82 | ~WordList() { Clear(); } |
65ec6247 | 83 | operator bool() { return len ? true : false; } |
9ce192d4 RD |
84 | void Clear(); |
85 | void Set(const char *s); | |
9ce192d4 | 86 | bool InList(const char *s); |
1e9bafca | 87 | bool InListAbbreviated(const char *s, const char marker); |
9ce192d4 RD |
88 | }; |
89 | ||
65ec6247 RD |
90 | inline bool IsAlphabetic(unsigned int ch) { |
91 | return ((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z')); | |
92 | } | |
93 | ||
7e0c58e9 RD |
94 | #ifdef SCI_NAMESPACE |
95 | } | |
96 | #endif | |
591d01be RD |
97 | |
98 | #ifdef _MSC_VER | |
99 | // Visual C++ doesn't like the private copy idiom for disabling | |
100 | // the default copy constructor and operator=, but it's fine. | |
101 | #pragma warning(disable: 4511 4512) | |
102 | #endif | |
103 | ||
9ce192d4 | 104 | #endif |