summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/printfcommon.h
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2009-01-22 08:14:28 +0000
committerdas <das@FreeBSD.org>2009-01-22 08:14:28 +0000
commitdfcf434c32c40bc259ff09e2780abf613ec3e249 (patch)
treef31a330a971da42d6e17918ccbac552bcdf334f6 /lib/libc/stdio/printfcommon.h
parenta921977684453c89f9016fdcbb3b9fbd6a4a670f (diff)
downloadFreeBSD-src-dfcf434c32c40bc259ff09e2780abf613ec3e249.zip
FreeBSD-src-dfcf434c32c40bc259ff09e2780abf613ec3e249.tar.gz
Add support for multibyte thousands_sep encodings, e.g., U+066C.
The integer thousands' separator code is rewritten in order to avoid having to preallocate a buffer for the largest possible digit string with the most possible instances of the longest possible multibyte thousands' separator. The new version inserts thousands' separators for integers using the same code as floating point.
Diffstat (limited to 'lib/libc/stdio/printfcommon.h')
-rw-r--r--lib/libc/stdio/printfcommon.h55
1 files changed, 5 insertions, 50 deletions
diff --git a/lib/libc/stdio/printfcommon.h b/lib/libc/stdio/printfcommon.h
index ab49b31..39b0003 100644
--- a/lib/libc/stdio/printfcommon.h
+++ b/lib/libc/stdio/printfcommon.h
@@ -54,10 +54,8 @@ static int exponent(CHAR *, int, CHAR);
#endif /* !NO_FLOATING_POINT */
-static CHAR *__ujtoa(uintmax_t, CHAR *, int, int, const char *, int, char,
- const char *);
-static CHAR *__ultoa(u_long, CHAR *, int, int, const char *, int, char,
- const char *);
+static CHAR *__ujtoa(uintmax_t, CHAR *, int, int, const char *);
+static CHAR *__ultoa(u_long, CHAR *, int, int, const char *);
#define NIOV 8
struct io_state {
@@ -158,12 +156,10 @@ io_flush(struct io_state *iop)
* use the given digits.
*/
static CHAR *
-__ultoa(u_long val, CHAR *endp, int base, int octzero, const char *xdigs,
- int needgrp, char thousep, const char *grp)
+__ultoa(u_long val, CHAR *endp, int base, int octzero, const char *xdigs)
{
CHAR *cp = endp;
long sval;
- int ndig;
/*
* Handle the three cases separately, in the hope of getting
@@ -175,7 +171,6 @@ __ultoa(u_long val, CHAR *endp, int base, int octzero, const char *xdigs,
*--cp = to_char(val);
return (cp);
}
- ndig = 0;
/*
* On many machines, unsigned arithmetic is harder than
* signed arithmetic, so we do at most one unsigned mod and
@@ -184,29 +179,11 @@ __ultoa(u_long val, CHAR *endp, int base, int octzero, const char *xdigs,
*/
if (val > LONG_MAX) {
*--cp = to_char(val % 10);
- ndig++;
sval = val / 10;
} else
sval = val;
do {
*--cp = to_char(sval % 10);
- ndig++;
- /*
- * If (*grp == CHAR_MAX) then no more grouping
- * should be performed.
- */
- if (needgrp && ndig == *grp && *grp != CHAR_MAX
- && sval > 9) {
- *--cp = thousep;
- ndig = 0;
- /*
- * If (*(grp+1) == '\0') then we have to
- * use *grp character (last grouping rule)
- * for all next cases
- */
- if (*(grp+1) != '\0')
- grp++;
- }
sval /= 10;
} while (sval != 0);
break;
@@ -235,50 +212,28 @@ __ultoa(u_long val, CHAR *endp, int base, int octzero, const char *xdigs,
/* Identical to __ultoa, but for intmax_t. */
static CHAR *
-__ujtoa(uintmax_t val, CHAR *endp, int base, int octzero, const char *xdigs,
- int needgrp, char thousep, const char *grp)
+__ujtoa(uintmax_t val, CHAR *endp, int base, int octzero, const char *xdigs)
{
CHAR *cp = endp;
intmax_t sval;
- int ndig;
/* quick test for small values; __ultoa is typically much faster */
/* (perhaps instead we should run until small, then call __ultoa?) */
if (val <= ULONG_MAX)
- return (__ultoa((u_long)val, endp, base, octzero, xdigs,
- needgrp, thousep, grp));
+ return (__ultoa((u_long)val, endp, base, octzero, xdigs));
switch (base) {
case 10:
if (val < 10) {
*--cp = to_char(val % 10);
return (cp);
}
- ndig = 0;
if (val > INTMAX_MAX) {
*--cp = to_char(val % 10);
- ndig++;
sval = val / 10;
} else
sval = val;
do {
*--cp = to_char(sval % 10);
- ndig++;
- /*
- * If (*grp == CHAR_MAX) then no more grouping
- * should be performed.
- */
- if (needgrp && *grp != CHAR_MAX && ndig == *grp
- && sval > 9) {
- *--cp = thousep;
- ndig = 0;
- /*
- * If (*(grp+1) == '\0') then we have to
- * use *grp character (last grouping rule)
- * for all next cases
- */
- if (*(grp+1) != '\0')
- grp++;
- }
sval /= 10;
} while (sval != 0);
break;
OpenPOWER on IntegriCloud