Commit 05a2c566 authored by Damjan Jovanovic's avatar Damjan Jovanovic Committed by Alexandre Julliard

oleaut32: Fix negative number handling in VarFormat.

parent b8b3a7d8
......@@ -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 */
......
/*
* 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,6 +1527,7 @@ VARIANT_FormatNumber_Bool:
*pBuff++ = defaultChar;
}
}
if (shouldAdvance)
pToken++;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment