36 #include <Carbon/Carbon.h>
43 #if defined(XP_MACOSX)
44 #define UTF16_CHARTYPE UniChar
45 #define NATIVE_CHAR_TYPE UniChar
46 #elif defined(XP_UNIX)
47 #define UTF16_CHARTYPE gunichar2
48 #define NATIVE_CHAR_TYPE gunichar
50 #define UTF16_CHARTYPE wchar_t
51 #define NATIVE_CHAR_TYPE wchar_t
54 #define CHARTYPE_OTHER 0
55 #define CHARTYPE_DIGIT 1
56 #define CHARTYPE_DECIMALPOINT 2
57 #define CHARTYPE_SIGN 3
58 #define CHARTYPE_EXPONENT 4
72 if (*p >=
'0' && *p <=
'9')
77 template<
class CHARTYPE>
79 PRBool *hasLeadingNumber,
80 PRFloat64 *leadingNumber,
81 PRInt32 *numberLength) {
89 PRBool gotDecimalPoint = PR_FALSE;
90 PRBool gotExponent = PR_FALSE;
91 PRBool gotSign = PR_FALSE;
92 PRBool gotExponentSign = PR_FALSE;
93 PRBool gotDigit = PR_FALSE;
94 PRBool gotExponentDigit = PR_FALSE;
95 PRBool abortParsing = PR_FALSE;
98 PRFloat64 decimalMul = 1;
102 const CHARTYPE *
p =
str;
104 while (!abortParsing && *p) {
111 if (gotSign || gotDigit || gotDecimalPoint) {
112 abortParsing = PR_TRUE;
129 if (gotExponentSign || gotExponentDigit) {
130 abortParsing = PR_TRUE;
134 gotExponentSign = PR_TRUE;
149 if (!gotDecimalPoint) {
154 value += (*p -
'0') * decimalMul;
157 gotExponentDigit = PR_TRUE;
159 expValue += *p -
'0';
166 if (gotDecimalPoint) {
167 abortParsing = PR_TRUE;
171 gotDecimalPoint = PR_TRUE;
174 abortParsing = PR_TRUE;
182 abortParsing = PR_TRUE;
192 gotExponent = PR_TRUE;
197 abortParsing = PR_TRUE;
204 abortParsing = PR_TRUE;
219 *numberLength = p-
str;
227 if (hasLeadingNumber)
228 *hasLeadingNumber = PR_FALSE;
237 PRFloat64 mul = pow((PRFloat64)10, (PRFloat64)(expValue * expSign));
244 if (hasLeadingNumber)
245 *hasLeadingNumber = PR_TRUE;
247 *leadingNumber =
value;
255 const CHARTYPE *
p = aStr;
256 const CHARTYPE *beginning = NULL;
262 return beginning-aStr;
#define CHARTYPE_EXPONENT
PRInt32 SB_FindNextNumber(const CHARTYPE *aStr)
void SB_ExtractLeadingNumber(const CHARTYPE *str, PRBool *hasLeadingNumber, PRFloat64 *leadingNumber, PRInt32 *numberLength)
#define CHARTYPE_DECIMALPOINT
PRInt32 SB_GetCharType(const CHARTYPE *p)