genericopenlibs/cppstdlib/stl/src/codecvt.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /*
       
     2  * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
       
     3  *
       
     4  * Copyright (c) 1999
       
     5  * Silicon Graphics Computer Systems, Inc.
       
     6  *
       
     7  * Copyright (c) 1999
       
     8  * Boris Fomitchev
       
     9  *
       
    10  * This material is provided "as is", with absolutely no warranty expressed
       
    11  * or implied. Any use is at your own risk.
       
    12  *
       
    13  * Permission to use or copy this software for any purpose is hereby granted
       
    14  * without fee, provided the above notices are retained on all copies.
       
    15  * Permission to modify the code and to distribute modified code is granted,
       
    16  * provided the above notices are retained, and a notice that the code was
       
    17  * modified is included with the above copyright notice.
       
    18  *
       
    19  */
       
    20 #include "stlport_prefix.h"
       
    21 
       
    22 #ifndef _STLP_NO_MBSTATE_T
       
    23 
       
    24 #include <locale>
       
    25 #include <algorithm>
       
    26 
       
    27 _STLP_BEGIN_NAMESPACE
       
    28 
       
    29 //----------------------------------------------------------------------
       
    30 // codecvt<char, char, mbstate_t>
       
    31 
       
    32 _STLP_DECLSPEC codecvt<char, char, mbstate_t>::~codecvt() {}
       
    33 
       
    34 _STLP_DECLSPEC int codecvt<char, char, mbstate_t>::do_length(const mbstate_t&,
       
    35                                               const  char* from,
       
    36                                               const  char* end,
       
    37                                               size_t mx) const
       
    38 { return (int)(min) ( __STATIC_CAST(size_t, (end - from)), mx); }
       
    39 
       
    40 _STLP_DECLSPEC int codecvt<char, char, mbstate_t>::do_max_length() const _STLP_NOTHROW
       
    41 { return 1; }
       
    42 
       
    43 _STLP_DECLSPEC bool
       
    44 codecvt<char, char, mbstate_t>::do_always_noconv() const _STLP_NOTHROW
       
    45 { return true; }
       
    46 
       
    47 _STLP_DECLSPEC int
       
    48 codecvt<char, char, mbstate_t>::do_encoding() const _STLP_NOTHROW
       
    49 { return 1; }
       
    50 
       
    51 _STLP_DECLSPEC codecvt_base::result
       
    52 codecvt<char, char, mbstate_t>::do_unshift(mbstate_t& /* __state */,
       
    53                                            char*      __to,
       
    54                                            char*      /* __to_limit */,
       
    55                                            char*&     __to_next) const
       
    56 { __to_next = __to; return noconv; }
       
    57 
       
    58 _STLP_DECLSPEC codecvt_base::result
       
    59 codecvt<char, char, mbstate_t>::do_in (mbstate_t&   /* __state */ ,
       
    60                                        const char*  __from,
       
    61                                        const char*  /* __from_end */,
       
    62                                        const char*& __from_next,
       
    63                                        char*        __to,
       
    64                                        char*        /* __to_end */,
       
    65                                        char*&       __to_next) const
       
    66 { __from_next = __from; __to_next   = __to; return noconv; }
       
    67 
       
    68 _STLP_DECLSPEC codecvt_base::result
       
    69 codecvt<char, char, mbstate_t>::do_out(mbstate_t&   /* __state */,
       
    70                                        const char*  __from,
       
    71                                        const char*  /* __from_end */,
       
    72                                        const char*& __from_next,
       
    73                                        char*        __to,
       
    74                                        char*        /* __to_limit */,
       
    75                                        char*&       __to_next) const
       
    76 { __from_next = __from; __to_next   = __to; return noconv; }
       
    77 
       
    78 
       
    79 #if !defined (_STLP_NO_WCHAR_T)
       
    80 //----------------------------------------------------------------------
       
    81 // codecvt<wchar_t, char, mbstate_t>
       
    82 
       
    83 _STLP_DECLSPEC codecvt<wchar_t, char, mbstate_t>::~codecvt() {}
       
    84 
       
    85 
       
    86 _STLP_DECLSPEC codecvt<wchar_t, char, mbstate_t>::result
       
    87 codecvt<wchar_t, char, mbstate_t>::do_out(state_type&         /* state */,
       
    88                                           const intern_type*  from,
       
    89                                           const intern_type*  from_end,
       
    90                                           const intern_type*& from_next,
       
    91                                           extern_type*        to,
       
    92                                           extern_type*        to_limit,
       
    93                                           extern_type*&       to_next) const {
       
    94   ptrdiff_t len = (min) (from_end - from, to_limit - to);
       
    95   copy(from, from + len, to);
       
    96   from_next = from + len;
       
    97   to_next   = to   + len;
       
    98   return ok;
       
    99 }
       
   100 
       
   101 _STLP_DECLSPEC codecvt<wchar_t, char, mbstate_t>::result
       
   102 codecvt<wchar_t, char, mbstate_t>::do_in (state_type&       /* state */,
       
   103                                           const extern_type*  from,
       
   104                                           const extern_type*  from_end,
       
   105                                           const extern_type*& from_next,
       
   106                                           intern_type*        to,
       
   107                                           intern_type*        to_limit,
       
   108                                           intern_type*&       to_next) const {
       
   109   ptrdiff_t len = (min) (from_end - from, to_limit - to);
       
   110   copy(__REINTERPRET_CAST(const unsigned char*, from),
       
   111        __REINTERPRET_CAST(const unsigned char*, from) + len, to);
       
   112   from_next = from + len;
       
   113   to_next   = to   + len;
       
   114   return ok;
       
   115 }
       
   116 
       
   117 _STLP_DECLSPEC codecvt<wchar_t, char, mbstate_t>::result
       
   118 codecvt<wchar_t, char, mbstate_t>::do_unshift(state_type&   /* state */,
       
   119                                               extern_type*  to,
       
   120                                               extern_type*  ,
       
   121                                               extern_type*& to_next) const {
       
   122   to_next = to;
       
   123   return noconv;
       
   124 }
       
   125 
       
   126 _STLP_DECLSPEC int codecvt<wchar_t, char, mbstate_t>::do_encoding() const _STLP_NOTHROW
       
   127 #ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
       
   128 {
       
   129 	int __ret = 0;
       
   130     if (MB_CUR_MAX == 1)
       
   131       __ret = 1;
       
   132     return __ret;
       
   133  }
       
   134 #else
       
   135 { return 1; }
       
   136 #endif
       
   137 
       
   138 _STLP_DECLSPEC bool codecvt<wchar_t, char, mbstate_t>::do_always_noconv() const _STLP_NOTHROW
       
   139 { return true; }
       
   140 
       
   141 _STLP_DECLSPEC int codecvt<wchar_t, char, mbstate_t>::do_length(const  state_type&,
       
   142                                                  const  extern_type* from,
       
   143                                                  const  extern_type* end,
       
   144                                                  size_t mx) const
       
   145 { return (int)(min) ((size_t) (end - from), mx); }
       
   146 
       
   147 _STLP_DECLSPEC int codecvt<wchar_t, char, mbstate_t>::do_max_length() const _STLP_NOTHROW
       
   148 { return 1; }
       
   149 #endif /* wchar_t */
       
   150 
       
   151 _STLP_END_NAMESPACE
       
   152 
       
   153 #endif /* _STLP_NO_MBSTATE_T */
       
   154 
       
   155 // Local Variables:
       
   156 // mode:C++
       
   157 // End:
       
   158