TQt conversion of scintilla for Qt3
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PropSet.h 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Scintilla source code edit control
  2. /** @file PropSet.h
  3. ** A Java style properties file module.
  4. **/
  5. // Copyright 1998-2002 by Neil Hodgson <neilh@scintilla.org>
  6. // The License.txt file describes the conditions under which this software may be distributed.
  7. #ifndef PROPSET_H
  8. #define PROPSET_H
  9. #include "SString.h"
  10. bool EqualCaseInsensitive(const char *a, const char *b);
  11. bool isprefix(const char *target, const char *prefix);
  12. struct Property {
  13. unsigned int hash;
  14. char *key;
  15. char *val;
  16. Property *next;
  17. Property() : hash(0), key(0), val(0), next(0) {}
  18. };
  19. /**
  20. */
  21. class PropSet {
  22. protected:
  23. enum { hashRoots=31 };
  24. Property *props[hashRoots];
  25. Property *enumnext;
  26. int enumhash;
  27. static bool caseSensitiveFilenames;
  28. static unsigned int HashString(const char *s, size_t len) {
  29. unsigned int ret = 0;
  30. while (len--) {
  31. ret <<= 4;
  32. ret ^= *s;
  33. s++;
  34. }
  35. return ret;
  36. }
  37. static bool IncludesVar(const char *value, const char *key);
  38. public:
  39. PropSet *superPS;
  40. PropSet();
  41. ~PropSet();
  42. void Set(const char *key, const char *val, int lenKey=-1, int lenVal=-1);
  43. void Set(const char *keyVal);
  44. void Unset(const char *key, int lenKey=-1);
  45. void SetMultiple(const char *s);
  46. SString Get(const char *key);
  47. SString GetExpanded(const char *key);
  48. SString Expand(const char *withVars, int maxExpands=100);
  49. int GetInt(const char *key, int defaultValue=0);
  50. SString GetWild(const char *keybase, const char *filename);
  51. SString GetNewExpand(const char *keybase, const char *filename="");
  52. void Clear();
  53. char *ToString(); // Caller must delete[] the return value
  54. bool GetFirst(char **key, char **val);
  55. bool GetNext(char **key, char **val);
  56. static void SetCaseSensitiveFilenames(bool caseSensitiveFilenames_) {
  57. caseSensitiveFilenames = caseSensitiveFilenames_;
  58. }
  59. private:
  60. // copy-value semantics not implemented
  61. PropSet(const PropSet &copy);
  62. void operator=(const PropSet &assign);
  63. };
  64. /**
  65. */
  66. class WordList {
  67. public:
  68. // Each word contains at least one character - a empty word acts as sentinel at the end.
  69. char **words;
  70. char **wordsNoCase;
  71. char *list;
  72. int len;
  73. bool onlyLineEnds; ///< Delimited by any white space or only line ends
  74. bool sorted;
  75. bool sortedNoCase;
  76. int starts[256];
  77. WordList(bool onlyLineEnds_ = false) :
  78. words(0), wordsNoCase(0), list(0), len(0), onlyLineEnds(onlyLineEnds_),
  79. sorted(false), sortedNoCase(false) {}
  80. ~WordList() { Clear(); }
  81. operator bool() { return len ? true : false; }
  82. char *operator[](int ind) { return words[ind]; }
  83. void Clear();
  84. void Set(const char *s);
  85. char *Allocate(int size);
  86. void SetFromAllocated();
  87. bool InList(const char *s);
  88. bool InListAbbreviated(const char *s, const char marker);
  89. const char *GetNearestWord(const char *wordStart, int searchLen,
  90. bool ignoreCase = false, SString wordCharacters="", int wordIndex = -1);
  91. char *GetNearestWords(const char *wordStart, int searchLen,
  92. bool ignoreCase=false, char otherSeparator='\0', bool exactLen=false);
  93. };
  94. inline bool IsAlphabetic(unsigned int ch) {
  95. return ((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z'));
  96. }
  97. #ifdef _MSC_VER
  98. // Visual C++ doesn't like the private copy idiom for disabling
  99. // the default copy constructor and operator=, but it's fine.
  100. #pragma warning(disable: 4511 4512)
  101. #endif
  102. #endif