tstring.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef __tstring_h__
  2. #define __tstring_h__
  3. #pragma once
  4. /////////////////////////////////////////////////////////////////////////////
  5. #pragma warning(disable: 4786)
  6. #include <functional>
  7. #include <string>
  8. #include <string.h>
  9. #include <tchar.h>
  10. #include <comutil.h>
  11. /////////////////////////////////////////////////////////////////////////////
  12. // Types
  13. typedef std::basic_string<TCHAR> tstring;
  14. /////////////////////////////////////////////////////////////////////////////
  15. // ci_less
  16. struct ci_less : public std::binary_function<tstring, tstring, bool>
  17. {
  18. bool operator()(const tstring& x, const tstring& y) const
  19. {
  20. return 0 > _tcsicmp(x.c_str(), y.c_str());
  21. }
  22. };
  23. typedef std::binary_negate<ci_less> ci_greater;
  24. /////////////////////////////////////////////////////////////////////////////
  25. // ci_less_bstr_t
  26. struct ci_less_bstr_t : public std::binary_function<_bstr_t, _bstr_t, bool>
  27. {
  28. bool operator()(const _bstr_t& x, const _bstr_t& y) const
  29. {
  30. if (!x.length())
  31. return y.length() ? true : false;
  32. if (!y.length())
  33. return false;
  34. int n = _wcsnicmp(x, y, min(x.length(), y.length()));
  35. if (0 > n)
  36. return true;
  37. if (0 == n)
  38. return x.length() < y.length();
  39. else
  40. return false;
  41. }
  42. };
  43. typedef std::binary_negate<ci_less_bstr_t> ci_greater_bstr_t;
  44. /////////////////////////////////////////////////////////////////////////////
  45. #endif // !__tstring_h__