Changeset 102006 in vbox for trunk/src/libs/xpcom18a4
- Timestamp:
- Nov 8, 2023 7:17:10 PM (15 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/xpcom/string/src/nsStringObsolete.cpp
r31259 r102006 51 51 #include "nsCRT.h" 52 52 #include "nsUTF8Utils.h" 53 #include "prdtoa.h"54 53 #include "prprf.h" 55 #ifdef VBOX_USE_IPRT_IN_XPCOM 56 # include <iprt/mem.h> 57 #endif 54 55 #include <iprt/assert.h> 56 #include <iprt/errcore.h> 57 #include <iprt/mem.h> 58 #include <iprt/string.h> 58 59 59 60 /* ***** BEGIN RICKG BLOCK ***** … … 803 804 return kNotFound; 804 805 } 805 806 /**807 * This is a copy of |PR_cnvtf| with a bug fixed. (The second argument808 * of PR_dtoa is 2 rather than 1.)809 *810 * XXXdarin if this is the right thing, then why wasn't it fixed in NSPR?!?811 */812 void813 Modified_cnvtf(char *buf, int bufsz, int prcsn, double fval)814 {815 PRIntn decpt, sign, numdigits;816 char *num, *nump;817 char *bufp = buf;818 char *endnum;819 820 /* If anything fails, we store an empty string in 'buf' */821 #ifdef VBOX_USE_IPRT_IN_XPCOM822 num = (char*)RTMemAlloc(bufsz);823 #else824 num = (char*)malloc(bufsz);825 #endif826 if (num == NULL) {827 buf[0] = '\0';828 return;829 }830 if (PR_dtoa(fval, 2, prcsn, &decpt, &sign, &endnum, num, bufsz)831 == PR_FAILURE) {832 buf[0] = '\0';833 goto done;834 }835 numdigits = endnum - num;836 nump = num;837 838 /*839 * The NSPR code had a fancy way of checking that we weren't dealing840 * with -0.0 or -NaN, but I'll just use < instead.841 * XXX Should we check !isnan(fval) as well? Is it portable? We842 * probably don't need to bother since NAN isn't portable.843 */844 if (sign && fval < 0.0f) {845 *bufp++ = '-';846 }847 848 if (decpt == 9999) {849 while ((*bufp++ = *nump++) != 0) {} /* nothing to execute */850 goto done;851 }852 853 if (decpt > (prcsn+1) || decpt < -(prcsn-1) || decpt < -5) {854 *bufp++ = *nump++;855 if (numdigits != 1) {856 *bufp++ = '.';857 }858 859 while (*nump != '\0') {860 *bufp++ = *nump++;861 }862 *bufp++ = 'e';863 PR_snprintf(bufp, bufsz - (bufp - buf), "%+d", decpt-1);864 }865 else if (decpt >= 0) {866 if (decpt == 0) {867 *bufp++ = '0';868 }869 else {870 while (decpt--) {871 if (*nump != '\0') {872 *bufp++ = *nump++;873 }874 else {875 *bufp++ = '0';876 }877 }878 }879 if (*nump != '\0') {880 *bufp++ = '.';881 while (*nump != '\0') {882 *bufp++ = *nump++;883 }884 }885 *bufp++ = '\0';886 }887 else if (decpt < 0) {888 *bufp++ = '0';889 *bufp++ = '.';890 while (decpt++) {891 *bufp++ = '0';892 }893 894 while (*nump != '\0') {895 *bufp++ = *nump++;896 }897 *bufp++ = '\0';898 }899 done:900 #ifdef VBOX_USE_IPRT_IN_XPCOM901 RTMemFree(num);902 #else903 free(num);904 #endif905 }906 806 907 807 /** … … 1141 1041 if (mLength > 0) 1142 1042 { 1143 char *conv_stopped; 1144 const char *str = mData; 1145 // Use PR_strtod, not strtod, since we don't want locale involved. 1146 res = (float)PR_strtod(str, &conv_stopped); 1147 if (conv_stopped == str+mLength) 1043 int vrc = RTStrToFloatEx(mData, NULL /*ppstNext*/, 0 /*cchMax*/, &res); 1044 if (vrc == VINF_SUCCESS) 1148 1045 *aErrorCode = (PRInt32) NS_OK; 1149 else // Not all the string was scanned1046 else // Illegal value 1150 1047 *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; 1151 1048 } … … 1165 1062 if (mLength > 0 && mLength < sizeof(buf)) 1166 1063 { 1167 char *conv_stopped;1168 1064 const char *str = ToCString(buf, sizeof(buf)); 1169 // Use PR_strtod, not strtod, since we don't want locale involved. 1170 res = (float)PR_strtod(str, &conv_stopped); 1171 if (conv_stopped == str+mLength) 1065 int vrc = RTStrToFloatEx(str, NULL /*ppstNext*/, 0 /*cchMax*/, &res); 1066 if (vrc == VINF_SUCCESS) 1172 1067 *aErrorCode = (PRInt32) NS_OK; 1173 else // Not all the string was scanned1068 else // Illegal value 1174 1069 *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; 1175 1070 } … … 1309 1204 { 1310 1205 char buf[40]; 1311 // Use Modified_cnvtf, which is locale-insensitive, instead of the 1312 // locale-sensitive PR_snprintf or sprintf(3) 1313 Modified_cnvtf(buf, sizeof(buf), 6, aFloat); 1206 RTFLOAT64U r64; 1207 r64.rd = aFloat; 1208 ssize_t cch = RTStrFormatR64(buf, sizeof(buf), &r64, 0, 6 /*cchPrecision*/, 0 /*fFlags*/); 1209 Assert(cch > 0); 1314 1210 Append(buf); 1315 1211 } … … 1319 1215 { 1320 1216 char buf[40]; 1321 // Use Modified_cnvtf, which is locale-insensitive, instead of the 1322 // locale-sensitive PR_snprintf or sprintf(3) 1323 Modified_cnvtf(buf, sizeof(buf), 6, aFloat); 1217 RTFLOAT64U r64; 1218 r64.rd = aFloat; 1219 ssize_t cch = RTStrFormatR64(buf, sizeof(buf), &r64, 0, 6 /*cchPrecision*/, 0 /*fFlags*/); 1220 Assert(cch > 0); 1324 1221 AppendWithConversion(buf); 1325 1222 }
Note:
See TracChangeset
for help on using the changeset viewer.