-// SciTE - Scintilla based Text Editor
-// PropSet.h - a java style properties file module
-// Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org>
+// Scintilla source code edit control
+/** @file PropSet.h
+ ** A Java style properties file module.
+ **/
+// Copyright 1998-2002 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);
-// Define another string class.
-// While it would be 'better' to use std::string, that doubles the executable size.
+bool isprefix(const char *target, const char *prefix);
-inline char *StringDup(const char *s) {
- if (!s)
- return 0;
- char *sNew = new char[strlen(s) + 1];
- if (sNew)
- strcpy(sNew, s);
- return sNew;
-}
+struct Property {
+ unsigned int hash;
+ char *key;
+ char *val;
+ Property *next;
+ Property() : hash(0), key(0), val(0), next(0) {}
+};
-class SString {
- char *s;
-public:
- SString() {
- s = 0;
- }
- SString(const SString &source) {
- s = StringDup(source.s);
- }
- SString(const char *s_) {
- s = StringDup(s_);
- }
- SString(int i) {
- char number[100];
- sprintf(number, "%0d", i);
- //itoa(i, number, 10);
- s = StringDup(number);
- }
- ~SString() {
- delete []s;
- s = 0;
- }
- SString &operator=(const SString &source) {
- if (this != &source) {
- delete []s;
- s = StringDup(source.s);
- }
- return *this;
- }
- bool operator==(const SString &other) const {
- if ((s == 0) && (other.s == 0))
- return true;
- if ((s == 0) || (other.s == 0))
- return false;
- return strcmp(s, other.s) == 0;
- }
- bool operator==(const char *sother) const {
- if ((s == 0) && (sother == 0))
- return true;
- if ((s == 0) || (sother == 0))
- return false;
- return strcmp(s, sother) == 0;
- }
- const char *c_str() const {
- if (s)
- return s;
- else
- return "";
- }
- int length() const {
- if (s)
- return strlen(s);
- else
- return 0;
- }
- char operator[](int i) {
- if (s)
- return s[i];
- else
- return '\0';
- }
- SString &operator +=(const char *sother) {
- int len = length();
- int lenOther = strlen(sother);
- char *sNew = new char[len + lenOther + 1];
- if (sNew) {
- if (s)
- memcpy(sNew, s, len);
- memcpy(sNew + len, sother, lenOther);
- sNew[len + lenOther] = '\0';
- delete []s;
- s = sNew;
+/**
+ */
+class PropSet {
+protected:
+ enum { hashRoots=31 };
+ Property *props[hashRoots];
+ Property *enumnext;
+ int enumhash;
+ static bool caseSensitiveFilenames;
+ static unsigned int HashString(const char *s, size_t len) {
+ unsigned int ret = 0;
+ while (len--) {
+ ret <<= 4;
+ ret ^= *s;
+ s++;
}
- return *this;
- }
- int value() {
- if (s)
- return atoi(s);
- else
- return 0;
+ return ret;
}
-};
+ static bool IncludesVar(const char *value, const char *key);
-class PropSet {
-private:
- char **vals;
- int size;
- int used;
public:
PropSet *superPS;
PropSet();
~PropSet();
- void EnsureCanAddEntry();
- void Set(const char *key, const char *val);
- void Set(char *keyval);
+ void Set(const char *key, const char *val, int lenKey=-1, int lenVal=-1);
+ void Set(const char *keyVal);
+ void Unset(const char *key, int lenKey=-1);
+ void SetMultiple(const char *s);
SString Get(const char *key);
+ SString GetExpanded(const char *key);
+ SString Expand(const char *withVars, int maxExpands=100);
int GetInt(const char *key, int defaultValue=0);
SString GetWild(const char *keybase, const char *filename);
- SString GetNewExpand(const char *keybase, const char *filename);
+ SString GetNewExpand(const char *keybase, const char *filename="");
void Clear();
- void ReadFromMemory(const char *data, int len);
- void Read(const char *filename);
-};
-
-// This is a fixed length list of strings suitable for display in combo boxes
-// as a memory of user entries
-template<int sz>
-class EntryMemory {
- SString entries[sz];
-public:
- void Insert(SString s) {
- for (int i=0;i<sz;i++) {
- if (entries[i] == s) {
- for (int j=i;j>0;j--) {
- entries[j] = entries[j-1];
- }
- entries[0] = s;
- return;
- }
- }
- for (int k=sz-1;k>0;k--) {
- entries[k] = entries[k-1];
- }
- entries[0] = s;
- }
- int Length() const {
- int len = 0;
- for (int i=0;i<sz;i++)
- if (entries[i].length())
- len++;
- return len;
- }
- SString At(int n) const {
- return entries[n];
+ char *ToString(); // Caller must delete[] the return value
+ bool GetFirst(char **key, char **val);
+ bool GetNext(char **key, char **val);
+ static void SetCaseSensitiveFilenames(bool caseSensitiveFilenames_) {
+ caseSensitiveFilenames = caseSensitiveFilenames_;
}
+
+private:
+ // copy-value semantics not implemented
+ PropSet(const PropSet ©);
+ void operator=(const PropSet &assign);
};
+/**
+ */
class WordList {
public:
- // Each word contains at least one character - a empty word acts as sentinal at the end.
+ // 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 onlyLineEnds; ///< Delimited by any white space or only line ends
+ bool sorted;
+ bool sortedNoCase;
int starts[256];
- WordList(bool onlyLineEnds_ = false) :
- words(0), list(0), len(0), onlyLineEnds(onlyLineEnds_) {}
+ WordList(bool onlyLineEnds_ = false) :
+ words(0), wordsNoCase(0), list(0), len(0), onlyLineEnds(onlyLineEnds_),
+ sorted(false), sortedNoCase(false) {}
~WordList() { Clear(); }
- operator bool() { return list; }
- const char *operator[](int ind) { return words[ind]; }
+ operator bool() { return len ? true : false; }
+ 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);
+ bool InListAbbreviated(const char *s, const char marker);
+ const char *GetNearestWord(const char *wordStart, int searchLen,
+ bool ignoreCase = false, SString wordCharacters="", int wordIndex = -1);
+ char *GetNearestWords(const char *wordStart, int searchLen,
+ bool ignoreCase=false, char otherSeparator='\0', bool exactLen=false);
};
+inline bool IsAlphabetic(unsigned int ch) {
+ return ((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z'));
+}
+
+
+#ifdef _MSC_VER
+// Visual C++ doesn't like the private copy idiom for disabling
+// the default copy constructor and operator=, but it's fine.
+#pragma warning(disable: 4511 4512)
+#endif
+
#endif