Changeset 798 in webkit for trunk/JavaScriptCore/kjs/ustring.cpp


Ignore:
Timestamp:
Mar 21, 2002, 4:31:57 PM (23 years ago)
Author:
mjs
Message:

Merged changes from LABYRINTH_KDE_3_MERGE branch.

File:
1 edited

Legend:

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

    r6 r798  
     1// -*- c-basic-offset: 2 -*-
    12/*
    23 *  This file is part of the KDE libraries
     
    1718 *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    1819 *  Boston, MA 02111-1307, USA.
     20 *
     21 *  $Id$
    1922 */
    2023
     
    3538#include "ustring.h"
    3639#include "operations.h"
     40#include <math.h>
    3741
    3842namespace KJS {
     
    122126
    123127UChar::UChar(const UCharReference &c)
    124 #ifdef KJS_SWAPPED_CHAR
    125   : lo(c.low()), hi(c.high())
    126 #else
    127   : hi(c.high()), lo(c.low())
    128 #endif
     128    : uc( c.unicode() )
    129129{
    130130}
     
    132132UChar UChar::toLower() const
    133133{
    134   if (islower(lo) && hi == 0)
     134  // ### properly supprot unicode tolower
     135  if (uc >= 256 || islower(uc))
    135136    return *this;
    136137
    137   return UChar(0, tolower(lo));
     138  return UChar(tolower(uc));
    138139}
    139140
    140141UChar UChar::toUpper() const
    141142{
    142   if (isupper(lo) && hi == 0)
     143  if (uc >= 256 || isupper(uc))
    143144    return *this;
    144145
    145   return UChar(0, toupper(lo));
     146  return UChar(toupper(uc));
    146147}
    147148
     
    237238{
    238239  char buf[40];
    239   sprintf(buf, "%.16g", d);     // does the right thing
     240
     241  if (d == -0)
     242    strcpy(buf,"0");
     243  else if (KJS::isNaN(d))
     244    strcpy(buf,"NaN");
     245  else if (KJS::isPosInf(d))
     246    strcpy(buf,"Infinity");
     247  else if (KJS::isNegInf(d))
     248    strcpy(buf,"-Infinity");
     249  else
     250    sprintf(buf, "%.16g", d);   // does the right thing
     251
     252  // ECMA 3rd ed. 9.8.1 9 e: "with no leading zeros"
     253  int buflen = strlen(buf);
     254  if (buflen >= 4 && buf[buflen-4] == 'e' && buf[buflen-2] == '0') {
     255    buf[buflen-2] = buf[buflen-1];
     256    buf[buflen-1] = 0;
     257  }
     258
    240259  return UString(buf);
    241260}
     
    265284  statBuffer = new char[size()+1];
    266285  for(int i = 0; i < size(); i++)
    267     statBuffer[i] = data()[i].lo;
     286    statBuffer[i] = data()[i].low();
    268287  statBuffer[size()] = '\0';
    269288
     
    277296  UChar *d = new UChar[l];
    278297  for (int i = 0; i < l; i++)
    279     d[i].lo = c[i];
     298    d[i].uc = c[i];
    280299  rep = Rep::create(d, l);
    281300
     
    287306  str.rep->ref();
    288307  release();
    289   rep = str.rep; 
     308  rep = str.rep;
    290309
    291310  return *this;
     
    301320  const UChar *u = data();
    302321  for(int i = 0; i < size(); i++, u++)
    303     if (u->hi)
     322    if (u->uc > 0xFF)
    304323      return false;
    305324
     
    321340}
    322341
    323 double UString::toDouble() const
     342double UString::toDouble( bool tolerant ) const
    324343{
    325344  double d;
     
    355374    char *end;
    356375    d = strtod(c, &end);
    357     if (d != 0.0 || end != c) {
     376    if ((d != 0.0 || end != c) && d != HUGE_VAL && d != -HUGE_VAL) {
    358377      c = end;
    359378    } else {
     
    376395  while (isspace(*c))
    377396    c++;
    378   if (*c != '\0')
     397  // don't allow anything after - unless tolerant=true
     398  if ( !tolerant && *c != '\0')
    379399    d = NaN;
    380400
     
    474494}
    475495
    476 bool KJS::operator==(const UChar &c1, const UChar &c2)
    477 {
    478   return ((c1.lo == c2.lo) & (c1.hi == c2.hi));
    479 }
    480 
    481496bool KJS::operator==(const UString& s1, const UString& s2)
    482497{
     
    498513  const UChar *u = s1.data();
    499514  while (*s2) {
    500     if (u->lo != *s2 || u->hi != 0)
     515    if (u->uc != *s2 )
    501516      return false;
    502517    s2++;
     
    505520
    506521  return true;
    507 }
    508 
    509 bool KJS::operator==(const char *s1, const UString& s2)
    510 {
    511   return operator==(s2, s1);
    512522}
    513523
Note: See TracChangeset for help on using the changeset viewer.