VirtualBox

Changeset 5712 in vbox


Ignore:
Timestamp:
Nov 12, 2007 3:40:19 PM (17 years ago)
Author:
vboxsync
Message:

Added warnings about trailing chars & spaces in the RTStrTo*Int* functions. Also added a new variant, RTStrTo*Int*Full, that will fail if there are trailing chars or spaces.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/string.h

    r5666 r5712  
    638638 *
    639639 * @returns iprt status code.
    640  *          Warnings are used to indicate conversion problems.
     640 *          Warnings are used to indicate convertion problems.
     641 * @retval  VWRN_NUMBER_TOO_BIG
     642 * @retval  VWRN_NEGATIVE_UNSIGNED
     643 * @retval  VWRN_TRAILING_CHARS
     644 * @retval  VWRN_TRAILING_SPACES
     645 * @retval  VINF_SUCCESS
     646 * @retval  VERR_NO_DIGITS
     647 *
    641648 * @param   pszValue    Pointer to the string value.
    642649 * @param   ppszNext    Where to store the pointer to the first char following the number. (Optional)
    643650 * @param   uBase       The base of the representation used.
    644  *                      If 0 the function will look for known prefixes before defaulting to 10.
     651 *                      If the function will look for known prefixes before defaulting to 10.
    645652 * @param   pu64        Where to store the converted number. (optional)
    646653 */
    647654RTDECL(int) RTStrToUInt64Ex(const char *pszValue, char **ppszNext, unsigned uBase, uint64_t *pu64);
     655
     656/**
     657 * Converts a string representation of a number to a 64-bit unsigned number,
     658 * making sure the full string is converted.
     659 *
     660 * @returns iprt status code.
     661 *          Warnings are used to indicate convertion problems.
     662 * @retval  VWRN_NUMBER_TOO_BIG
     663 * @retval  VWRN_NEGATIVE_UNSIGNED
     664 * @retval  VINF_SUCCESS
     665 * @retval  VERR_NO_DIGITS
     666 * @retval  VERR_TRAILING_SPACES
     667 * @retval  VERR_TRAILING_CHARS
     668 *
     669 * @param   pszValue    Pointer to the string value.
     670 * @param   uBase       The base of the representation used.
     671 *                      If the function will look for known prefixes before defaulting to 10.
     672 * @param   pu64        Where to store the converted number. (optional)
     673 */
     674RTDECL(int) RTStrToUInt64Full(const char *pszValue, unsigned uBase, uint64_t *pu64);
    648675
    649676/**
     
    662689 * @returns iprt status code.
    663690 *          Warnings are used to indicate conversion problems.
     691 * @retval  VWRN_NUMBER_TOO_BIG
     692 * @retval  VWRN_NEGATIVE_UNSIGNED
     693 * @retval  VWRN_TRAILING_CHARS
     694 * @retval  VWRN_TRAILING_SPACES
     695 * @retval  VINF_SUCCESS
     696 * @retval  VERR_NO_DIGITS
     697 *
    664698 * @param   pszValue    Pointer to the string value.
    665699 * @param   ppszNext    Where to store the pointer to the first char following the number. (Optional)
     
    671705
    672706/**
     707 * Converts a string representation of a number to a 32-bit unsigned number,
     708 * making sure the full string is converted.
     709 *
     710 * @returns iprt status code.
     711 *          Warnings are used to indicate convertion problems.
     712 * @retval  VWRN_NUMBER_TOO_BIG
     713 * @retval  VWRN_NEGATIVE_UNSIGNED
     714 * @retval  VINF_SUCCESS
     715 * @retval  VERR_NO_DIGITS
     716 * @retval  VERR_TRAILING_SPACES
     717 * @retval  VERR_TRAILING_CHARS
     718 *
     719 * @param   pszValue    Pointer to the string value.
     720 * @param   uBase       The base of the representation used.
     721 *                      If the function will look for known prefixes before defaulting to 10.
     722 * @param   pu32        Where to store the converted number. (optional)
     723 */
     724RTDECL(int) RTStrToUInt32Full(const char *pszValue, unsigned uBase, uint32_t *pu32);
     725
     726/**
    673727 * Converts a string representation of a number to a 64-bit unsigned number.
    674728 * The base is guessed.
     
    685739 * @returns iprt status code.
    686740 *          Warnings are used to indicate conversion problems.
     741 * @retval  VWRN_NUMBER_TOO_BIG
     742 * @retval  VWRN_NEGATIVE_UNSIGNED
     743 * @retval  VWRN_TRAILING_CHARS
     744 * @retval  VWRN_TRAILING_SPACES
     745 * @retval  VINF_SUCCESS
     746 * @retval  VERR_NO_DIGITS
     747 *
    687748 * @param   pszValue    Pointer to the string value.
    688749 * @param   ppszNext    Where to store the pointer to the first char following the number. (Optional)
     
    694755
    695756/**
     757 * Converts a string representation of a number to a 16-bit unsigned number,
     758 * making sure the full string is converted.
     759 *
     760 * @returns iprt status code.
     761 *          Warnings are used to indicate convertion problems.
     762 * @retval  VWRN_NUMBER_TOO_BIG
     763 * @retval  VWRN_NEGATIVE_UNSIGNED
     764 * @retval  VINF_SUCCESS
     765 * @retval  VERR_NO_DIGITS
     766 * @retval  VERR_TRAILING_SPACES
     767 * @retval  VERR_TRAILING_CHARS
     768 *
     769 * @param   pszValue    Pointer to the string value.
     770 * @param   uBase       The base of the representation used.
     771 *                      If the function will look for known prefixes before defaulting to 10.
     772 * @param   pu16        Where to store the converted number. (optional)
     773 */
     774RTDECL(int) RTStrToUInt16Full(const char *pszValue, unsigned uBase, uint16_t *pu16);
     775
     776/**
    696777 * Converts a string representation of a number to a 16-bit unsigned number.
    697778 * The base is guessed.
     
    708789 * @returns iprt status code.
    709790 *          Warnings are used to indicate conversion problems.
     791 * @retval  VWRN_NUMBER_TOO_BIG
     792 * @retval  VWRN_NEGATIVE_UNSIGNED
     793 * @retval  VWRN_TRAILING_CHARS
     794 * @retval  VWRN_TRAILING_SPACES
     795 * @retval  VINF_SUCCESS
     796 * @retval  VERR_NO_DIGITS
     797 *
    710798 * @param   pszValue    Pointer to the string value.
    711799 * @param   ppszNext    Where to store the pointer to the first char following the number. (Optional)
     
    717805
    718806/**
     807 * Converts a string representation of a number to a 8-bit unsigned number,
     808 * making sure the full string is converted.
     809 *
     810 * @returns iprt status code.
     811 *          Warnings are used to indicate convertion problems.
     812 * @retval  VWRN_NUMBER_TOO_BIG
     813 * @retval  VWRN_NEGATIVE_UNSIGNED
     814 * @retval  VINF_SUCCESS
     815 * @retval  VERR_NO_DIGITS
     816 * @retval  VERR_TRAILING_SPACES
     817 * @retval  VERR_TRAILING_CHARS
     818 *
     819 * @param   pszValue    Pointer to the string value.
     820 * @param   uBase       The base of the representation used.
     821 *                      If the function will look for known prefixes before defaulting to 10.
     822 * @param   pu8         Where to store the converted number. (optional)
     823 */
     824RTDECL(int) RTStrToUInt8Full(const char *pszValue, unsigned uBase, uint8_t *pu8);
     825
     826/**
    719827 * Converts a string representation of a number to a 8-bit unsigned number.
    720828 * The base is guessed.
     
    731839 * @returns iprt status code.
    732840 *          Warnings are used to indicate conversion problems.
     841 * @retval  VWRN_NUMBER_TOO_BIG
     842 * @retval  VWRN_TRAILING_CHARS
     843 * @retval  VWRN_TRAILING_SPACES
     844 * @retval  VINF_SUCCESS
     845 * @retval  VERR_NO_DIGITS
     846 *
    733847 * @param   pszValue    Pointer to the string value.
    734848 * @param   ppszNext    Where to store the pointer to the first char following the number. (Optional)
     
    740854
    741855/**
     856 * Converts a string representation of a number to a 64-bit signed number,
     857 * making sure the full string is converted.
     858 *
     859 * @returns iprt status code.
     860 *          Warnings are used to indicate convertion problems.
     861 * @retval  VWRN_NUMBER_TOO_BIG
     862 * @retval  VINF_SUCCESS
     863 * @retval  VERR_TRAILING_CHARS
     864 * @retval  VERR_TRAILING_SPACES
     865 * @retval  VERR_NO_DIGITS
     866 *
     867 * @param   pszValue    Pointer to the string value.
     868 * @param   uBase       The base of the representation used.
     869 *                      If the function will look for known prefixes before defaulting to 10.
     870 * @param   pi64        Where to store the converted number. (optional)
     871 */
     872RTDECL(int) RTStrToInt64Full(const char *pszValue, unsigned uBase, int64_t *pi64);
     873
     874/**
    742875 * Converts a string representation of a number to a 64-bit signed number.
    743876 * The base is guessed.
     
    754887 * @returns iprt status code.
    755888 *          Warnings are used to indicate conversion problems.
     889 * @retval  VWRN_NUMBER_TOO_BIG
     890 * @retval  VWRN_TRAILING_CHARS
     891 * @retval  VWRN_TRAILING_SPACES
     892 * @retval  VINF_SUCCESS
     893 * @retval  VERR_NO_DIGITS
     894 *
    756895 * @param   pszValue    Pointer to the string value.
    757896 * @param   ppszNext    Where to store the pointer to the first char following the number. (Optional)
     
    763902
    764903/**
     904 * Converts a string representation of a number to a 32-bit signed number,
     905 * making sure the full string is converted.
     906 *
     907 * @returns iprt status code.
     908 *          Warnings are used to indicate convertion problems.
     909 * @retval  VWRN_NUMBER_TOO_BIG
     910 * @retval  VINF_SUCCESS
     911 * @retval  VERR_TRAILING_CHARS
     912 * @retval  VERR_TRAILING_SPACES
     913 * @retval  VERR_NO_DIGITS
     914 *
     915 * @param   pszValue    Pointer to the string value.
     916 * @param   uBase       The base of the representation used.
     917 *                      If the function will look for known prefixes before defaulting to 10.
     918 * @param   pi32        Where to store the converted number. (optional)
     919 */
     920RTDECL(int) RTStrToInt32Full(const char *pszValue, unsigned uBase, int32_t *pi32);
     921
     922/**
    765923 * Converts a string representation of a number to a 32-bit signed number.
    766924 * The base is guessed.
     
    777935 * @returns iprt status code.
    778936 *          Warnings are used to indicate conversion problems.
     937 * @retval  VWRN_NUMBER_TOO_BIG
     938 * @retval  VWRN_TRAILING_CHARS
     939 * @retval  VWRN_TRAILING_SPACES
     940 * @retval  VINF_SUCCESS
     941 * @retval  VERR_NO_DIGITS
     942 *
    779943 * @param   pszValue    Pointer to the string value.
    780944 * @param   ppszNext    Where to store the pointer to the first char following the number. (Optional)
     
    786950
    787951/**
     952 * Converts a string representation of a number to a 16-bit signed number,
     953 * making sure the full string is converted.
     954 *
     955 * @returns iprt status code.
     956 *          Warnings are used to indicate convertion problems.
     957 * @retval  VWRN_NUMBER_TOO_BIG
     958 * @retval  VINF_SUCCESS
     959 * @retval  VERR_TRAILING_CHARS
     960 * @retval  VERR_TRAILING_SPACES
     961 * @retval  VERR_NO_DIGITS
     962 *
     963 * @param   pszValue    Pointer to the string value.
     964 * @param   uBase       The base of the representation used.
     965 *                      If the function will look for known prefixes before defaulting to 10.
     966 * @param   pi16        Where to store the converted number. (optional)
     967 */
     968RTDECL(int) RTStrToInt16Full(const char *pszValue, unsigned uBase, int16_t *pi16);
     969
     970/**
    788971 * Converts a string representation of a number to a 16-bit signed number.
    789972 * The base is guessed.
     
    800983 * @returns iprt status code.
    801984 *          Warnings are used to indicate conversion problems.
     985 * @retval  VWRN_NUMBER_TOO_BIG
     986 * @retval  VWRN_TRAILING_CHARS
     987 * @retval  VWRN_TRAILING_SPACES
     988 * @retval  VINF_SUCCESS
     989 * @retval  VERR_NO_DIGITS
     990 *
    802991 * @param   pszValue    Pointer to the string value.
    803992 * @param   ppszNext    Where to store the pointer to the first char following the number. (Optional)
     
    807996 */
    808997RTDECL(int) RTStrToInt8Ex(const char *pszValue, char **ppszNext, unsigned uBase, int8_t *pi8);
     998
     999/**
     1000 * Converts a string representation of a number to a 8-bit signed number,
     1001 * making sure the full string is converted.
     1002 *
     1003 * @returns iprt status code.
     1004 *          Warnings are used to indicate convertion problems.
     1005 * @retval  VWRN_NUMBER_TOO_BIG
     1006 * @retval  VINF_SUCCESS
     1007 * @retval  VERR_TRAILING_CHARS
     1008 * @retval  VERR_TRAILING_SPACES
     1009 * @retval  VERR_NO_DIGITS
     1010 *
     1011 * @param   pszValue    Pointer to the string value.
     1012 * @param   uBase       The base of the representation used.
     1013 *                      If the function will look for known prefixes before defaulting to 10.
     1014 * @param   pi64        Where to store the converted number. (optional)
     1015 */
     1016RTDECL(int) RTStrToInt8Full(const char *pszValue, unsigned uBase, int8_t *pi8);
    8091017
    8101018/**
  • trunk/src/VBox/Runtime/common/string/strtonum.cpp

    r5413 r5712  
    8383 * @returns iprt status code.
    8484 *          Warnings are used to indicate convertion problems.
     85 * @retval  VWRN_NUMBER_TOO_BIG
     86 * @retval  VWRN_NEGATIVE_UNSIGNED
     87 * @retval  VWRN_TRAILING_CHARS
     88 * @retval  VWRN_TRAILING_SPACES
     89 * @retval  VINF_SUCCESS
     90 * @retval  VERR_NO_DIGITS
     91 *
    8592 * @param   pszValue    Pointer to the string value.
    8693 * @param   ppszNext    Where to store the pointer to the first char following the number. (Optional)
     
    173180        *ppszNext = (char *)psz;
    174181
     182    /*
     183     * Warn about trailing chars/spaces.
     184     */
     185    if (    rc == VINF_SUCCESS
     186        &&  *psz)
     187    {
     188        while (*psz == ' ' || *psz == '\t')
     189            psz++;
     190        rc = *psz ? VWRN_TRAILING_CHARS : VWRN_TRAILING_SPACES;
     191    }
     192
     193    return rc;
     194}
     195
     196
     197/**
     198 * Converts a string representation of a number to a 64-bit unsigned number,
     199 * making sure the full string is converted.
     200 *
     201 * @returns iprt status code.
     202 *          Warnings are used to indicate convertion problems.
     203 * @retval  VWRN_NUMBER_TOO_BIG
     204 * @retval  VWRN_NEGATIVE_UNSIGNED
     205 * @retval  VINF_SUCCESS
     206 * @retval  VERR_NO_DIGITS
     207 * @retval  VERR_TRAILING_SPACES
     208 * @retval  VERR_TRAILING_CHARS
     209 *
     210 * @param   pszValue    Pointer to the string value.
     211 * @param   uBase       The base of the representation used.
     212 *                      If the function will look for known prefixes before defaulting to 10.
     213 * @param   pu64        Where to store the converted number. (optional)
     214 */
     215RTDECL(int) RTStrToUInt64Full(const char *pszValue, unsigned uBase, uint64_t *pu64)
     216{
     217    char *psz;
     218    int rc = RTStrToUInt64Ex(pszValue, &psz, uBase, pu64);
     219    if (RT_SUCCESS(rc) && *psz)
     220    {
     221        if (rc == VWRN_TRAILING_CHARS || rc == VWRN_TRAILING_SPACES)
     222            rc = -rc;
     223        else
     224        {
     225            while (*psz == ' ' || *psz == '\t')
     226                psz++;
     227            rc = *psz ? VERR_TRAILING_CHARS : VERR_TRAILING_SPACES;
     228        }
     229    }
    175230    return rc;
    176231}
     
    200255 * @returns iprt status code.
    201256 *          Warnings are used to indicate convertion problems.
     257 * @retval  VWRN_NUMBER_TOO_BIG
     258 * @retval  VWRN_NEGATIVE_UNSIGNED
     259 * @retval  VWRN_TRAILING_CHARS
     260 * @retval  VWRN_TRAILING_SPACES
     261 * @retval  VINF_SUCCESS
     262 * @retval  VERR_NO_DIGITS
     263 *
    202264 * @param   pszValue    Pointer to the string value.
    203265 * @param   ppszNext    Where to store the pointer to the first char following the number. (Optional)
     
    210272    uint64_t u64;
    211273    int rc = RTStrToUInt64Ex(pszValue, ppszNext, uBase, &u64);
     274    if (rc == VINF_SUCCESS)
     275    {
     276        if (u64 & ~0xffffffffULL)
     277            rc = VWRN_NUMBER_TOO_BIG;
     278    }
     279    if (pu32)
     280        *pu32 = (uint32_t)u64;
     281    return rc;
     282}
     283
     284
     285/**
     286 * Converts a string representation of a number to a 32-bit unsigned number,
     287 * making sure the full string is converted.
     288 *
     289 * @returns iprt status code.
     290 *          Warnings are used to indicate convertion problems.
     291 * @retval  VWRN_NUMBER_TOO_BIG
     292 * @retval  VWRN_NEGATIVE_UNSIGNED
     293 * @retval  VINF_SUCCESS
     294 * @retval  VERR_NO_DIGITS
     295 * @retval  VERR_TRAILING_SPACES
     296 * @retval  VERR_TRAILING_CHARS
     297 *
     298 * @param   pszValue    Pointer to the string value.
     299 * @param   uBase       The base of the representation used.
     300 *                      If the function will look for known prefixes before defaulting to 10.
     301 * @param   pu32        Where to store the converted number. (optional)
     302 */
     303RTDECL(int) RTStrToUInt32Full(const char *pszValue, unsigned uBase, uint32_t *pu32)
     304{
     305    uint64_t u64;
     306    int rc = RTStrToUInt64Full(pszValue, uBase, &u64);
    212307    if (rc == VINF_SUCCESS)
    213308    {
     
    244339 * @returns iprt status code.
    245340 *          Warnings are used to indicate convertion problems.
     341 * @retval  VWRN_NUMBER_TOO_BIG
     342 * @retval  VWRN_NEGATIVE_UNSIGNED
     343 * @retval  VWRN_TRAILING_CHARS
     344 * @retval  VWRN_TRAILING_SPACES
     345 * @retval  VINF_SUCCESS
     346 * @retval  VERR_NO_DIGITS
     347 *
    246348 * @param   pszValue    Pointer to the string value.
    247349 * @param   ppszNext    Where to store the pointer to the first char following the number. (Optional)
     
    254356    uint64_t u64;
    255357    int rc = RTStrToUInt64Ex(pszValue, ppszNext, uBase, &u64);
     358    if (rc == VINF_SUCCESS)
     359    {
     360        if (u64 & ~0xffffULL)
     361            rc = VWRN_NUMBER_TOO_BIG;
     362    }
     363    if (pu16)
     364        *pu16 = (uint16_t)u64;
     365    return rc;
     366}
     367
     368
     369/**
     370 * Converts a string representation of a number to a 16-bit unsigned number,
     371 * making sure the full string is converted.
     372 *
     373 * @returns iprt status code.
     374 *          Warnings are used to indicate convertion problems.
     375 * @retval  VWRN_NUMBER_TOO_BIG
     376 * @retval  VWRN_NEGATIVE_UNSIGNED
     377 * @retval  VINF_SUCCESS
     378 * @retval  VERR_NO_DIGITS
     379 * @retval  VERR_TRAILING_SPACES
     380 * @retval  VERR_TRAILING_CHARS
     381 *
     382 * @param   pszValue    Pointer to the string value.
     383 * @param   uBase       The base of the representation used.
     384 *                      If the function will look for known prefixes before defaulting to 10.
     385 * @param   pu16        Where to store the converted number. (optional)
     386 */
     387RTDECL(int) RTStrToUInt16Full(const char *pszValue, unsigned uBase, uint16_t *pu16)
     388{
     389    uint64_t u64;
     390    int rc = RTStrToUInt64Full(pszValue, uBase, &u64);
    256391    if (rc == VINF_SUCCESS)
    257392    {
     
    288423 * @returns iprt status code.
    289424 *          Warnings are used to indicate convertion problems.
     425 * @retval  VWRN_NUMBER_TOO_BIG
     426 * @retval  VWRN_NEGATIVE_UNSIGNED
     427 * @retval  VWRN_TRAILING_CHARS
     428 * @retval  VWRN_TRAILING_SPACES
     429 * @retval  VINF_SUCCESS
     430 * @retval  VERR_NO_DIGITS
     431 *
    290432 * @param   pszValue    Pointer to the string value.
    291433 * @param   ppszNext    Where to store the pointer to the first char following the number. (Optional)
     
    298440    uint64_t u64;
    299441    int rc = RTStrToUInt64Ex(pszValue, ppszNext, uBase, &u64);
     442    if (rc == VINF_SUCCESS)
     443    {
     444        if (u64 & ~0xffULL)
     445            rc = VWRN_NUMBER_TOO_BIG;
     446    }
     447    if (pu8)
     448        *pu8 = (uint8_t)u64;
     449    return rc;
     450}
     451
     452
     453/**
     454 * Converts a string representation of a number to a 8-bit unsigned number,
     455 * making sure the full string is converted.
     456 *
     457 * @returns iprt status code.
     458 *          Warnings are used to indicate convertion problems.
     459 * @retval  VWRN_NUMBER_TOO_BIG
     460 * @retval  VWRN_NEGATIVE_UNSIGNED
     461 * @retval  VINF_SUCCESS
     462 * @retval  VERR_NO_DIGITS
     463 * @retval  VERR_TRAILING_SPACES
     464 * @retval  VERR_TRAILING_CHARS
     465 *
     466 * @param   pszValue    Pointer to the string value.
     467 * @param   uBase       The base of the representation used.
     468 *                      If the function will look for known prefixes before defaulting to 10.
     469 * @param   pu8         Where to store the converted number. (optional)
     470 */
     471RTDECL(int) RTStrToUInt8Full(const char *pszValue, unsigned uBase, uint8_t *pu8)
     472{
     473    uint64_t u64;
     474    int rc = RTStrToUInt64Full(pszValue, uBase, &u64);
    300475    if (rc == VINF_SUCCESS)
    301476    {
     
    337512 * @returns iprt status code.
    338513 *          Warnings are used to indicate convertion problems.
     514 * @retval  VWRN_NUMBER_TOO_BIG
     515 * @retval  VWRN_TRAILING_CHARS
     516 * @retval  VWRN_TRAILING_SPACES
     517 * @retval  VINF_SUCCESS
     518 * @retval  VERR_NO_DIGITS
     519 *
    339520 * @param   pszValue    Pointer to the string value.
    340521 * @param   ppszNext    Where to store the pointer to the first char following the number. (Optional)
     
    423604        *ppszNext = (char *)psz;
    424605
     606    /*
     607     * Warn about trailing chars/spaces.
     608     */
     609    if (    rc == VINF_SUCCESS
     610        &&  *psz)
     611    {
     612        while (*psz == ' ' || *psz == '\t')
     613            psz++;
     614        rc = *psz ? VWRN_TRAILING_CHARS : VWRN_TRAILING_SPACES;
     615    }
     616
     617    return rc;
     618}
     619
     620
     621/**
     622 * Converts a string representation of a number to a 64-bit signed number,
     623 * making sure the full string is converted.
     624 *
     625 * @returns iprt status code.
     626 *          Warnings are used to indicate convertion problems.
     627 * @retval  VWRN_NUMBER_TOO_BIG
     628 * @retval  VINF_SUCCESS
     629 * @retval  VERR_TRAILING_CHARS
     630 * @retval  VERR_TRAILING_SPACES
     631 * @retval  VERR_NO_DIGITS
     632 *
     633 * @param   pszValue    Pointer to the string value.
     634 * @param   uBase       The base of the representation used.
     635 *                      If the function will look for known prefixes before defaulting to 10.
     636 * @param   pi64        Where to store the converted number. (optional)
     637 */
     638RTDECL(int) RTStrToInt64Full(const char *pszValue, unsigned uBase, int64_t *pi64)
     639{
     640    char *psz;
     641    int rc = RTStrToInt64Ex(pszValue, &psz, uBase, pi64);
     642    if (RT_SUCCESS(rc) && *psz)
     643    {
     644        if (rc == VWRN_TRAILING_CHARS || rc == VWRN_TRAILING_SPACES)
     645            rc = -rc;
     646        else
     647        {
     648            while (*psz == ' ' || *psz == '\t')
     649                psz++;
     650            rc = *psz ? VERR_TRAILING_CHARS : VERR_TRAILING_SPACES;
     651        }
     652    }
    425653    return rc;
    426654}
     
    450678 * @returns iprt status code.
    451679 *          Warnings are used to indicate convertion problems.
     680 * @retval  VWRN_NUMBER_TOO_BIG
     681 * @retval  VWRN_TRAILING_CHARS
     682 * @retval  VWRN_TRAILING_SPACES
     683 * @retval  VINF_SUCCESS
     684 * @retval  VERR_NO_DIGITS
     685 *
    452686 * @param   pszValue    Pointer to the string value.
    453687 * @param   ppszNext    Where to store the pointer to the first char following the number. (Optional)
     
    460694    int64_t i64;
    461695    int rc = RTStrToInt64Ex(pszValue, ppszNext, uBase, &i64);
     696    if (rc == VINF_SUCCESS)
     697    {
     698        int32_t i32 = (int32_t)i64;
     699        if (i64 != (int64_t)i32)
     700            rc = VWRN_NUMBER_TOO_BIG;
     701    }
     702    if (pi32)
     703        *pi32 = (int32_t)i64;
     704    return rc;
     705}
     706
     707
     708/**
     709 * Converts a string representation of a number to a 32-bit signed number,
     710 * making sure the full string is converted.
     711 *
     712 * @returns iprt status code.
     713 *          Warnings are used to indicate convertion problems.
     714 * @retval  VWRN_NUMBER_TOO_BIG
     715 * @retval  VINF_SUCCESS
     716 * @retval  VERR_TRAILING_CHARS
     717 * @retval  VERR_TRAILING_SPACES
     718 * @retval  VERR_NO_DIGITS
     719 *
     720 * @param   pszValue    Pointer to the string value.
     721 * @param   uBase       The base of the representation used.
     722 *                      If the function will look for known prefixes before defaulting to 10.
     723 * @param   pi32        Where to store the converted number. (optional)
     724 */
     725RTDECL(int) RTStrToInt32Full(const char *pszValue, unsigned uBase, int32_t *pi32)
     726{
     727    int64_t i64;
     728    int rc = RTStrToInt64Full(pszValue, uBase, &i64);
    462729    if (rc == VINF_SUCCESS)
    463730    {
     
    495762 * @returns iprt status code.
    496763 *          Warnings are used to indicate convertion problems.
     764 * @retval  VWRN_NUMBER_TOO_BIG
     765 * @retval  VWRN_TRAILING_CHARS
     766 * @retval  VWRN_TRAILING_SPACES
     767 * @retval  VINF_SUCCESS
     768 * @retval  VERR_NO_DIGITS
     769 *
    497770 * @param   pszValue    Pointer to the string value.
    498771 * @param   ppszNext    Where to store the pointer to the first char following the number. (Optional)
     
    505778    int64_t i64;
    506779    int rc = RTStrToInt64Ex(pszValue, ppszNext, uBase, &i64);
     780    if (rc == VINF_SUCCESS)
     781    {
     782        int16_t i16 = (int16_t)i64;
     783        if (i64 != (int64_t)i16)
     784            rc = VWRN_NUMBER_TOO_BIG;
     785    }
     786    if (pi16)
     787        *pi16 = (int16_t)i64;
     788    return rc;
     789}
     790
     791
     792/**
     793 * Converts a string representation of a number to a 16-bit signed number,
     794 * making sure the full string is converted.
     795 *
     796 * @returns iprt status code.
     797 *          Warnings are used to indicate convertion problems.
     798 * @retval  VWRN_NUMBER_TOO_BIG
     799 * @retval  VINF_SUCCESS
     800 * @retval  VERR_TRAILING_CHARS
     801 * @retval  VERR_TRAILING_SPACES
     802 * @retval  VERR_NO_DIGITS
     803 *
     804 * @param   pszValue    Pointer to the string value.
     805 * @param   uBase       The base of the representation used.
     806 *                      If the function will look for known prefixes before defaulting to 10.
     807 * @param   pi16        Where to store the converted number. (optional)
     808 */
     809RTDECL(int) RTStrToInt16Full(const char *pszValue, unsigned uBase, int16_t *pi16)
     810{
     811    int64_t i64;
     812    int rc = RTStrToInt64Full(pszValue, uBase, &i64);
    507813    if (rc == VINF_SUCCESS)
    508814    {
     
    540846 * @returns iprt status code.
    541847 *          Warnings are used to indicate convertion problems.
     848 * @retval  VWRN_NUMBER_TOO_BIG
     849 * @retval  VWRN_TRAILING_CHARS
     850 * @retval  VWRN_TRAILING_SPACES
     851 * @retval  VINF_SUCCESS
     852 * @retval  VERR_NO_DIGITS
     853 *
    542854 * @param   pszValue    Pointer to the string value.
    543855 * @param   ppszNext    Where to store the pointer to the first char following the number. (Optional)
     
    550862    int64_t i64;
    551863    int rc = RTStrToInt64Ex(pszValue, ppszNext, uBase, &i64);
     864    if (rc == VINF_SUCCESS)
     865    {
     866        int8_t i8 = (int8_t)i64;
     867        if (i64 != (int64_t)i8)
     868            rc = VWRN_NUMBER_TOO_BIG;
     869    }
     870    if (pi8)
     871        *pi8 = (int8_t)i64;
     872    return rc;
     873}
     874
     875
     876/**
     877 * Converts a string representation of a number to a 8-bit signed number,
     878 * making sure the full string is converted.
     879 *
     880 * @returns iprt status code.
     881 *          Warnings are used to indicate convertion problems.
     882 * @retval  VWRN_NUMBER_TOO_BIG
     883 * @retval  VINF_SUCCESS
     884 * @retval  VERR_TRAILING_CHARS
     885 * @retval  VERR_TRAILING_SPACES
     886 * @retval  VERR_NO_DIGITS
     887 *
     888 * @param   pszValue    Pointer to the string value.
     889 * @param   uBase       The base of the representation used.
     890 *                      If the function will look for known prefixes before defaulting to 10.
     891 * @param   pi64        Where to store the converted number. (optional)
     892 */
     893RTDECL(int) RTStrToInt8Full(const char *pszValue, unsigned uBase, int8_t *pi8)
     894{
     895    int64_t i64;
     896    int rc = RTStrToInt64Full(pszValue, uBase, &i64);
    552897    if (rc == VINF_SUCCESS)
    553898    {
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