From d4e18b8ea9e4ed40740ea3dccc72ad89ca6f2518 Mon Sep 17 00:00:00 2001 From: chip Date: Mon, 13 Nov 2006 22:35:43 +0000 Subject: [PATCH] Refine the Win32 sprintf("%e") kludge. But it's getting to the point where we may have to leave Win32 users to their own devices. git-svn-id: https://svn.parrot.org/parrot/trunk@15496 d31e2699-5ff4-0310-a27c-f18f2fbe73fe --- src/spf_render.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/spf_render.c b/src/spf_render.c index 40a1e520b7..95019d5051 100644 --- a/src/spf_render.c +++ b/src/spf_render.c @@ -700,18 +700,20 @@ Parrot_sprintf_format(Interp *interp, STRING *pat, } #ifdef WIN32 - /* Microsoft uses a retarded, broken, nonstandard - * behavior with regards to signs, exponents and - * precision: it doesn't count the + as part of the - * precision. We'll fix it ourselves if need be. + /* Microsoft defaults to three digits for exponents, + * even when fewer digits would suffice. For the sake + * of portability, we will here attempt to hide that. */ if (ch == 'g' || ch == 'G' || ch == 'e' || ch == 'E') { - UINTVAL j; - for (j=0; j < strlen(tc); j++) { - if(tolower(tc[j]) == 'e' - && (tc[j+1] == '+' || tc[j+1] == '-') - && tc[j+2] == '0') + size_t tclen = strlen(tc); + size_t j; + for (j = 0; j < tclen; j++) { + if ( (tc[j] == 'e' || tc[j] == 'E') + && (tc[j+1] == '+' || tc[j+1] == '-') + && tc[j+2] == '0' + && isdigit((unsigned char)tc[j+3]) + && isdigit((unsigned char)tc[j+4])) { mem_sys_memmove(&tc[j+2], &tc[j+3], strlen(&tc[j+2])); @@ -724,6 +726,9 @@ Parrot_sprintf_format(Interp *interp, STRING *pat, tc[0] = ' '; } } + + /* only one fix required per string */ + break; } } }