12 #include "cl_integer_io.h"
16 void format_integer (cl_ostream stream, const cl_I& arg,
17 unsigned int base, sintL mincol, char padchar,
18 char commachar, uintL commainterval, cl_boolean commaflag,
19 cl_boolean positive_sign_flag)
21 if ((mincol == 0) && !commaflag && !positive_sign_flag) {
22 // Normale Ausgabe tut's.
23 print_integer(stream,base,arg);
26 var char* oldstring = print_integer_to_string(base,arg);
27 var uintL oldstring_length = strlen(oldstring);
28 var uintL number_of_digits = (minusp(arg) ? oldstring_length-1 : oldstring_length);
29 var uintL number_of_commas = (commaflag ? floor(number_of_digits-1,commainterval) : 0);
30 var cl_boolean positive_sign = (cl_boolean) (positive_sign_flag && (arg > 0));
31 var uintL newstring_length = (positive_sign ? 1 : 0) + oldstring_length + number_of_commas;
32 var char* newstring = (char *) cl_malloc_hook(newstring_length+1);
33 newstring[newstring_length] = '\0'; // newstring termination
39 // Dann oldstring in newstring übertragen, dabei Kommata überspringen:
40 var uintL oldpos = oldstring_length;
41 var uintL oldpos_mod = 0; // = (oldstring_length - oldpos) % commainterval
42 var uintL newpos = newstring_length;
44 newstring[--newpos] = oldstring[--oldpos];
45 if (number_of_commas > 0) {
46 // Check whether ((oldstring_length - oldpos) % commainterval) == 0
47 if (++oldpos_mod == commainterval) {
49 // noch ein Komma einzufügen
50 newstring[--newpos] = commachar;
57 format_padded_string(stream,mincol,1,0,padchar,cl_true,newstring);
58 #else // expand this special case of format_padded_string inline:
59 if ((sintL)newstring_length < mincol)
60 format_padding(stream,mincol-newstring_length,padchar);
61 fprint(stream,newstring);
63 cl_free_hook(newstring);
64 cl_free_hook(oldstring);