build/stlport/src/num_put.cpp

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

mercurial