Changeset 65344 in webkit for trunk/JavaScriptCore/runtime/UString.cpp
- Timestamp:
- Aug 13, 2010, 6:28:27 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/UString.cpp
r65305 r65344 205 205 } 206 206 207 char* UString::ascii() const208 {209 static char* asciiBuffer = 0;210 211 unsigned len = length();212 unsigned neededSize = len + 1;213 delete[] asciiBuffer;214 asciiBuffer = new char[neededSize];215 216 const UChar* p = characters();217 char* q = asciiBuffer;218 const UChar* limit = p + len;219 while (p != limit) {220 *q = static_cast<char>(p[0]);221 ++p;222 ++q;223 }224 *q = '\0';225 226 return asciiBuffer;227 }228 229 207 static inline bool isInfinity(double number) 230 208 { … … 584 562 } 585 563 564 CString UString::ascii() const 565 { 566 // Basic Latin1 (ISO) encoding - Unicode characters 0..255 are 567 // preserved, characters outside of this range are converted to '?'. 568 569 unsigned length = this->length(); 570 const UChar* characters = this->characters(); 571 572 char* characterBuffer; 573 CString result = CString::newUninitialized(length, characterBuffer); 574 575 for (unsigned i = 0; i < length; ++i) { 576 UChar ch = characters[i]; 577 characterBuffer[i] = ch && (ch < 0x20 || ch >= 0x7f) ? '?' : ch; 578 } 579 580 return result; 581 } 582 583 CString UString::latin1() const 584 { 585 // Basic Latin1 (ISO) encoding - Unicode characters 0..255 are 586 // preserved, characters outside of this range are converted to '?'. 587 588 unsigned length = this->length(); 589 const UChar* characters = this->characters(); 590 591 char* characterBuffer; 592 CString result = CString::newUninitialized(length, characterBuffer); 593 594 for (unsigned i = 0; i < length; ++i) { 595 UChar ch = characters[i]; 596 characterBuffer[i] = ch > 0xff ? '?' : ch; 597 } 598 599 return result; 600 } 601 586 602 // Helper to write a three-byte UTF-8 code point to the buffer, caller must check room is available. 587 603 static inline void putUTF8Triple(char*& buffer, UChar ch)
Note:
See TracChangeset
for help on using the changeset viewer.