Source code of Windows XP (NT5)
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.

92 lines
2.5 KiB

  1. #pragma once
  2. #include <string>
  3. int StringCompareI(const char* s, const char* t)
  4. { return _stricmp(s, t); }
  5. int StringCompareI(const wchar_t* s, const wchar_t* t)
  6. { return _wcsicmp(s, t); }
  7. int StringCompareNI(const char* s, const char* t, size_t n)
  8. { return _strnicmp(s, t, n); }
  9. int StringCompareNI(const wchar_t* s, const wchar_t* t, size_t n)
  10. { return _wcsnicmp(s, t, n); }
  11. size_t StringLength(const char* s)
  12. { return strlen(s); }
  13. size_t StringLength(const wchar_t* s)
  14. { return wcslen(s); }
  15. template <typename Char_t>
  16. class StringTemplate_t : public std::basic_string<Char_t>
  17. {
  18. typedef std::basic_string<Char_t> Base;
  19. public:
  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. bool Starts(const StringTemplate_t& t) const
  56. {
  57. return (StringCompareNI(c_str(), t.c_str(), t.Length()) == 0);
  58. }
  59. //
  60. // we're have some ambiguity problem..
  61. //
  62. const_reference operator[](int n) const { return *(begin() + n); }
  63. const_reference operator[](unsigned n) const { return *(begin() + n); }
  64. const_reference operator[](unsigned long n) const { return *(begin() + n); }
  65. operator const Char_t*() const { return c_str(); }
  66. };
  67. typedef StringTemplate_t<char> StringA_t;
  68. typedef StringTemplate_t<wchar_t> StringW_t;
  69. typedef StringW_t String_t;