Changeset 5712 in vbox
- Timestamp:
- Nov 12, 2007 3:40:19 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/string.h
r5666 r5712 638 638 * 639 639 * @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 * 641 648 * @param pszValue Pointer to the string value. 642 649 * @param ppszNext Where to store the pointer to the first char following the number. (Optional) 643 650 * @param uBase The base of the representation used. 644 * If 0the function will look for known prefixes before defaulting to 10.651 * If the function will look for known prefixes before defaulting to 10. 645 652 * @param pu64 Where to store the converted number. (optional) 646 653 */ 647 654 RTDECL(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 */ 674 RTDECL(int) RTStrToUInt64Full(const char *pszValue, unsigned uBase, uint64_t *pu64); 648 675 649 676 /** … … 662 689 * @returns iprt status code. 663 690 * 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 * 664 698 * @param pszValue Pointer to the string value. 665 699 * @param ppszNext Where to store the pointer to the first char following the number. (Optional) … … 671 705 672 706 /** 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 */ 724 RTDECL(int) RTStrToUInt32Full(const char *pszValue, unsigned uBase, uint32_t *pu32); 725 726 /** 673 727 * Converts a string representation of a number to a 64-bit unsigned number. 674 728 * The base is guessed. … … 685 739 * @returns iprt status code. 686 740 * 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 * 687 748 * @param pszValue Pointer to the string value. 688 749 * @param ppszNext Where to store the pointer to the first char following the number. (Optional) … … 694 755 695 756 /** 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 */ 774 RTDECL(int) RTStrToUInt16Full(const char *pszValue, unsigned uBase, uint16_t *pu16); 775 776 /** 696 777 * Converts a string representation of a number to a 16-bit unsigned number. 697 778 * The base is guessed. … … 708 789 * @returns iprt status code. 709 790 * 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 * 710 798 * @param pszValue Pointer to the string value. 711 799 * @param ppszNext Where to store the pointer to the first char following the number. (Optional) … … 717 805 718 806 /** 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 */ 824 RTDECL(int) RTStrToUInt8Full(const char *pszValue, unsigned uBase, uint8_t *pu8); 825 826 /** 719 827 * Converts a string representation of a number to a 8-bit unsigned number. 720 828 * The base is guessed. … … 731 839 * @returns iprt status code. 732 840 * 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 * 733 847 * @param pszValue Pointer to the string value. 734 848 * @param ppszNext Where to store the pointer to the first char following the number. (Optional) … … 740 854 741 855 /** 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 */ 872 RTDECL(int) RTStrToInt64Full(const char *pszValue, unsigned uBase, int64_t *pi64); 873 874 /** 742 875 * Converts a string representation of a number to a 64-bit signed number. 743 876 * The base is guessed. … … 754 887 * @returns iprt status code. 755 888 * 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 * 756 895 * @param pszValue Pointer to the string value. 757 896 * @param ppszNext Where to store the pointer to the first char following the number. (Optional) … … 763 902 764 903 /** 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 */ 920 RTDECL(int) RTStrToInt32Full(const char *pszValue, unsigned uBase, int32_t *pi32); 921 922 /** 765 923 * Converts a string representation of a number to a 32-bit signed number. 766 924 * The base is guessed. … … 777 935 * @returns iprt status code. 778 936 * 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 * 779 943 * @param pszValue Pointer to the string value. 780 944 * @param ppszNext Where to store the pointer to the first char following the number. (Optional) … … 786 950 787 951 /** 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 */ 968 RTDECL(int) RTStrToInt16Full(const char *pszValue, unsigned uBase, int16_t *pi16); 969 970 /** 788 971 * Converts a string representation of a number to a 16-bit signed number. 789 972 * The base is guessed. … … 800 983 * @returns iprt status code. 801 984 * 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 * 802 991 * @param pszValue Pointer to the string value. 803 992 * @param ppszNext Where to store the pointer to the first char following the number. (Optional) … … 807 996 */ 808 997 RTDECL(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 */ 1016 RTDECL(int) RTStrToInt8Full(const char *pszValue, unsigned uBase, int8_t *pi8); 809 1017 810 1018 /** -
trunk/src/VBox/Runtime/common/string/strtonum.cpp
r5413 r5712 83 83 * @returns iprt status code. 84 84 * 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 * 85 92 * @param pszValue Pointer to the string value. 86 93 * @param ppszNext Where to store the pointer to the first char following the number. (Optional) … … 173 180 *ppszNext = (char *)psz; 174 181 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 */ 215 RTDECL(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 } 175 230 return rc; 176 231 } … … 200 255 * @returns iprt status code. 201 256 * 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 * 202 264 * @param pszValue Pointer to the string value. 203 265 * @param ppszNext Where to store the pointer to the first char following the number. (Optional) … … 210 272 uint64_t u64; 211 273 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 */ 303 RTDECL(int) RTStrToUInt32Full(const char *pszValue, unsigned uBase, uint32_t *pu32) 304 { 305 uint64_t u64; 306 int rc = RTStrToUInt64Full(pszValue, uBase, &u64); 212 307 if (rc == VINF_SUCCESS) 213 308 { … … 244 339 * @returns iprt status code. 245 340 * 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 * 246 348 * @param pszValue Pointer to the string value. 247 349 * @param ppszNext Where to store the pointer to the first char following the number. (Optional) … … 254 356 uint64_t u64; 255 357 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 */ 387 RTDECL(int) RTStrToUInt16Full(const char *pszValue, unsigned uBase, uint16_t *pu16) 388 { 389 uint64_t u64; 390 int rc = RTStrToUInt64Full(pszValue, uBase, &u64); 256 391 if (rc == VINF_SUCCESS) 257 392 { … … 288 423 * @returns iprt status code. 289 424 * 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 * 290 432 * @param pszValue Pointer to the string value. 291 433 * @param ppszNext Where to store the pointer to the first char following the number. (Optional) … … 298 440 uint64_t u64; 299 441 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 */ 471 RTDECL(int) RTStrToUInt8Full(const char *pszValue, unsigned uBase, uint8_t *pu8) 472 { 473 uint64_t u64; 474 int rc = RTStrToUInt64Full(pszValue, uBase, &u64); 300 475 if (rc == VINF_SUCCESS) 301 476 { … … 337 512 * @returns iprt status code. 338 513 * 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 * 339 520 * @param pszValue Pointer to the string value. 340 521 * @param ppszNext Where to store the pointer to the first char following the number. (Optional) … … 423 604 *ppszNext = (char *)psz; 424 605 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 */ 638 RTDECL(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 } 425 653 return rc; 426 654 } … … 450 678 * @returns iprt status code. 451 679 * 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 * 452 686 * @param pszValue Pointer to the string value. 453 687 * @param ppszNext Where to store the pointer to the first char following the number. (Optional) … … 460 694 int64_t i64; 461 695 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 */ 725 RTDECL(int) RTStrToInt32Full(const char *pszValue, unsigned uBase, int32_t *pi32) 726 { 727 int64_t i64; 728 int rc = RTStrToInt64Full(pszValue, uBase, &i64); 462 729 if (rc == VINF_SUCCESS) 463 730 { … … 495 762 * @returns iprt status code. 496 763 * 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 * 497 770 * @param pszValue Pointer to the string value. 498 771 * @param ppszNext Where to store the pointer to the first char following the number. (Optional) … … 505 778 int64_t i64; 506 779 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 */ 809 RTDECL(int) RTStrToInt16Full(const char *pszValue, unsigned uBase, int16_t *pi16) 810 { 811 int64_t i64; 812 int rc = RTStrToInt64Full(pszValue, uBase, &i64); 507 813 if (rc == VINF_SUCCESS) 508 814 { … … 540 846 * @returns iprt status code. 541 847 * 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 * 542 854 * @param pszValue Pointer to the string value. 543 855 * @param ppszNext Where to store the pointer to the first char following the number. (Optional) … … 550 862 int64_t i64; 551 863 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 */ 893 RTDECL(int) RTStrToInt8Full(const char *pszValue, unsigned uBase, int8_t *pi8) 894 { 895 int64_t i64; 896 int rc = RTStrToInt64Full(pszValue, uBase, &i64); 552 897 if (rc == VINF_SUCCESS) 553 898 {
Note:
See TracChangeset
for help on using the changeset viewer.