Changeset 65344 in webkit for trunk/JavaScriptCore/runtime
- Timestamp:
- Aug 13, 2010, 6:28:27 PM (15 years ago)
- Location:
- trunk/JavaScriptCore/runtime
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/Identifier.h
r65305 r65344 51 51 int length() const { return m_string.length(); } 52 52 53 const char*ascii() const { return m_string.ascii(); }53 CString ascii() const { return m_string.ascii(); } 54 54 55 55 static Identifier from(ExecState* exec, unsigned y); -
trunk/JavaScriptCore/runtime/ScopeChain.cpp
r48774 r65344 44 44 for (PropertyNameArray::const_iterator propIter = propertyNames.begin(); propIter != propEnd; propIter++) { 45 45 Identifier name = *propIter; 46 fprintf(stderr, "%s, ", name. ascii());46 fprintf(stderr, "%s, ", name.ustring().utf8().data()); 47 47 } 48 48 fprintf(stderr, "\n"); -
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) -
trunk/JavaScriptCore/runtime/UString.h
r65305 r65344 88 88 } 89 89 90 CString ascii() const; 91 CString latin1() const; 90 92 CString utf8(bool strict = false) const; 91 93 … … 120 122 121 123 UString substr(unsigned pos = 0, unsigned len = 0xFFFFFFFF) const; 122 123 // NOTE: This method should only be used for *debugging* purposes as it124 // is neither Unicode safe nor free from side effects nor thread-safe.125 char* ascii() const;126 124 127 125 private:
Note:
See TracChangeset
for help on using the changeset viewer.