VirtualBox

Ignore:
Timestamp:
Aug 12, 2022 11:24:22 AM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
152967
Message:

IPRT/nocrt: Added floating point parsing to vsscanf, very relaxed wrt input format for now. bugref:10261

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/string/nocrt-vsscanf.cpp

    r96128 r96161  
    3333#include <iprt/nocrt/stdio.h>
    3434#include <iprt/ctype.h>
     35#include <iprt/err.h>
    3536#include <iprt/stdarg.h>
    3637#include <iprt/string.h>
     
    139140    }
    140141
     142    return pszString;
     143}
     144
     145
     146static const char *rtNoCrtScanFloat(const char *pszString, char chPrefix, int cchWidth, void *pvDst, int *pcMatches)
     147{
     148    size_t const cchMax = cchWidth > 0 ? (unsigned)cchWidth : 0;
     149    int          rc;
     150    switch (chPrefix)
     151    {
     152        default:
     153        case '\0':
     154#ifndef RT_OS_WINDOWS /* Windows doesn't do float, only double and "long" double (same as double). */
     155            rc = RTStrToFloatEx(pszString, (char **)&pszString, cchMax, (float *)pvDst);
     156            break;
     157#else
     158            RT_FALL_THRU();
     159#endif
     160        case 'l':
     161            rc = RTStrToDoubleEx(pszString, (char **)&pszString, cchMax, (double *)pvDst);
     162            break;
     163
     164        case 'L':
     165            rc = RTStrToLongDoubleEx(pszString, (char **)&pszString, cchMax, (long double *)pvDst);
     166            break;
     167    }
     168    if (rc != VERR_NO_DIGITS)
     169        *pcMatches += pvDst != NULL;
     170    else
     171        pszString = NULL;
    141172    return pszString;
    142173}
     
    271302                        void *pvDst = NULL;
    272303                        if (fAssign)
    273                             pvDst = va_arg(va, void *); /* This ought to work most place... Probably standard conforming. */
     304                            pvDst = va_arg(va, void *); /* This ought to work most place... Probably not standard conforming. */
    274305                        pszString = rtNoCrtScanInt(pszString,
    275306                                                   chFmt == 'i' ? 0 : chFmt == 'd' || chFmt == 'u' ? 10 : chFmt == 'o' ? 8 :  16,
     
    281312                    }
    282313
     314                    case 'a':
     315                    case 'A':
     316                    case 'e':
     317                    case 'E':
     318                    case 'f':
     319                    case 'F':
     320                    case 'g':
     321                    case 'G':
     322                    {
     323                        while (RT_C_IS_SPACE(*pszString))
     324                            pszString++;
     325
     326                        /* Note! We don't really give a hoot what input format type we're given,
     327                                 we keep and open mind and acceept whatever we find that looks like
     328                                 floating point.  This is doubtfully standard compliant. */
     329                        void *pvDst = NULL;
     330                        if (fAssign)
     331                            pvDst = va_arg(va, void *); /* This ought to work most place... Probably not standard conforming. */
     332                        pszString = rtNoCrtScanFloat(pszString, chPrefix, cchWidth, pvDst, &cMatches);
     333                        if (!pszString)
     334                            return cMatches;
     335                        break;
     336                    }
     337
    283338                    case 'n':
    284339                    {
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette