|
1 /* |
|
2 * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved. |
|
3 * |
|
4 * Copyright (c) 1999 |
|
5 * Silicon Graphics Computer Systems, Inc. |
|
6 * |
|
7 * Copyright (c) 1999 |
|
8 * Boris Fomitchev |
|
9 * |
|
10 * This material is provided "as is", with absolutely no warranty expressed |
|
11 * or implied. Any use is at your own risk. |
|
12 * |
|
13 * Permission to use or copy this software for any purpose is hereby granted |
|
14 * without fee, provided the above notices are retained on all copies. |
|
15 * Permission to modify the code and to distribute modified code is granted, |
|
16 * provided the above notices are retained, and a notice that the code was |
|
17 * modified is included with the above copyright notice. |
|
18 * |
|
19 */ |
|
20 |
|
21 # ifndef _STLP_NUM_PUT_H |
|
22 # define _STLP_NUM_PUT_H |
|
23 |
|
24 #ifndef _STLP_INTERNAL_NUM_PUT_H |
|
25 #include <stl/_num_put.h> |
|
26 #endif |
|
27 #ifndef _STLP_INTERNAL_OSTREAM_H |
|
28 #include <stl/_ostream.h> |
|
29 #endif |
|
30 |
|
31 _STLP_BEGIN_NAMESPACE |
|
32 |
|
33 // Note that grouping[0] is the number of digits in the *rightmost* group. |
|
34 // We assume, without checking, that *last is null and that there is enough |
|
35 // space in the buffer to extend the number past [first, last). |
|
36 template <class Char> |
|
37 ptrdiff_t |
|
38 __insert_grouping_aux(Char* first, Char* last, const string& grouping, |
|
39 Char separator, Char Plus, Char Minus, |
|
40 int basechars) |
|
41 { |
|
42 typedef string::size_type str_size; |
|
43 |
|
44 if (first == last) |
|
45 return 0; |
|
46 |
|
47 int sign = 0; |
|
48 |
|
49 if (*first == Plus || *first == Minus) { |
|
50 sign = 1; |
|
51 ++first; |
|
52 } |
|
53 |
|
54 first += basechars; |
|
55 str_size n = 0; // Index of the current group. |
|
56 Char* cur_group = last; // Points immediately beyond the rightmost |
|
57 // digit of the current group. |
|
58 int groupsize = 0; // Size of the current group. |
|
59 |
|
60 while (true) { |
|
61 //groupsize = n < grouping.size() ? grouping[n]-48 : groupsize; |
|
62 groupsize = n < grouping.size() ? grouping[n] : groupsize; |
|
63 ++n; |
|
64 |
|
65 if (groupsize <= 0 || groupsize >= cur_group - first) |
|
66 break; |
|
67 |
|
68 // Insert a separator character just before position cur_group - groupsize |
|
69 cur_group -= groupsize; |
|
70 ++last; |
|
71 copy_backward(cur_group, last, last + 1); |
|
72 *cur_group = separator; |
|
73 } |
|
74 |
|
75 return (last - first) + sign + basechars; |
|
76 } |
|
77 |
|
78 _STLP_END_NAMESPACE |
|
79 |
|
80 # endif |