Damjan Jovanovic : oleaut32: Fix negative number handling in VarFormat.
Alexandre Julliard
julliard at winehq.org
Mon Aug 25 06:21:40 CDT 2008
Module: wine
Branch: master
Commit: 05a2c566223c9d723d84c4bc5abc910c331c9da6
URL: http://source.winehq.org/git/wine.git/?a=commit;h=05a2c566223c9d723d84c4bc5abc910c331c9da6
Author: Damjan Jovanovic <damjan.jov at gmail.com>
Date: Fri Aug 22 12:37:57 2008 +0200
oleaut32: Fix negative number handling in VarFormat.
---
dlls/oleaut32/tests/varformat.c | 4 ++--
dlls/oleaut32/varformat.c | 26 +++++++++++++++++++++++++-
2 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/dlls/oleaut32/tests/varformat.c b/dlls/oleaut32/tests/varformat.c
index 2895408..4098927 100644
--- a/dlls/oleaut32/tests/varformat.c
+++ b/dlls/oleaut32/tests/varformat.c
@@ -369,9 +369,9 @@ static void test_VarFormat(void)
VARFMT(VT_R8,V_R8,47.11,".0000E+0",S_OK,".4711E+2");
VARFMT(VT_R8,V_R8,3.0401e-13,"#####.####e-0%",S_OK,"30401.e-15%");
VARFMT(VT_R8,V_R8,1.57,"0.00",S_OK,"1.57");
- todo_wine {
VARFMT(VT_R8,V_R8,-1.57,"0.00",S_OK,"-1.57");
- }
+ VARFMT(VT_R8,V_R8,-1.57,"#.##",S_OK,"-1.57");
+ VARFMT(VT_R8,V_R8,-0.1,".#",S_OK,"-.1");
/* 'out' is not cleared */
diff --git a/dlls/oleaut32/varformat.c b/dlls/oleaut32/varformat.c
index 83f075f..887525c 100644
--- a/dlls/oleaut32/varformat.c
+++ b/dlls/oleaut32/varformat.c
@@ -1,6 +1,7 @@
/*
* Variant formatting functions
*
+ * Copyright 2008 Damjan Jovanovic
* Copyright 2003 Jon Griffiths
*
* This library is free software; you can redistribute it and/or
@@ -1181,6 +1182,7 @@ HRESULT WINAPI VarTokenizeFormatString(LPOLESTR lpszFormat, LPBYTE rgbTok,
/* Number formatting state flags */
#define NUM_WROTE_DEC 0x01 /* Written the decimal separator */
#define NUM_WRITE_ON 0x02 /* Started to write the number */
+#define NUM_WROTE_SIGN 0x04 /* Written the negative sign */
/* Format a variant using a number format */
static HRESULT VARIANT_FormatNumber(LPVARIANT pVarIn, LPOLESTR lpszFormat,
@@ -1320,6 +1322,7 @@ static HRESULT VARIANT_FormatNumber(LPVARIANT pVarIn, LPOLESTR lpszFormat,
{
WCHAR defaultChar = '?';
DWORD boolFlag, localeValue = 0;
+ BOOL shouldAdvance = TRUE;
if (pToken - rgbTok > header->size)
{
@@ -1377,6 +1380,16 @@ VARIANT_FormatNumber_Bool:
break;
case FMT_NUM_DECIMAL:
+ if ((np.dwOutFlags & NUMPRS_NEG) && !(dwState & NUM_WROTE_SIGN))
+ {
+ /* last chance for a negative sign in the .# case */
+ TRACE("write negative sign\n");
+ localeValue = LOCALE_SNEGATIVESIGN;
+ defaultChar = '-';
+ dwState |= NUM_WROTE_SIGN;
+ shouldAdvance = FALSE;
+ break;
+ }
TRACE("write decimal separator\n");
localeValue = LOCALE_SDECIMAL;
defaultChar = '.';
@@ -1452,6 +1465,16 @@ VARIANT_FormatNumber_Bool:
{
int count, count_max;
+ if ((np.dwOutFlags & NUMPRS_NEG) && !(dwState & NUM_WROTE_SIGN))
+ {
+ TRACE("write negative sign\n");
+ localeValue = LOCALE_SNEGATIVESIGN;
+ defaultChar = '-';
+ dwState |= NUM_WROTE_SIGN;
+ shouldAdvance = FALSE;
+ break;
+ }
+
need_int -= pToken[1];
count_max = have_int + pad - need_int;
if (count_max < 0)
@@ -1504,7 +1527,8 @@ VARIANT_FormatNumber_Bool:
*pBuff++ = defaultChar;
}
}
- pToken++;
+ if (shouldAdvance)
+ pToken++;
}
VARIANT_FormatNumber_Exit:
More information about the wine-cvs
mailing list