[18190] | 1 | /* __gmp_doprnt_integer_ios -- integer formatted output to an ostream. |
---|
| 2 | |
---|
| 3 | THE FUNCTIONS IN THIS FILE ARE FOR INTERNAL USE ONLY. THEY'RE ALMOST |
---|
| 4 | CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR DISAPPEAR COMPLETELY IN |
---|
| 5 | FUTURE GNU MP RELEASES. |
---|
| 6 | |
---|
| 7 | Copyright 2001 Free Software Foundation, Inc. |
---|
| 8 | |
---|
| 9 | This file is part of the GNU MP Library. |
---|
| 10 | |
---|
| 11 | The GNU MP Library is free software; you can redistribute it and/or modify |
---|
| 12 | it under the terms of the GNU Lesser General Public License as published by |
---|
| 13 | the Free Software Foundation; either version 2.1 of the License, or (at your |
---|
| 14 | option) any later version. |
---|
| 15 | |
---|
| 16 | The GNU MP Library is distributed in the hope that it will be useful, but |
---|
| 17 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
---|
| 18 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
---|
| 19 | License for more details. |
---|
| 20 | |
---|
| 21 | You should have received a copy of the GNU Lesser General Public License |
---|
| 22 | along with the GNU MP Library; see the file COPYING.LIB. If not, write to |
---|
| 23 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
---|
| 24 | MA 02111-1307, USA. */ |
---|
| 25 | |
---|
| 26 | #include <iostream> |
---|
| 27 | #include <stdarg.h> /* for va_list and hence doprnt_funs_t */ |
---|
| 28 | #include <string.h> |
---|
| 29 | |
---|
| 30 | #include "gmp.h" |
---|
| 31 | #include "gmp-impl.h" |
---|
| 32 | |
---|
| 33 | #include <stdio.h> |
---|
| 34 | |
---|
| 35 | using namespace std; |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | /* The gmp_asprintf support routines never give an error, so |
---|
| 39 | __gmp_doprnt_integer shouldn't fail and it's return can just be checked |
---|
| 40 | with an ASSERT. */ |
---|
| 41 | |
---|
| 42 | ostream& |
---|
| 43 | __gmp_doprnt_integer_ostream (ostream &o, struct doprnt_params_t *p, |
---|
| 44 | char *s) |
---|
| 45 | { |
---|
| 46 | struct gmp_asprintf_t d; |
---|
| 47 | char *result; |
---|
| 48 | int ret; |
---|
| 49 | |
---|
| 50 | /* don't show leading zeros the way printf does */ |
---|
| 51 | p->prec = -1; |
---|
| 52 | |
---|
| 53 | GMP_ASPRINTF_T_INIT (d, &result); |
---|
| 54 | ret = __gmp_doprnt_integer (&__gmp_asprintf_funs_noformat, &d, p, s); |
---|
| 55 | ASSERT (ret != -1); |
---|
| 56 | __gmp_asprintf_final (&d); |
---|
| 57 | (*__gmp_free_func) (s, strlen(s)+1); |
---|
| 58 | |
---|
| 59 | gmp_allocated_string alloc = result; |
---|
| 60 | return o.write (result, strlen (result)); |
---|
| 61 | } |
---|