12 #include "cln/integer_io.h"
18 void format_integer (std::ostream& stream, const cl_I& arg,
19 unsigned int base, sintL mincol, char padchar,
20 char commachar, uintL commainterval, bool commaflag,
21 bool positive_sign_flag)
23 if ((mincol == 0) && !commaflag && !positive_sign_flag) {
24 // Normale Ausgabe tut's.
25 print_integer(stream,base,arg);
28 var char* oldstring = print_integer_to_string(base,arg);
29 var uintL oldstring_length = ::strlen(oldstring);
30 var uintL number_of_digits = (minusp(arg) ? oldstring_length-1 : oldstring_length);
31 var uintL number_of_commas = (commaflag ? floor(number_of_digits-1,commainterval) : 0);
32 var bool positive_sign = positive_sign_flag && (arg > 0);
33 var uintL newstring_length = (positive_sign ? 1 : 0) + oldstring_length + number_of_commas;
34 var char* newstring = (char *) malloc_hook(newstring_length+1);
35 newstring[newstring_length] = '\0'; // newstring termination
41 // Dann oldstring in newstring übertragen, dabei Kommata überspringen:
42 var uintL oldpos = oldstring_length;
43 var uintL oldpos_mod = 0; // = (oldstring_length - oldpos) % commainterval
44 var uintL newpos = newstring_length;
46 newstring[--newpos] = oldstring[--oldpos];
47 if (number_of_commas > 0) {
48 // Check whether ((oldstring_length - oldpos) % commainterval) == 0
49 if (++oldpos_mod == commainterval) {
51 // noch ein Komma einzufügen
52 newstring[--newpos] = commachar;
59 format_padded_string(stream,mincol,1,0,padchar,true,newstring);
60 #else // expand this special case of format_padded_string inline:
61 if ((sintL)newstring_length < mincol)
62 format_padding(stream,mincol-newstring_length,padchar);
63 fprint(stream,newstring);