num_put.h

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 # ifndef _STLP_NUM_PUT_H
00020 #  define _STLP_NUM_PUT_H
00021 
00022 #ifndef _STLP_INTERNAL_NUM_PUT_H
00023 #include <stl/_num_put.h>
00024 #endif
00025 #ifndef _STLP_INTERNAL_OSTREAM_H
00026 #include <stl/_ostream.h>
00027 #endif
00028 
00029 _STLP_BEGIN_NAMESPACE
00030 
00031 // Note that grouping[0] is the number of digits in the *rightmost* group.
00032 // We assume, without checking, that *last is null and that there is enough
00033 // space in the buffer to extend the number past [first, last).
00034 template <class Char>
00035 ptrdiff_t 
00036 __insert_grouping_aux(Char* first, Char* last, const string& grouping,
00037                       Char separator, Char Plus, Char Minus,
00038                       int basechars)
00039 {
00040   typedef string::size_type str_size;
00041 
00042   if (first == last)
00043     return 0;
00044 
00045   int sign = 0;
00046 
00047   if (*first == Plus || *first == Minus) {
00048     sign = 1;
00049     ++first;
00050   }
00051  
00052   first += basechars;
00053   str_size n = 0;               // Index of the current group.
00054   Char* cur_group = last;       // Points immediately beyond the rightmost
00055                                 // digit of the current group.
00056   int groupsize = 0;            // Size of the current group.
00057   
00058   while (true) {
00059     groupsize = n < grouping.size() ? grouping[n] : groupsize;
00060     ++n;
00061 
00062     if (groupsize <= 0 || groupsize >= cur_group - first)
00063       break;
00064 
00065     // Insert a separator character just before position cur_group - groupsize
00066     cur_group -= groupsize;
00067     ++last;
00068     copy_backward(cur_group, last, last + 1);
00069     *cur_group = separator;
00070   }
00071 
00072   return (last - first) + sign + basechars;
00073 }
00074 
00075 _STLP_END_NAMESPACE
00076 
00077 # endif

Generated on Mon Jun 5 10:20:45 2006 for Intelligence.kdevelop by  doxygen 1.4.6