os/ossrv/genericopenlibs/cppstdlib/stl/src/num_put.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/src/num_put.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,230 @@
     1.4 +/*
     1.5 + * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
     1.6 + *
     1.7 + * Copyright (c) 1999
     1.8 + * Silicon Graphics Computer Systems, Inc.
     1.9 + *
    1.10 + * Copyright (c) 1999
    1.11 + * Boris Fomitchev
    1.12 + *
    1.13 + * This material is provided "as is", with absolutely no warranty expressed
    1.14 + * or implied. Any use is at your own risk.
    1.15 + *
    1.16 + * Permission to use or copy this software for any purpose is hereby granted
    1.17 + * without fee, provided the above notices are retained on all copies.
    1.18 + * Permission to modify the code and to distribute modified code is granted,
    1.19 + * provided the above notices are retained, and a notice that the code was
    1.20 + * modified is included with the above copyright notice.
    1.21 + *
    1.22 + */
    1.23 +
    1.24 +#include "stlport_prefix.h"
    1.25 +
    1.26 +#include <locale>
    1.27 +#include <ostream>
    1.28 +
    1.29 +#ifdef __SYMBIAN32__WSD__
    1.30 +#include <libstdcppwsd.h>
    1.31 +#endif //__SYMBIAN32__WSD__
    1.32 +
    1.33 +_STLP_BEGIN_NAMESPACE
    1.34 +
    1.35 +// Note that grouping[0] is the number of digits in the *rightmost* group.
    1.36 +// We assume, without checking, that *last is null and that there is enough
    1.37 +// space in the buffer to extend the number past [first, last).
    1.38 +template <class Char>
    1.39 +static ptrdiff_t
    1.40 +__insert_grouping_aux(Char* first, Char* last, const string& grouping,
    1.41 +                      Char separator, Char Plus, Char Minus,
    1.42 +                      int basechars) {
    1.43 +  typedef string::size_type str_size;
    1.44 +
    1.45 +  if (first == last)
    1.46 +    return 0;
    1.47 +
    1.48 +  int sign = 0;
    1.49 +
    1.50 +  if (*first == Plus || *first == Minus) {
    1.51 +    sign = 1;
    1.52 +    ++first;
    1.53 +  }
    1.54 +
    1.55 +  first += basechars;
    1.56 +  str_size n = 0;               // Index of the current group.
    1.57 +  Char* cur_group = last;       // Points immediately beyond the rightmost
    1.58 +                                // digit of the current group.
    1.59 +  int groupsize = 0;            // Size of the current group.
    1.60 +
    1.61 +  for (;;) {
    1.62 +    groupsize = n < grouping.size() ? grouping[n] : groupsize;
    1.63 +    ++n;
    1.64 +
    1.65 +    if (groupsize <= 0 || groupsize >= cur_group - first)
    1.66 +      break;
    1.67 +
    1.68 +    // Insert a separator character just before position cur_group - groupsize
    1.69 +    cur_group -= groupsize;
    1.70 +    ++last;
    1.71 +    copy_backward(cur_group, last, last + 1);
    1.72 +    *cur_group = separator;
    1.73 +  }
    1.74 +
    1.75 +  return (last - first) + sign + basechars;
    1.76 +}
    1.77 +
    1.78 +//Dynamic output buffer version.
    1.79 +template <class Char, class Str>
    1.80 +static void
    1.81 +__insert_grouping_aux( /* __basic_iostring<Char> */ Str& iostr, size_t __group_pos,
    1.82 +                      const string& grouping,
    1.83 +                      Char separator, Char Plus, Char Minus,
    1.84 +                      int basechars) {
    1.85 +  typedef string::size_type str_size;
    1.86 +
    1.87 +  if (iostr.size() < __group_pos)
    1.88 +    return;
    1.89 +
    1.90 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
    1.91 +  int __first_pos = 0;
    1.92 +#else
    1.93 +  size_t __first_pos = 0;
    1.94 +#endif
    1.95 +  Char __first = *iostr.begin();
    1.96 +
    1.97 +  if (__first == Plus || __first == Minus) {
    1.98 +    ++__first_pos;
    1.99 +  }
   1.100 +
   1.101 +  __first_pos += basechars;
   1.102 +#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
   1.103 +  typename basic_string<Char>::iterator cur_group(iostr.begin() + __group_pos);  // Points immediately beyond the rightmost
   1.104 +  																	// digit of the current group.
   1.105 +  int groupsize = 0; // Size of the current group (if grouping.size() == 0, size
   1.106 +                     // of group unlimited: we force condition (groupsize <= 0))
   1.107 +
   1.108 +  for ( str_size n = 0; ; ) { // Index of the current group
   1.109 +    if ( n < grouping.size() ) {
   1.110 +      groupsize = __STATIC_CAST( int, grouping[n++] );
   1.111 +    }
   1.112 +
   1.113 +    if ( (groupsize <= 0) || (groupsize >= ((cur_group - iostr.begin()) - __first_pos)) ||
   1.114 +         (groupsize == CHAR_MAX)) {
   1.115 +      break;
   1.116 +    }
   1.117 +#else
   1.118 +  str_size n = 0;                                                   // Index of the current group.
   1.119 +  typename basic_string<Char>::iterator cur_group(iostr.begin() + __group_pos);  // Points immediately beyond the rightmost
   1.120 +                                                                    // digit of the current group.
   1.121 +  unsigned int groupsize = 0;                                       // Size of the current group.
   1.122 +
   1.123 +  for (;;) {
   1.124 +    groupsize = n < grouping.size() ? grouping[n] : groupsize;
   1.125 +    ++n;
   1.126 +
   1.127 +    if (groupsize <= 0 || groupsize >= ((cur_group - iostr.begin()) + __first_pos))
   1.128 +      break;
   1.129 +#endif
   1.130 +
   1.131 +    // Insert a separator character just before position cur_group - groupsize
   1.132 +    cur_group -= groupsize;
   1.133 +    cur_group = iostr.insert(cur_group, separator);
   1.134 +  }
   1.135 +}
   1.136 +
   1.137 +//----------------------------------------------------------------------
   1.138 +// num_put
   1.139 +
   1.140 +_STLP_MOVE_TO_PRIV_NAMESPACE
   1.141 +
   1.142 +_STLP_DECLSPEC const char* _STLP_CALL __hex_char_table_lo()
   1.143 +{ return "0123456789abcdefx"; }
   1.144 +
   1.145 +_STLP_DECLSPEC const char* _STLP_CALL __hex_char_table_hi()
   1.146 +{ return "0123456789ABCDEFX"; }
   1.147 +
   1.148 +char* _STLP_CALL
   1.149 +__write_integer(char* buf, ios_base::fmtflags flags, long x) {
   1.150 +  char tmp[64];
   1.151 +  char* bufend = tmp+64;
   1.152 +  char* beg = __write_integer_backward(bufend, flags, x);
   1.153 +  return copy(beg, bufend, buf);
   1.154 +}
   1.155 +
   1.156 +///-------------------------------------
   1.157 +
   1.158 +_STLP_DECLSPEC ptrdiff_t _STLP_CALL
   1.159 +__insert_grouping(char * first, char * last, const string& grouping,
   1.160 +                  char separator, char Plus, char Minus, int basechars) {
   1.161 +  return __insert_grouping_aux(first, last, grouping,
   1.162 +                               separator, Plus, Minus, basechars);
   1.163 +}
   1.164 +
   1.165 +_STLP_DECLSPEC void _STLP_CALL
   1.166 +__insert_grouping(__iostring &str, size_t group_pos, const string& grouping,
   1.167 +                  char separator, char Plus, char Minus, int basechars) {
   1.168 +  __insert_grouping_aux(str, group_pos, grouping, separator, Plus, Minus, basechars);
   1.169 +}
   1.170 +
   1.171 +#if !defined (_STLP_NO_WCHAR_T)
   1.172 +_STLP_DECLSPEC ptrdiff_t _STLP_CALL
   1.173 +__insert_grouping(wchar_t* first, wchar_t* last, const string& grouping,
   1.174 +                  wchar_t separator, wchar_t Plus, wchar_t Minus,
   1.175 +                  int basechars) {
   1.176 +  return __insert_grouping_aux(first, last, grouping, separator,
   1.177 +                               Plus, Minus, basechars);
   1.178 +}
   1.179 +
   1.180 +_STLP_DECLSPEC void _STLP_CALL
   1.181 +__insert_grouping(__iowstring &str, size_t group_pos, const string& grouping,
   1.182 +                  wchar_t separator, wchar_t Plus, wchar_t Minus,
   1.183 +                  int basechars) {
   1.184 +  __insert_grouping_aux(str, group_pos, grouping, separator, Plus, Minus, basechars);
   1.185 +}
   1.186 +#endif
   1.187 +
   1.188 +_STLP_MOVE_TO_STD_NAMESPACE
   1.189 +
   1.190 +#if defined (__SYMBIAN32__WSD__)
   1.191 +template <>
   1.192 +_STLP_DECLSPEC locale::id& num_put<char, ostreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId()
   1.193 +    {
   1.194 +	return get_libcpp_wsd().num_put_char_ostreambuf_iterator_id;
   1.195 +    }
   1.196 +#  ifndef _STLP_NO_WCHAR_T
   1.197 +template <>
   1.198 +_STLP_DECLSPEC locale::id& num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::GetFacetLocaleId()
   1.199 +    {
   1.200 +	return get_libcpp_wsd().num_put_wchar_ostreambuf_iterator_id;
   1.201 +    }
   1.202 +#  endif /* _STLP_NO_WCHAR_T */
   1.203 +#endif /* __SYMBIAN32__WSD__ */
   1.204 +
   1.205 +//----------------------------------------------------------------------
   1.206 +// Force instantiation of num_put<>
   1.207 +#if !defined(_STLP_NO_FORCE_INSTANTIATE)
   1.208 +template class _STLP_CLASS_DECLSPEC ostreambuf_iterator<char, char_traits<char> >;
   1.209 +// template class num_put<char, char*>;
   1.210 +template class num_put<char, ostreambuf_iterator<char, char_traits<char> > >;
   1.211 +# ifndef _STLP_NO_WCHAR_T
   1.212 +template class ostreambuf_iterator<wchar_t, char_traits<wchar_t> >;
   1.213 +template class num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
   1.214 +// template class num_put<wchar_t, wchar_t*>;
   1.215 +# endif /* INSTANTIATE_WIDE_STREAMS */
   1.216 +#endif
   1.217 +
   1.218 +#if defined(__EPOC32__)
   1.219 +template <>
   1.220 +locale::id num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id={14};
   1.221 +
   1.222 +# if !defined (_STLP_NO_WCHAR_T)
   1.223 +template <>
   1.224 +locale::id num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id={33};
   1.225 +# endif
   1.226 +
   1.227 +#endif
   1.228 +
   1.229 +_STLP_END_NAMESPACE
   1.230 +
   1.231 +// Local Variables:
   1.232 +// mode:C++
   1.233 +// End: