_collate.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright (c) 1999
  3. * Silicon Graphics Computer Systems, Inc.
  4. *
  5. * Copyright (c) 1999
  6. * Boris Fomitchev
  7. *
  8. * This material is provided "as is", with absolutely no warranty expressed
  9. * or implied. Any use is at your own risk.
  10. *
  11. * Permission to use or copy this software for any purpose is hereby granted
  12. * without fee, provided the above notices are retained on all copies.
  13. * Permission to modify the code and to distribute modified code is granted,
  14. * provided the above notices are retained, and a notice that the code was
  15. * modified is included with the above copyright notice.
  16. *
  17. */
  18. // WARNING: This is an internal header file, included by other C++
  19. // standard library headers. You should not attempt to use this header
  20. // file directly.
  21. #ifndef _STLP_INTERNAL_COLLATE_H
  22. #define _STLP_INTERNAL_COLLATE_H
  23. #ifndef _STLP_C_LOCALE_H
  24. # include <stl/c_locale.h>
  25. #endif
  26. #ifndef _STLP_INTERNAL_LOCALE_H
  27. # include <stl/_locale.h>
  28. #endif
  29. #ifndef _STLP_INTERNAL_STRING_H
  30. # include <stl/_string.h>
  31. #endif
  32. _STLP_BEGIN_NAMESPACE
  33. template <class _CharT> class collate {};
  34. template <class _CharT> class collate_byname {};
  35. _STLP_TEMPLATE_NULL
  36. class _STLP_CLASS_DECLSPEC collate<char> : public locale::facet {
  37. public:
  38. typedef char char_type;
  39. typedef string string_type;
  40. explicit collate(size_t __refs = 0) : locale::facet(__refs) {}
  41. int compare(const char* __low1, const char* __high1,
  42. const char* __low2, const char* __high2) const {
  43. return do_compare( __low1, __high1, __low2, __high2);
  44. }
  45. string_type transform(const char* __low, const char* __high) const {
  46. return do_transform(__low, __high);
  47. }
  48. long hash(const char* __low, const char* __high) const
  49. { return do_hash(__low, __high); }
  50. static _STLP_STATIC_DECLSPEC locale::id id;
  51. protected:
  52. ~collate();
  53. virtual int do_compare(const char*, const char*,
  54. const char*, const char*) const;
  55. virtual string_type do_transform(const char*, const char*) const;
  56. virtual long do_hash(const char*, const char*) const;
  57. private:
  58. collate(const collate<char>&);
  59. collate<char>& operator =(const collate<char>&);
  60. };
  61. # ifndef _STLP_NO_WCHAR_T
  62. _STLP_TEMPLATE_NULL
  63. class _STLP_CLASS_DECLSPEC collate<wchar_t> : public locale::facet {
  64. public:
  65. typedef wchar_t char_type;
  66. typedef wstring string_type;
  67. explicit collate(size_t __refs = 0) : locale::facet(__refs) {}
  68. int compare(const wchar_t* __low1, const wchar_t* __high1,
  69. const wchar_t* __low2, const wchar_t* __high2) const {
  70. return do_compare( __low1, __high1, __low2, __high2);
  71. }
  72. string_type transform(const wchar_t* __low, const wchar_t* __high) const {
  73. return do_transform(__low, __high);
  74. }
  75. long hash(const wchar_t* __low, const wchar_t* __high) const
  76. { return do_hash(__low, __high); }
  77. static _STLP_STATIC_DECLSPEC locale::id id;
  78. protected:
  79. ~collate();
  80. virtual int do_compare(const wchar_t*, const wchar_t*,
  81. const wchar_t*, const wchar_t*) const;
  82. virtual string_type do_transform(const wchar_t*, const wchar_t*) const;
  83. virtual long do_hash(const wchar_t* __low, const wchar_t* __high) const;
  84. private:
  85. collate(const collate<wchar_t>&);
  86. collate<wchar_t>& operator = (const collate<wchar_t>&);
  87. };
  88. # endif /* NO_WCHAR_T */
  89. _STLP_TEMPLATE_NULL
  90. class _STLP_CLASS_DECLSPEC collate_byname<char>: public collate<char> {
  91. friend class _Locale_impl;
  92. public:
  93. explicit collate_byname(const char* __name, size_t __refs = 0);
  94. protected:
  95. ~collate_byname();
  96. virtual int do_compare(const char*, const char*,
  97. const char*, const char*) const;
  98. virtual string_type do_transform(const char*, const char*) const;
  99. private:
  100. collate_byname(_Locale_collate *__coll)
  101. : _M_collate(__coll) {}
  102. _Locale_collate* _M_collate;
  103. collate_byname(const collate_byname<char>&);
  104. collate_byname<char>& operator =(const collate_byname<char>&);
  105. };
  106. # ifndef _STLP_NO_WCHAR_T
  107. _STLP_TEMPLATE_NULL
  108. class _STLP_CLASS_DECLSPEC collate_byname<wchar_t>: public collate<wchar_t> {
  109. friend class _Locale_impl;
  110. public:
  111. explicit collate_byname(const char * __name, size_t __refs = 0);
  112. protected:
  113. ~collate_byname();
  114. virtual int do_compare(const wchar_t*, const wchar_t*,
  115. const wchar_t*, const wchar_t*) const;
  116. virtual string_type do_transform(const wchar_t*, const wchar_t*) const;
  117. private:
  118. collate_byname(_Locale_collate *__coll)
  119. : _M_collate(__coll) {}
  120. _Locale_collate* _M_collate;
  121. collate_byname(const collate_byname<wchar_t>&);
  122. collate_byname<wchar_t>& operator =(const collate_byname<wchar_t>&);
  123. };
  124. # endif /* NO_WCHAR_T */
  125. template <class _CharT, class _Traits, class _Alloc>
  126. bool
  127. __locale_do_operator_call (const locale& __loc,
  128. const basic_string<_CharT, _Traits, _Alloc>& __x,
  129. const basic_string<_CharT, _Traits, _Alloc>& __y) {
  130. collate<_CharT> const& __coll = use_facet<collate<_CharT> >(__loc);
  131. return __coll.compare(__x.data(), __x.data() + __x.size(),
  132. __y.data(), __y.data() + __y.size()) < 0;
  133. }
  134. _STLP_END_NAMESPACE
  135. #endif /* _STLP_INTERNAL_COLLATE_H */
  136. // Local Variables:
  137. // mode:C++
  138. // End: