ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

num_put.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1999
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Copyright (c) 1999
00006  * Boris Fomitchev
00007  *
00008  * This material is provided "as is", with absolutely no warranty expressed
00009  * or implied. Any use is at your own risk.
00010  *
00011  * Permission to use or copy this software for any purpose is hereby granted
00012  * without fee, provided the above notices are retained on all copies.
00013  * Permission to modify the code and to distribute modified code is granted,
00014  * provided the above notices are retained, and a notice that the code was
00015  * modified is included with the above copyright notice.
00016  *
00017  */
00018 
00019 #include "stlport_prefix.h"
00020 
00021 #include <locale>
00022 #include <ostream>
00023 
00024 _STLP_BEGIN_NAMESPACE
00025 
00026 // Note that grouping[0] is the number of digits in the *rightmost* group.
00027 // We assume, without checking, that *last is null and that there is enough
00028 // space in the buffer to extend the number past [first, last).
00029 template <class Char>
00030 static ptrdiff_t
00031 __insert_grouping_aux(Char* first, Char* last, const string& grouping,
00032                       Char separator, Char Plus, Char Minus,
00033                       int basechars) {
00034   typedef string::size_type str_size;
00035 
00036   if (first == last)
00037     return 0;
00038 
00039   int sign = 0;
00040 
00041   if (*first == Plus || *first == Minus) {
00042     sign = 1;
00043     ++first;
00044   }
00045 
00046   first += basechars;
00047   Char* cur_group = last; // Points immediately beyond the rightmost
00048                           // digit of the current group.
00049   int groupsize = 0; // Size of the current group (if grouping.size() == 0, size
00050                      // of group unlimited: we force condition (groupsize <= 0))
00051 
00052   for ( str_size n = 0; ; ) { // Index of the current group
00053     if ( n < grouping.size() ) {
00054       groupsize = __STATIC_CAST(int, grouping[n++] );
00055     }
00056 
00057     if ((groupsize <= 0) || (groupsize >= cur_group - first) || (groupsize == CHAR_MAX)) {
00058       break;
00059     }
00060 
00061     // Insert a separator character just before position cur_group - groupsize
00062     cur_group -= groupsize;
00063     ++last;
00064     copy_backward(cur_group, last, last + 1);
00065     *cur_group = separator;
00066   }
00067 
00068   return (last - first) + sign + basechars;
00069 }
00070 
00071 //Dynamic output buffer version.
00072 template <class Char, class Str>
00073 static void
00074 __insert_grouping_aux( /* __basic_iostring<Char> */ Str& iostr, size_t __group_pos,
00075                       const string& grouping,
00076                       Char separator, Char Plus, Char Minus,
00077                       int basechars) {
00078   typedef string::size_type str_size;
00079 
00080   if (iostr.size() < __group_pos)
00081     return;
00082 
00083   int __first_pos = 0;
00084   Char __first = *iostr.begin();
00085 
00086   if (__first == Plus || __first == Minus) {
00087     ++__first_pos;
00088   }
00089 
00090   __first_pos += basechars;
00091 
00092   typename Str::iterator cur_group(iostr.begin() + __group_pos);    // Points immediately beyond the rightmost
00093                                                                     // digit of the current group.
00094   int groupsize = 0; // Size of the current group (if grouping.size() == 0, size
00095                      // of group unlimited: we force condition (groupsize <= 0))
00096 
00097   for ( str_size n = 0; ; ) { // Index of the current group
00098     if ( n < grouping.size() ) {
00099       groupsize = __STATIC_CAST( int, grouping[n++] );
00100     }
00101 
00102     if ( (groupsize <= 0) || (groupsize >= ((cur_group - iostr.begin()) - __first_pos)) ||
00103          (groupsize == CHAR_MAX)) {
00104       break;
00105     }
00106 
00107     // Insert a separator character just before position cur_group - groupsize
00108     cur_group -= groupsize;
00109     cur_group = iostr.insert(cur_group, separator);
00110   }
00111 }
00112 
00113 //----------------------------------------------------------------------
00114 // num_put
00115 
00116 _STLP_MOVE_TO_PRIV_NAMESPACE
00117 
00118 _STLP_DECLSPEC const char* _STLP_CALL __hex_char_table_lo()
00119 { return "0123456789abcdefx"; }
00120 
00121 _STLP_DECLSPEC const char* _STLP_CALL __hex_char_table_hi()
00122 { return "0123456789ABCDEFX"; }
00123 
00124 char* _STLP_CALL
00125 __write_integer(char* buf, ios_base::fmtflags flags, long x) {
00126   char tmp[64];
00127   char* bufend = tmp+64;
00128   char* beg = __write_integer_backward(bufend, flags, x);
00129   return copy(beg, bufend, buf);
00130 }
00131 
00133 
00134 ptrdiff_t _STLP_CALL
00135 __insert_grouping(char * first, char * last, const string& grouping,
00136                   char separator, char Plus, char Minus, int basechars) {
00137   return __insert_grouping_aux(first, last, grouping,
00138                                separator, Plus, Minus, basechars);
00139 }
00140 
00141 void _STLP_CALL
00142 __insert_grouping(__iostring &str, size_t group_pos, const string& grouping,
00143                   char separator, char Plus, char Minus, int basechars) {
00144   __insert_grouping_aux(str, group_pos, grouping, separator, Plus, Minus, basechars);
00145 }
00146 
00147 #if !defined (_STLP_NO_WCHAR_T)
00148 ptrdiff_t _STLP_CALL
00149 __insert_grouping(wchar_t* first, wchar_t* last, const string& grouping,
00150                   wchar_t separator, wchar_t Plus, wchar_t Minus,
00151                   int basechars) {
00152   return __insert_grouping_aux(first, last, grouping, separator,
00153                                Plus, Minus, basechars);
00154 }
00155 
00156 void _STLP_CALL
00157 __insert_grouping(__iowstring &str, size_t group_pos, const string& grouping,
00158                   wchar_t separator, wchar_t Plus, wchar_t Minus,
00159                   int basechars) {
00160   __insert_grouping_aux(str, group_pos, grouping, separator, Plus, Minus, basechars);
00161 }
00162 #endif
00163 
00164 _STLP_MOVE_TO_STD_NAMESPACE
00165 
00166 //----------------------------------------------------------------------
00167 // Force instantiation of num_put<>
00168 #if !defined(_STLP_NO_FORCE_INSTANTIATE)
00169 template class _STLP_CLASS_DECLSPEC ostreambuf_iterator<char, char_traits<char> >;
00170 // template class num_put<char, char*>;
00171 template class num_put<char, ostreambuf_iterator<char, char_traits<char> > >;
00172 # ifndef _STLP_NO_WCHAR_T
00173 template class ostreambuf_iterator<wchar_t, char_traits<wchar_t> >;
00174 template class num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
00175 // template class num_put<wchar_t, wchar_t*>;
00176 # endif /* INSTANTIATE_WIDE_STREAMS */
00177 #endif
00178 
00179 _STLP_END_NAMESPACE
00180 
00181 // Local Variables:
00182 // mode:C++
00183 // End:

Generated on Sun May 27 2012 04:35:13 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.