Changeset 7245 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Aug 12, 2004, 4:04:11 PM (21 years ago)
Author:
darin
Message:

Reviewed by Adele.

  • fixed 3 problems with parse functions that I just wrote, fixing 3 more Mozilla JavaScript tests
  • kjs/function.cpp: (KJS::parseDigit): Fix typo, 'Z' instead of 'z', that prevented lowercase hex digits from working. (KJS::parseInt): Add octal support. Specification says it's optional, but I guess not. (KJS::parseFloat): Fix check for "0x" in parseFloat to return 0 rather than NaN. Also add code to skip leading "+" or "-".
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/function.cpp

    r7239 r7245  
    527527    } else if (c >= 'A' && c <= 'Z') {
    528528        digit = c - 'A' + 10;
    529     } else if (c >= 'a' && c <= 'Z') {
     529    } else if (c >= 'a' && c <= 'z') {
    530530        digit = c - 'a' + 10;
    531531    }
     
    555555    }
    556556
    557     if (length - p >= 2 && s[p] == '0' && (s[p + 1] == 'x' || s[p + 1] == 'X')) {
    558         if (radix == 0)
    559             radix = 16;
    560         if (radix == 16)
    561             p += 2;
    562     }
    563     if (radix == 0)
    564         radix = 10;
     557    if ((radix == 0 || radix == 16) && length - p >= 2 && s[p] == '0' && (s[p + 1] == 'x' || s[p + 1] == 'X')) {
     558        radix = 16;
     559        p += 2;
     560    } else if (radix == 0) {
     561        if (p < length && s[p] == '0')
     562            radix = 8;
     563        else
     564            radix = 10;
     565    }
    565566
    566567    if (radix < 2 || radix > 36)
     
    587588static double parseFloat(const UString &s)
    588589{
     590    // Check for 0x prefix here, because toDouble allows it, but we must treat it as 0.
     591    // Need to skip any whitespace and then one + or - sign.
    589592    int length = s.size();
    590593    int p = 0;
    591 
    592     // Skip whitespace.
    593594    while (p < length && isStrWhiteSpace(s[p].uc)) {
    594595        ++p;
    595596    }
    596 
    597     // Check for 0x numbers here, because toDouble allows them, but we must not.
     597    if (p < length && (s[p] == '+' || s[p] == '-')) {
     598        ++p;
     599    }
    598600    if (length - p >= 2 && s[p] == '0' && (s[p + 1] == 'x' || s[p + 1] == 'X')) {
    599         return NaN;
    600     }
    601 
    602     return s.substr(p).toDouble( true /*tolerant*/, false /* NaN for empty string */ );
     601        return 0;
     602    }
     603
     604    return s.toDouble( true /*tolerant*/, false /* NaN for empty string */ );
    603605}
    604606
Note: See TracChangeset for help on using the changeset viewer.