home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / Rw / codecvt.cc next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  6.2 KB  |  184 lines

  1. #ifndef __CODECVT_CC
  2. #define __CODECVT_CC
  3. #pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
  4. /***************************************************************************
  5.  *
  6.  * codecvt.cc - Definitions for the Standard Library code conversion facet
  7.  *
  8.  ***************************************************************************
  9.  *
  10.  * Copyright (c) 1994-1999 Rogue Wave Software, Inc.  All Rights Reserved.
  11.  *
  12.  * This computer software is owned by Rogue Wave Software, Inc. and is
  13.  * protected by U.S. copyright laws and other laws and by international
  14.  * treaties.  This computer software is furnished by Rogue Wave Software,
  15.  * Inc. pursuant to a written license agreement and may be used, copied,
  16.  * transmitted, and stored only in accordance with the terms of such
  17.  * license and with the inclusion of the above copyright notice.  This
  18.  * computer software or any other copies thereof may not be provided or
  19.  * otherwise made available to any other person.
  20.  *
  21.  * U.S. Government Restricted Rights.  This computer software is provided
  22.  * with Restricted Rights.  Use, duplication, or disclosure by the
  23.  * Government is subject to restrictions as set forth in subparagraph (c)
  24.  * (1) (ii) of The Rights in Technical Data and Computer Software clause
  25.  * at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the
  26.  * Commercial Computer Software รป Restricted Rights at 48 CFR 52.227-19,
  27.  * as applicable.  Manufacturer is Rogue Wave Software, Inc., 5500
  28.  * Flatiron Parkway, Boulder, Colorado 80301 USA.
  29.  *
  30.  **************************************************************************/
  31.  
  32. #ifndef _RWSTD_NO_NAMESPACE
  33. namespace std {
  34. #endif
  35.  
  36. // -------------------------------------------------------
  37. // Facet codecvt<internT,externT,stateT> member templates.
  38. // -------------------------------------------------------
  39.  
  40. #ifndef _RWSTD_NO_TEMPLATE_STATIC_ID
  41. template <class internT,class externT,class stateT>
  42. locale::id codecvt<internT,externT,stateT>::id;
  43. #endif
  44.  
  45. template <class internT,class externT,class stateT>
  46. codecvt<internT,externT,stateT>::~codecvt() {}
  47.  
  48. template <class internT, class externT, class stateT>
  49. codecvt_base::result
  50. codecvt<internT,externT,stateT>::do_out (stateT&,
  51.     const internT*, const internT*, const internT*&,
  52.     externT*, externT*, externT*&) const
  53. {
  54.   return noconv;
  55. }
  56.  
  57. template <class internT, class externT, class stateT>
  58. codecvt_base::result
  59. codecvt<internT,externT,stateT>::do_in (stateT&,
  60.     const externT*, const externT*, const externT*&,
  61.     internT*, internT*, internT*&) const
  62. {
  63.   return noconv;
  64. }
  65.  
  66. template <class internT, class externT, class stateT>
  67. codecvt_base::result
  68. codecvt<internT,externT,stateT>::do_unshift (stateT&,
  69.     externT*, externT*, externT*&) const
  70. {
  71.   return noconv;
  72. }
  73.  
  74. template <class internT,class externT,class stateT>
  75. int codecvt<internT,externT,stateT>::do_encoding()
  76.     const _RWSTD_THROW_SPEC_NULL
  77. {
  78.   return sizeof(internT) == sizeof(externT);
  79. }
  80.  
  81. template <class internT,class externT,class stateT>
  82. bool codecvt<internT,externT,stateT>::do_always_noconv ()
  83.     const _RWSTD_THROW_SPEC_NULL
  84. {
  85.   return true;
  86. }
  87.  
  88. template <class internT,class externT,class stateT>
  89. int codecvt<internT,externT,stateT>::do_length (const stateT&,
  90.     const externT *from, const externT *from_end, size_t max) const
  91. {
  92.   return min (size_t(from_end-from), max);
  93. }
  94.  
  95. template <class internT,class externT,class stateT>
  96. int codecvt<internT,externT,stateT>::do_max_length ()
  97.     const _RWSTD_THROW_SPEC_NULL
  98. {
  99.   return 1;
  100. }
  101.  
  102. template <class internT,class externT,class stateT>
  103. _TYPENAME codecvt<internT,externT,stateT>::internal_string_type
  104. codecvt<internT,externT,stateT>::in (const external_string_type &s) const
  105. {
  106.   // Calculate the number of internT's that will be produced.  (I'm not sure
  107.   // what to use for max in the do_length call; too bad char_traits can't tell
  108.   // me.) (This needs to be revised to use separate in and out versions of
  109.   // do_length once someone comes up with the right syntax.)
  110.   int n=1000; // do_length(stateT(0),s.c_str(),s.c_str()+s.length(),
  111.               // numeric_limits<size_t>::max() / do_max_length());
  112.  
  113.   const externT *unused_from;
  114.   internT *unused_to;
  115.  
  116.   internT *conversion_buffer=new internT[n];
  117.   stateT stt(0);
  118.   n=do_in(stt,s.c_str(),s.c_str()+s.length(),unused_from,
  119.       conversion_buffer,conversion_buffer+n,unused_to);
  120.   internal_string_type result(conversion_buffer,conversion_buffer+n);
  121.   delete[] conversion_buffer;
  122.   return result;
  123. }
  124.  
  125. // --------------------------------------------------------------
  126. // Facet codecvt_byname<internT,externT,stateT> member templates.
  127. // --------------------------------------------------------------
  128.  
  129. template <class internT, class externT, class stateT>
  130. codecvt_byname<internT,externT,stateT>::codecvt_byname
  131.     (const char*, size_t refs):
  132.     codecvt<internT,externT,stateT>(refs)
  133. { }
  134.  
  135. template <class internT, class externT, class stateT>
  136. codecvt_byname<internT,externT, stateT>::~codecvt_byname ()
  137. { }
  138.  
  139. template <class internT, class externT, class stateT>
  140. codecvt_base::result 
  141. codecvt_byname<internT,externT, stateT>::do_out (stateT&,
  142.     const internT*, const internT*, const internT*&,
  143.           externT*, externT*, externT*&) const
  144. {
  145.   return codecvt_base::error;
  146. }
  147.  
  148. template <class internT, class externT, class stateT>
  149. codecvt_base::result
  150. codecvt_byname<internT,externT, stateT>::do_in (stateT&,
  151.     const externT*, const externT*, const externT*&,
  152.           internT*, internT*, internT*&) const
  153. {
  154.   return codecvt_base::error;
  155. }
  156.  
  157. template <class internT, class externT, class stateT>
  158. codecvt_base::result
  159. codecvt_byname<internT,externT,stateT>::do_unshift (stateT&,
  160.           externT*, externT*, externT*&) const
  161. {
  162.   return codecvt_base::error;
  163. }
  164.  
  165. template <class internT, class externT, class stateT>
  166. int codecvt_byname<internT,externT,stateT>::do_encoding () const
  167.     _RWSTD_THROW_SPEC_NULL
  168. {
  169.   return -1;
  170. }
  171.  
  172. template <class internT, class externT, class stateT>
  173. bool codecvt_byname<internT,externT,stateT>::do_always_noconv () const
  174.     _RWSTD_THROW_SPEC_NULL
  175. {
  176.   return false;
  177. }
  178. #ifndef _RWSTD_NO_NAMESPACE
  179. }
  180. #endif
  181.  
  182. #pragma option pop
  183. #endif /* __CODECVT_CC */
  184.