X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9ce192d417eb9eb614bcf8510e91dac318706249..f0b22b4a039b5797b94ecde35e2b67f6716c9e84:/src/stc/scintilla/include/PropSet.h diff --git a/src/stc/scintilla/include/PropSet.h b/src/stc/scintilla/include/PropSet.h index 31da01f954..025174f8ab 100644 --- a/src/stc/scintilla/include/PropSet.h +++ b/src/stc/scintilla/include/PropSet.h @@ -8,44 +8,92 @@ bool EqualCaseInsensitive(const char *a, const char *b); +#if PLAT_WIN +#define strcasecmp stricmp +#define strncasecmp strnicmp +#endif + +#ifdef __WXMSW__ +#define strcasecmp stricmp +#define strncasecmp strnicmp +#endif + // Define another string class. // While it would be 'better' to use std::string, that doubles the executable size. -inline char *StringDup(const char *s) { +inline char *StringDup(const char *s, int len=-1) { if (!s) return 0; - char *sNew = new char[strlen(s) + 1]; - if (sNew) - strcpy(sNew, s); + if (len == -1) + len = strlen(s); + char *sNew = new char[len + 1]; + if (sNew) { + strncpy(sNew, s, len); + sNew[len] = '\0'; + } return sNew; } class SString { char *s; + int ssize; public: + typedef const char* const_iterator; + typedef int size_type; + static size_type npos; + const char* begin(void) const { + return s; + } + const char* end(void) const { + return &s[ssize]; + } + size_type size(void) const { + if (s) + return ssize; + else + return 0; + } + SString &assign(const char* sother, int size_ = -1) { + char *t = s; + s = StringDup(sother,size_); + ssize = (s) ? strlen(s) : 0; + delete []t; + return *this; + } + SString &assign(const SString& sother, int size_ = -1) { + return assign(sother.s,size_); + } + SString &assign(const_iterator ibeg, const_iterator iend) { + return assign(ibeg,iend - ibeg); + } SString() { s = 0; + ssize = 0; } SString(const SString &source) { s = StringDup(source.s); + ssize = (s) ? strlen(s) : 0; } SString(const char *s_) { s = StringDup(s_); + ssize = (s) ? strlen(s) : 0; } SString(int i) { char number[100]; sprintf(number, "%0d", i); - //itoa(i, number, 10); s = StringDup(number); + ssize = (s) ? strlen(s) : 0; } ~SString() { delete []s; s = 0; + ssize = 0; } SString &operator=(const SString &source) { if (this != &source) { delete []s; s = StringDup(source.s); + ssize = (s) ? strlen(s) : 0; } return *this; } @@ -56,6 +104,9 @@ public: return false; return strcmp(s, other.s) == 0; } + bool operator!=(const SString &other) const { + return !operator==(other); + } bool operator==(const char *sother) const { if ((s == 0) && (sother == 0)) return true; @@ -63,6 +114,9 @@ public: return false; return strcmp(s, sother) == 0; } + bool operator!=(const char *sother) const { + return !operator==(sother); + } const char *c_str() const { if (s) return s; @@ -75,106 +129,116 @@ public: else return 0; } - char operator[](int i) { + char operator[](int i) const { if (s) return s[i]; else return '\0'; } SString &operator +=(const char *sother) { + return append(sother,-1); + } + SString &operator +=(const SString &sother) { + return append(sother.s,sother.ssize); + } + SString &operator +=(char ch) { + return append(&ch,1); + } + SString &append(const char* sother, int lenOther) { int len = length(); - int lenOther = strlen(sother); + if(lenOther < 0) + lenOther = strlen(sother); char *sNew = new char[len + lenOther + 1]; if (sNew) { if (s) memcpy(sNew, s, len); - memcpy(sNew + len, sother, lenOther); + strncpy(&sNew[len], sother, lenOther); sNew[len + lenOther] = '\0'; delete []s; s = sNew; + ssize = (s) ? strlen(s) : 0; } return *this; } - int value() { + int value() const { if (s) return atoi(s); - else + else return 0; } + void substitute(char find, char replace) { + char *t = s; + while (t) { + t = strchr(t, find); + if (t) + *t = replace; + } + } + // I don't think this really belongs here -- Neil + void correctPath() { +#ifdef unix + substitute('\\', '/'); +#else + substitute('/', '\\'); +#endif + } +}; + +struct Property { + unsigned int hash; + char *key; + char *val; + Property *next; + Property() : hash(0), key(0), val(0), next(0) {} }; class PropSet { private: - char **vals; - int size; - int used; + enum { hashRoots=31 }; + Property *props[hashRoots]; public: PropSet *superPS; PropSet(); ~PropSet(); - void EnsureCanAddEntry(); 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(); - 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 -class EntryMemory { - SString entries[sz]; -public: - void Insert(SString s) { - for (int i=0;i0;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?@[\\]^`{|}~", ch) != NULL; +} + #endif