aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/PropSet.h
blob: 90e0a266fbbb5db928e6def45b3d2151c8798a7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Scintilla source code edit control
/** @file PropSet.h
 ** A Java style properties file module.
 **/
// Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.

#ifndef PROPSET_H
#define PROPSET_H
#include "SString.h"

bool EqualCaseInsensitive(const char *a, const char *b);

bool isprefix(const char *target, const char *prefix);

struct Property {
	unsigned int hash;
	char *key;
	char *val;
	Property *next;
	Property() : hash(0), key(0), val(0), next(0) {}
};

/**
 */
class PropSet {
private:
	enum { hashRoots=31 };
	Property *props[hashRoots];
public:
	PropSet *superPS;
	PropSet();
	~PropSet();
	void Set(const char *key, const char *val);
	void Set(char *keyval);
	SString Get(const char *key);
	SString GetExpanded(const char *key);
	SString Expand(const char *withvars);
	int GetInt(const char *key, int defaultValue=0);
	SString GetWild(const char *keybase, const char *filename);
	SString GetNewExpand(const char *keybase, const char *filename);
	void Clear();
};

/**
 */
class WordList {
public:
	// Each word contains at least one character - a empty word acts as sentinel at the end.
	char **words;
	char **wordsNoCase;
	char *list;
	int len;
	bool onlyLineEnds;	///< Delimited by any white space or only line ends
	bool sorted;
	int starts[256];
	WordList(bool onlyLineEnds_ = false) : 
		words(0), wordsNoCase(0), list(0), len(0), onlyLineEnds(onlyLineEnds_), sorted(false) {}
	~WordList() { Clear(); }
	operator bool() { return len ? true : false; }
	const char *operator[](int ind) { return words[ind]; }
	void Clear();
	void Set(const char *s);
	char *Allocate(int size);
	void SetFromAllocated();
	bool InList(const char *s);
	const char *GetNearestWord(const char *wordStart, int searchLen = -1, bool ignoreCase = false);
	char *GetNearestWords(const char *wordStart, int searchLen = -1, bool ignoreCase = false);
};

inline bool nonFuncChar(char ch) {
	return strchr("\t\n\r !\"#$%&'()*+,-./:;<=>?@[\\]^`{|}~", ch) != NULL;
}

#endif