/home/ntakagi/work/STLport-5.1.5/src/num_put.cppGo 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 str_size n = 0; // Index of the current group. 00048 Char* cur_group = last; // Points immediately beyond the rightmost 00049 // digit of the current group. 00050 int groupsize = 0; // Size of the current group. 00051 00052 for (;;) { 00053 groupsize = n < grouping.size() ? grouping[n] : groupsize; 00054 ++n; 00055 00056 if (groupsize <= 0 || groupsize >= cur_group - first) 00057 break; 00058 00059 // Insert a separator character just before position cur_group - groupsize 00060 cur_group -= groupsize; 00061 ++last; 00062 copy_backward(cur_group, last, last + 1); 00063 *cur_group = separator; 00064 } 00065 00066 return (last - first) + sign + basechars; 00067 } 00068 00069 //Dynamic output buffer version. 00070 template <class Char, class Str> 00071 static void 00072 __insert_grouping_aux( /* __basic_iostring<Char> */ Str& iostr, size_t __group_pos, 00073 const string& grouping, 00074 Char separator, Char Plus, Char Minus, 00075 int basechars) { 00076 typedef string::size_type str_size; 00077 00078 if (iostr.size() < __group_pos) 00079 return; 00080 00081 size_t __first_pos = 0; 00082 Char __first = *iostr.begin(); 00083 00084 if (__first == Plus || __first == Minus) { 00085 ++__first_pos; 00086 } 00087 00088 __first_pos += basechars; 00089 str_size n = 0; // Index of the current group. 00090 typename basic_string<Char>::iterator cur_group(iostr.begin() + __group_pos); // Points immediately beyond the rightmost 00091 // digit of the current group. 00092 unsigned int groupsize = 0; // Size of the current group. 00093 00094 for (;;) { 00095 groupsize = n < grouping.size() ? grouping[n] : groupsize; 00096 ++n; 00097 00098 if (groupsize <= 0 || groupsize >= ((cur_group - iostr.begin()) + __first_pos)) 00099 break; 00100 00101 // Insert a separator character just before position cur_group - groupsize 00102 cur_group -= groupsize; 00103 cur_group = iostr.insert(cur_group, separator); 00104 } 00105 } 00106 00107 //---------------------------------------------------------------------- 00108 // num_put 00109 00110 _STLP_MOVE_TO_PRIV_NAMESPACE 00111 00112 _STLP_DECLSPEC const char* _STLP_CALL __hex_char_table_lo() 00113 { return "0123456789abcdefx"; } 00114 00115 _STLP_DECLSPEC const char* _STLP_CALL __hex_char_table_hi() 00116 { return "0123456789ABCDEFX"; } 00117 00118 char* _STLP_CALL 00119 __write_integer(char* buf, ios_base::fmtflags flags, long x) { 00120 char tmp[64]; 00121 char* bufend = tmp+64; 00122 char* beg = __write_integer_backward(bufend, flags, x); 00123 return copy(beg, bufend, buf); 00124 } 00125 00127 00128 ptrdiff_t _STLP_CALL 00129 __insert_grouping(char * first, char * last, const string& grouping, 00130 char separator, char Plus, char Minus, int basechars) { 00131 return __insert_grouping_aux(first, last, grouping, 00132 separator, Plus, Minus, basechars); 00133 } 00134 00135 void _STLP_CALL 00136 __insert_grouping(__iostring &str, size_t group_pos, const string& grouping, 00137 char separator, char Plus, char Minus, int basechars) { 00138 __insert_grouping_aux(str, group_pos, grouping, separator, Plus, Minus, basechars); 00139 } 00140 00141 #if !defined (_STLP_NO_WCHAR_T) 00142 ptrdiff_t _STLP_CALL 00143 __insert_grouping(wchar_t* first, wchar_t* last, const string& grouping, 00144 wchar_t separator, wchar_t Plus, wchar_t Minus, 00145 int basechars) { 00146 return __insert_grouping_aux(first, last, grouping, separator, 00147 Plus, Minus, basechars); 00148 } 00149 00150 void _STLP_CALL 00151 __insert_grouping(__iowstring &str, size_t group_pos, const string& grouping, 00152 wchar_t separator, wchar_t Plus, wchar_t Minus, 00153 int basechars) { 00154 __insert_grouping_aux(str, group_pos, grouping, separator, Plus, Minus, basechars); 00155 } 00156 #endif 00157 00158 _STLP_MOVE_TO_STD_NAMESPACE 00159 00160 //---------------------------------------------------------------------- 00161 // Force instantiation of num_put<> 00162 #if !defined(_STLP_NO_FORCE_INSTANTIATE) 00163 template class _STLP_CLASS_DECLSPEC ostreambuf_iterator<char, char_traits<char> >; 00164 // template class num_put<char, char*>; 00165 template class num_put<char, ostreambuf_iterator<char, char_traits<char> > >; 00166 # ifndef _STLP_NO_WCHAR_T 00167 template class ostreambuf_iterator<wchar_t, char_traits<wchar_t> >; 00168 template class num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >; 00169 // template class num_put<wchar_t, wchar_t*>; 00170 # endif /* INSTANTIATE_WIDE_STREAMS */ 00171 #endif 00172 00173 _STLP_END_NAMESPACE 00174 00175 // Local Variables: 00176 // mode:C++ 00177 // End:
Generated on Mon Mar 10 15:32:17 2008 by ![]() |