Austin Schuh | bb1338c | 2024-06-15 19:31:16 -0700 | [diff] [blame^] | 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 either: |
| 13 | |
| 14 | * the GNU Lesser General Public License as published by the Free |
| 15 | Software Foundation; either version 3 of the License, or (at your |
| 16 | option) any later version. |
| 17 | |
| 18 | or |
| 19 | |
| 20 | * the GNU General Public License as published by the Free Software |
| 21 | Foundation; either version 2 of the License, or (at your option) any |
| 22 | later version. |
| 23 | |
| 24 | or both in parallel, as here. |
| 25 | |
| 26 | The GNU MP Library is distributed in the hope that it will be useful, but |
| 27 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 28 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 29 | for more details. |
| 30 | |
| 31 | You should have received copies of the GNU General Public License and the |
| 32 | GNU Lesser General Public License along with the GNU MP Library. If not, |
| 33 | see https://www.gnu.org/licenses/. */ |
| 34 | |
| 35 | #include <iostream> |
| 36 | #include <stdarg.h> /* for va_list and hence doprnt_funs_t */ |
| 37 | #include <string.h> /* for strlen */ |
| 38 | |
| 39 | #include "gmp-impl.h" |
| 40 | |
| 41 | using namespace std; |
| 42 | |
| 43 | |
| 44 | /* The gmp_asprintf support routines never give an error, so |
| 45 | __gmp_doprnt_integer shouldn't fail and it's return can just be checked |
| 46 | with an ASSERT. */ |
| 47 | |
| 48 | ostream& |
| 49 | __gmp_doprnt_integer_ostream (ostream &o, struct doprnt_params_t *p, |
| 50 | char *s) |
| 51 | { |
| 52 | struct gmp_asprintf_t d; |
| 53 | char *result; |
| 54 | int ret; |
| 55 | |
| 56 | /* don't show leading zeros the way printf does */ |
| 57 | p->prec = -1; |
| 58 | |
| 59 | GMP_ASPRINTF_T_INIT (d, &result); |
| 60 | ret = __gmp_doprnt_integer (&__gmp_asprintf_funs_noformat, &d, p, s); |
| 61 | ASSERT (ret != -1); |
| 62 | __gmp_asprintf_final (&d); |
| 63 | (*__gmp_free_func) (s, strlen(s)+1); |
| 64 | |
| 65 | gmp_allocated_string t (result); |
| 66 | return o.write (t.str, t.len); |
| 67 | } |