Leaked source code of windows server 2003
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.

96 lines
2.8 KiB

  1. #pragma once
  2. #include <string>
  3. inline int StringCompareI(const char* s, const char* t)
  4. { return _stricmp(s, t); }
  5. inline int StringCompareI(const wchar_t* s, const wchar_t* t)
  6. { return _wcsicmp(s, t); }
  7. inline int StringCompareNI(const char* s, const char* t, size_t n)
  8. { return _strnicmp(s, t, n); }
  9. inline int StringCompareNI(const wchar_t* s, const wchar_t* t, size_t n)
  10. { return _wcsnicmp(s, t, n); }
  11. template <typename Char_t>
  12. class StringTemplate_t : public std::basic_string<Char_t>
  13. {
  14. typedef std::basic_string<Char_t> Base;
  15. public:
  16. static size_t StringLength(const char* s)
  17. { return strlen(s); }
  18. static size_t StringLength(const wchar_t* s)
  19. { return wcslen(s); }
  20. StringTemplate_t() { }
  21. ~StringTemplate_t() { }
  22. StringTemplate_t(const_iterator i, const_iterator j) : Base(i, j) { }
  23. StringTemplate_t(PCWSTR t) : Base(t) { }
  24. StringTemplate_t& operator=(PCWSTR t) { Base::operator=(t); return *this; }
  25. StringTemplate_t(const StringTemplate_t& t) : Base(t) { }
  26. StringTemplate_t& operator=(const StringTemplate_t& t) { Base::operator=(t); return *this; }
  27. StringTemplate_t(const Base& t) : Base(t) { }
  28. StringTemplate_t& operator=(const Base& t) { Base::operator=(t); return *this; }
  29. bool operator<(const StringTemplate_t& t) const
  30. {
  31. return (StringCompareI(c_str(), t.c_str()) < 0);
  32. }
  33. bool operator==(const StringTemplate_t& t) const
  34. {
  35. return (StringCompareI(c_str(), t.c_str()) == 0);
  36. }
  37. bool operator<(const Base& t) const
  38. {
  39. return (StringCompareI(c_str(), t.c_str()) < 0);
  40. }
  41. bool operator==(const Base& t) const
  42. {
  43. return (StringCompareI(c_str(), t.c_str()) == 0);
  44. }
  45. bool operator<(PCWSTR t) const
  46. {
  47. return (StringCompareI(c_str(), t) < 0);
  48. }
  49. bool operator==(PCWSTR t) const
  50. {
  51. return (StringCompareI(c_str(), t) == 0);
  52. }
  53. static size_t Length(PCWSTR s) { return StringLength(s); }
  54. size_t Length() const { return length(); }
  55. size_t GetLength() const { return length(); }
  56. void clear() { const static Char_t c[1]; operator=(c); }
  57. bool Starts(const StringTemplate_t& t) const
  58. {
  59. return (StringCompareNI(c_str(), t.c_str(), t.Length()) == 0);
  60. }
  61. //
  62. // we're have some ambiguity problem..
  63. //
  64. const_reference operator[](int n) const { return *(begin() + n); }
  65. const_reference operator[](unsigned n) const { return *(begin() + n); }
  66. const_reference operator[](unsigned long n) const { return *(begin() + n); }
  67. operator const Char_t*() const { return c_str(); }
  68. };
  69. typedef StringTemplate_t<char> StringA_t;
  70. typedef StringTemplate_t<wchar_t> StringW_t;
  71. typedef StringW_t String_t;