Ignore:
Timestamp:
Sep 3, 2000, 8:05:40 PM (25 years ago)
Author:
phaller
Message:

WINE NLS sync

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/heapstring.cpp

    r3976 r4174  
    1 /* $Id: heapstring.cpp,v 1.31 2000-08-10 02:19:57 phaller Exp $ */
     1/* $Id: heapstring.cpp,v 1.32 2000-09-03 18:04:56 phaller Exp $ */
    22
    33/*
     
    11891189    return nData;
    11901190}
    1191 
    1192 
    1193 /*****************************************************************************
    1194  * Name      : GetNumberFormat
    1195  * Purpose   : format a given number string according to local settings
    1196  * Parameters:
    1197  * Variables :
    1198  * Result    :
    1199  * Remark    : KERNEL32.355
    1200  * Status    :
    1201  *
    1202  * Author    : Patrick Haller [Sun, 2000/06/12 12:46]
    1203  *****************************************************************************/
    1204 
    1205 
    1206 ODINFUNCTION6(INT,               GetNumberFormatA,
    1207               LCID,              locale,
    1208               DWORD,             dwflags,
    1209               LPCSTR,            lpvalue,
    1210               CONST NUMBERFMTA *,lpFormat,
    1211               LPSTR,             lpNumberStr,
    1212               int,               cchNumber)
    1213 {
    1214   dprintf(("not properly implemented.\n"));
    1215  
    1216   char   sNumberDigits[3], sDecimalSymbol[5], sDigitsInGroup[11], sDigitGroupSymbol[5], sILZero[2];
    1217   INT    nNumberDigits, nNumberDecimal, i, j, nCounter, nStep, nRuleIndex, nGrouping, nDigits, retVal, nLZ;
    1218   char   sNumber[128], sDestination[128], sDigitsAfterDecimal[10], sDigitsBeforeDecimal[128];
    1219   char   sRule[10], sSemiColumn[]=";", sBuffer[5], sNegNumber[2];
    1220   char   *pStr = NULL, *pTmpStr = NULL;
    1221   LCID   systemDefaultLCID;
    1222   BOOL   bNegative = FALSE;
    1223   enum   Operations
    1224   {
    1225     USE_PARAMETER,
    1226     USE_LOCALEINFO,
    1227     USE_SYSTEMDEFAULT,
    1228     RETURN_ERROR
    1229   } used_operation;
    1230 
    1231   strncpy(sNumber, lpvalue, 128);
    1232   sNumber[127] = '\0';
    1233 
    1234   /* Make sure we have a valid input string, get the number
    1235    * of digits before and after the decimal symbol, and check
    1236    * if this is a negative number.
    1237    */
    1238   if ( OLE_GetNumberComponents(sNumber, sDigitsBeforeDecimal, sDigitsAfterDecimal, &bNegative) != -1)
    1239   {
    1240     nNumberDecimal = strlen(sDigitsBeforeDecimal);
    1241     nDigits = strlen(sDigitsAfterDecimal);
    1242   }
    1243   else
    1244   {
    1245     SetLastError(ERROR_INVALID_PARAMETER);
    1246     return 0;
    1247   }
    1248 
    1249   /* Which source will we use to format the string */
    1250   used_operation = RETURN_ERROR;
    1251   if (lpFormat != NULL)
    1252   {
    1253     if (dwflags == 0)
    1254       used_operation = USE_PARAMETER;
    1255   }
    1256   else
    1257   {
    1258     if (dwflags & LOCALE_NOUSEROVERRIDE)
    1259       used_operation = USE_LOCALEINFO;
    1260     else
    1261       used_operation = USE_SYSTEMDEFAULT;
    1262   }
    1263 
    1264   /* Load the fields we need */
    1265   switch(used_operation)
    1266   {
    1267     case USE_LOCALEINFO:
    1268         GetLocaleInfoA(locale, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
    1269         GetLocaleInfoA(locale, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
    1270         GetLocaleInfoA(locale, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
    1271         GetLocaleInfoA(locale, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
    1272         GetLocaleInfoA(locale, LOCALE_ILZERO, sILZero, sizeof(sILZero));
    1273         GetLocaleInfoA(locale, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
    1274         break;
    1275     case USE_PARAMETER:
    1276         sprintf(sNumberDigits, "%d",lpFormat->NumDigits);
    1277         strcpy(sDecimalSymbol, lpFormat->lpDecimalSep);
    1278         sprintf(sDigitsInGroup, "%d;0",lpFormat->Grouping);
    1279         strcpy(sDigitGroupSymbol, lpFormat->lpThousandSep);
    1280         sprintf(sILZero, "%d",lpFormat->LeadingZero);
    1281         sprintf(sNegNumber, "%d",lpFormat->NegativeOrder);
    1282         break;
    1283     case USE_SYSTEMDEFAULT:
    1284         systemDefaultLCID = GetSystemDefaultLCID();
    1285         GetLocaleInfoA(systemDefaultLCID, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
    1286         GetLocaleInfoA(systemDefaultLCID, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
    1287         GetLocaleInfoA(systemDefaultLCID, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
    1288         GetLocaleInfoA(systemDefaultLCID, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
    1289         GetLocaleInfoA(systemDefaultLCID, LOCALE_ILZERO, sILZero, sizeof(sILZero));
    1290         GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
    1291         break;
    1292     default:
    1293         SetLastError(ERROR_INVALID_PARAMETER);
    1294         return 0;
    1295     }
    1296 
    1297     nNumberDigits = atoi(sNumberDigits);
    1298    
    1299     /* Remove the ";" */
    1300     i=0;
    1301     j = 1;
    1302     for (nCounter=0; nCounter<strlen(sDigitsInGroup); nCounter++)
    1303     {
    1304         if ( memcmp(sDigitsInGroup + nCounter, sSemiColumn, 1) != 0 )
    1305         {
    1306             memcpy(sRule + j, sDigitsInGroup + nCounter, 1);
    1307             i++;
    1308             j++;
    1309         }
    1310     }
    1311     sprintf(sBuffer, "%d", i);
    1312     memcpy(sRule, sBuffer, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
    1313     memcpy(sRule + j, "\0", 1);
    1314    
    1315     /* First, format the digits before the decimal. */
    1316     if ((nNumberDecimal>0) && (atoi(sDigitsBeforeDecimal) != 0))
    1317     {
    1318         /* Working on an inverted string is easier ! */
    1319         OLE_InvertString(sDigitsBeforeDecimal);
    1320 
    1321         nStep = nCounter = i = j = 0;
    1322         nRuleIndex = 1;
    1323         nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
    1324        
    1325         /* Here, we will loop until we reach the end of the string.
    1326          * An internal counter (j) is used in order to know when to
    1327          * insert the "digit group symbol".
    1328          */
    1329         while (nNumberDecimal > 0)
    1330         {
    1331             i = nCounter + nStep;
    1332             memcpy(sDestination + i, sDigitsBeforeDecimal + nCounter, 1);
    1333             nCounter++;
    1334             j++;
    1335             if (j >= nGrouping)
    1336             {
    1337                 j = 0;
    1338                 if (nRuleIndex < sRule[0])
    1339                     nRuleIndex++;
    1340                 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
    1341                 memcpy(sDestination + i+1, sDigitGroupSymbol, strlen(sDigitGroupSymbol));
    1342                 nStep+= strlen(sDigitGroupSymbol);
    1343             }
    1344 
    1345             nNumberDecimal--;
    1346         }
    1347 
    1348         memcpy(sDestination + i+1, "\0", 1);
    1349         /* Get the string in the right order ! */
    1350         OLE_InvertString(sDestination);
    1351      }
    1352      else
    1353      {
    1354         nLZ = atoi(sILZero);
    1355         if (nLZ != 0)
    1356         {       
    1357             /* Use 0.xxx instead of .xxx */
    1358             memcpy(sDestination, "0", 1);
    1359             memcpy(sDestination+1, "\0", 1);
    1360         }
    1361         else
    1362             memcpy(sDestination, "\0", 1);
    1363 
    1364      }
    1365 
    1366     /* Second, format the digits after the decimal. */
    1367     j = 0;
    1368     nCounter = nNumberDigits;
    1369     if ( (nDigits>0) && (pStr = strstr (sNumber, ".")) )
    1370     {
    1371         i = strlen(sNumber) - strlen(pStr) + 1;       
    1372         strncpy ( sDigitsAfterDecimal, sNumber + i, nNumberDigits);
    1373         j = strlen(sDigitsAfterDecimal);
    1374         if (j < nNumberDigits)
    1375             nCounter = nNumberDigits-j;           
    1376     }
    1377     for (i=0;i<nCounter;i++)
    1378          memcpy(sDigitsAfterDecimal+i+j, "0", 1);   
    1379     memcpy(sDigitsAfterDecimal + nNumberDigits, "\0", 1);   
    1380 
    1381     i = strlen(sDestination);
    1382     j = strlen(sDigitsAfterDecimal);
    1383     /* Finally, construct the resulting formatted string. */
    1384        
    1385     for (nCounter=0; nCounter<i; nCounter++)
    1386         memcpy(sNumber + nCounter, sDestination + nCounter, 1);
    1387        
    1388     memcpy(sNumber + nCounter, sDecimalSymbol, strlen(sDecimalSymbol));
    1389 
    1390     for (i=0; i<j; i++)
    1391         memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), sDigitsAfterDecimal + i, 1);
    1392     memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), "\0", 1);
    1393        
    1394     /* Is it a negative number */
    1395     if (bNegative == TRUE)
    1396     {
    1397         i = atoi(sNegNumber);
    1398         pStr = sDestination;
    1399         pTmpStr = sNumber;
    1400         switch (i)
    1401         {         
    1402         case 0:
    1403             *pStr++ = '(';
    1404             while (*sNumber != '\0')
    1405                 *pStr++ =  *pTmpStr++;
    1406             *pStr++ = ')';               
    1407             break; 
    1408         case 1:
    1409             *pStr++ = '-';
    1410             while (*pTmpStr != '\0')
    1411                 *pStr++ =  *pTmpStr++;
    1412             break;
    1413         case 2:
    1414             *pStr++ = '-';
    1415             *pStr++ = ' ';
    1416             while (*pTmpStr != '\0')
    1417                 *pStr++ =  *pTmpStr++;
    1418             break;
    1419         case 3:
    1420             while (*pTmpStr != '\0')
    1421                 *pStr++ =  *pTmpStr++;
    1422             *pStr++ = '-';
    1423             break;
    1424         case 4:
    1425             while (*pTmpStr != '\0')
    1426                 *pStr++ =  *pTmpStr++;
    1427             *pStr++ = ' ';
    1428             *pStr++ = '-';
    1429             break;
    1430         default:
    1431             while (*pTmpStr != '\0')
    1432                 *pStr++ =  *pTmpStr++;
    1433             break;
    1434         }
    1435     }
    1436     else
    1437         strcpy(sDestination, sNumber);
    1438 
    1439     /* If cchNumber is zero, then returns the number of bytes or characters
    1440      * required to hold the formatted number string
    1441      */
    1442     if (cchNumber==0)
    1443         retVal = strlen(sDestination) + 1;
    1444     else           
    1445     {
    1446         strncpy (lpNumberStr, sDestination, cchNumber);
    1447         lpNumberStr[cchNumber-1] = '\0';   /* ensure we got a NULL at the end */
    1448         retVal = strlen(lpNumberStr);
    1449     }
    1450          
    1451     return retVal;
    1452 }
    1453 
    1454 
    1455 
    1456 
    1457 /*****************************************************************************
    1458  * Name      : GetNumberFormat
    1459  * Purpose   : format a given number string according to local settings
    1460  * Parameters:
    1461  * Variables :
    1462  * Result    :
    1463  * Remark    :
    1464  * Status    :
    1465  *
    1466  * Author    : Patrick Haller [Sun, 2000/06/12 12:46]
    1467  *****************************************************************************/
    1468 
    1469 int WIN32API GetNumberFormatW(LCID     Locale,
    1470                               DWORD    dwFlags,
    1471                               LPCWSTR lpValue,
    1472                               CONST NUMBERFMTW *lpFormat,
    1473                               LPWSTR  lpNumberStr,
    1474                               int      cchNumber)
    1475 {
    1476   dprintf(("GetNumberFormatW(%08x,%08x,%s,%08x,%s,%08x) not properly implemented.\n",
    1477            Locale,
    1478            dwFlags,
    1479            lpValue,
    1480            lpFormat,
    1481            lpNumberStr,
    1482            cchNumber));
    1483  
    1484   // @@@PH cheap ass emulation
    1485   lstrcpynW(lpNumberStr,
    1486             lpValue,
    1487             cchNumber);
    1488  
    1489   return lstrlenW(lpNumberStr);
    1490 }
    1491 
Note: See TracChangeset for help on using the changeset viewer.