codecvt.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. #include "stlport_prefix.h"
  19. #include <locale>
  20. #include <algorithm>
  21. _STLP_BEGIN_NAMESPACE
  22. //----------------------------------------------------------------------
  23. // codecvt<char, char, mbstate_t>
  24. codecvt<char, char, mbstate_t>::~codecvt() {}
  25. int codecvt<char, char, mbstate_t>::do_length(state_type&,
  26. const char* from,
  27. const char* end,
  28. size_t mx) const
  29. { return (int)(min) ( __STATIC_CAST(size_t, (end - from)), mx); }
  30. int codecvt<char, char, mbstate_t>::do_max_length() const _STLP_NOTHROW
  31. { return 1; }
  32. bool
  33. codecvt<char, char, mbstate_t>::do_always_noconv() const _STLP_NOTHROW
  34. { return true; }
  35. int
  36. codecvt<char, char, mbstate_t>::do_encoding() const _STLP_NOTHROW
  37. { return 1; }
  38. codecvt_base::result
  39. codecvt<char, char, mbstate_t>::do_unshift(state_type& /* __state */,
  40. char* __to,
  41. char* /* __to_limit */,
  42. char*& __to_next) const
  43. { __to_next = __to; return noconv; }
  44. codecvt_base::result
  45. codecvt<char, char, mbstate_t>::do_in (state_type& /* __state */ ,
  46. const char* __from,
  47. const char* /* __from_end */,
  48. const char*& __from_next,
  49. char* __to,
  50. char* /* __to_end */,
  51. char*& __to_next) const
  52. { __from_next = __from; __to_next = __to; return noconv; }
  53. codecvt_base::result
  54. codecvt<char, char, mbstate_t>::do_out(state_type& /* __state */,
  55. const char* __from,
  56. const char* /* __from_end */,
  57. const char*& __from_next,
  58. char* __to,
  59. char* /* __to_limit */,
  60. char*& __to_next) const
  61. { __from_next = __from; __to_next = __to; return noconv; }
  62. #if !defined (_STLP_NO_WCHAR_T)
  63. //----------------------------------------------------------------------
  64. // codecvt<wchar_t, char, mbstate_t>
  65. codecvt<wchar_t, char, mbstate_t>::~codecvt() {}
  66. codecvt<wchar_t, char, mbstate_t>::result
  67. codecvt<wchar_t, char, mbstate_t>::do_out(state_type& /* state */,
  68. const intern_type* from,
  69. const intern_type* from_end,
  70. const intern_type*& from_next,
  71. extern_type* to,
  72. extern_type* to_limit,
  73. extern_type*& to_next) const {
  74. ptrdiff_t len = (min) (from_end - from, to_limit - to);
  75. copy(from, from + len, to);
  76. from_next = from + len;
  77. to_next = to + len;
  78. return ok;
  79. }
  80. codecvt<wchar_t, char, mbstate_t>::result
  81. codecvt<wchar_t, char, mbstate_t>::do_in (state_type& /* state */,
  82. const extern_type* from,
  83. const extern_type* from_end,
  84. const extern_type*& from_next,
  85. intern_type* to,
  86. intern_type* to_limit,
  87. intern_type*& to_next) const {
  88. ptrdiff_t len = (min) (from_end - from, to_limit - to);
  89. copy(__REINTERPRET_CAST(const unsigned char*, from),
  90. __REINTERPRET_CAST(const unsigned char*, from) + len, to);
  91. from_next = from + len;
  92. to_next = to + len;
  93. return ok;
  94. }
  95. codecvt<wchar_t, char, mbstate_t>::result
  96. codecvt<wchar_t, char, mbstate_t>::do_unshift(state_type& /* state */,
  97. extern_type* to,
  98. extern_type* ,
  99. extern_type*& to_next) const {
  100. to_next = to;
  101. return noconv;
  102. }
  103. int codecvt<wchar_t, char, mbstate_t>::do_encoding() const _STLP_NOTHROW
  104. { return 1; }
  105. bool codecvt<wchar_t, char, mbstate_t>::do_always_noconv() const _STLP_NOTHROW
  106. { return true; }
  107. int codecvt<wchar_t, char, mbstate_t>::do_length(state_type&,
  108. const extern_type* from,
  109. const extern_type* end,
  110. size_t mx) const
  111. { return (int)(min) ((size_t) (end - from), mx); }
  112. int codecvt<wchar_t, char, mbstate_t>::do_max_length() const _STLP_NOTHROW
  113. { return 1; }
  114. #endif /* wchar_t */
  115. _STLP_END_NAMESPACE
  116. // Local Variables:
  117. // mode:C++
  118. // End: