Changeset 798 in webkit for trunk/JavaScriptCore/kjs/ustring.cpp
- Timestamp:
- Mar 21, 2002, 4:31:57 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/ustring.cpp
r6 r798 1 // -*- c-basic-offset: 2 -*- 1 2 /* 2 3 * This file is part of the KDE libraries … … 17 18 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 19 * Boston, MA 02111-1307, USA. 20 * 21 * $Id$ 19 22 */ 20 23 … … 35 38 #include "ustring.h" 36 39 #include "operations.h" 40 #include <math.h> 37 41 38 42 namespace KJS { … … 122 126 123 127 UChar::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() ) 129 129 { 130 130 } … … 132 132 UChar UChar::toLower() const 133 133 { 134 if (islower(lo) && hi == 0) 134 // ### properly supprot unicode tolower 135 if (uc >= 256 || islower(uc)) 135 136 return *this; 136 137 137 return UChar( 0, tolower(lo));138 return UChar(tolower(uc)); 138 139 } 139 140 140 141 UChar UChar::toUpper() const 141 142 { 142 if ( isupper(lo) && hi == 0)143 if (uc >= 256 || isupper(uc)) 143 144 return *this; 144 145 145 return UChar( 0, toupper(lo));146 return UChar(toupper(uc)); 146 147 } 147 148 … … 237 238 { 238 239 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 240 259 return UString(buf); 241 260 } … … 265 284 statBuffer = new char[size()+1]; 266 285 for(int i = 0; i < size(); i++) 267 statBuffer[i] = data()[i].lo ;286 statBuffer[i] = data()[i].low(); 268 287 statBuffer[size()] = '\0'; 269 288 … … 277 296 UChar *d = new UChar[l]; 278 297 for (int i = 0; i < l; i++) 279 d[i]. lo= c[i];298 d[i].uc = c[i]; 280 299 rep = Rep::create(d, l); 281 300 … … 287 306 str.rep->ref(); 288 307 release(); 289 rep = str.rep; 308 rep = str.rep; 290 309 291 310 return *this; … … 301 320 const UChar *u = data(); 302 321 for(int i = 0; i < size(); i++, u++) 303 if (u-> hi)322 if (u->uc > 0xFF) 304 323 return false; 305 324 … … 321 340 } 322 341 323 double UString::toDouble( ) const342 double UString::toDouble( bool tolerant ) const 324 343 { 325 344 double d; … … 355 374 char *end; 356 375 d = strtod(c, &end); 357 if ( d != 0.0 || end != c) {376 if ((d != 0.0 || end != c) && d != HUGE_VAL && d != -HUGE_VAL) { 358 377 c = end; 359 378 } else { … … 376 395 while (isspace(*c)) 377 396 c++; 378 if (*c != '\0') 397 // don't allow anything after - unless tolerant=true 398 if ( !tolerant && *c != '\0') 379 399 d = NaN; 380 400 … … 474 494 } 475 495 476 bool KJS::operator==(const UChar &c1, const UChar &c2)477 {478 return ((c1.lo == c2.lo) & (c1.hi == c2.hi));479 }480 481 496 bool KJS::operator==(const UString& s1, const UString& s2) 482 497 { … … 498 513 const UChar *u = s1.data(); 499 514 while (*s2) { 500 if (u-> lo != *s2 || u->hi != 0)515 if (u->uc != *s2 ) 501 516 return false; 502 517 s2++; … … 505 520 506 521 return true; 507 }508 509 bool KJS::operator==(const char *s1, const UString& s2)510 {511 return operator==(s2, s1);512 522 } 513 523
Note:
See TracChangeset
for help on using the changeset viewer.