Ignore:
Timestamp:
Aug 26, 2010, 3:22:33 PM (15 years ago)
Author:
[email protected]
Message:

Bug 44655 - Add debug only convenience methods to obtain a Vector<char> from a String/StringImpl.

Reviewed by Brady Eidson.

  • wtf/text/WTFString.cpp:

(asciiDebug):

Return a Vector<char> containing the contents of a string as ASCII.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/text/WTFString.cpp

    r65959 r66142  
    986986
    987987#ifndef NDEBUG
    988 // For use in the debugger - leaks memory
     988// For use in the debugger
    989989String* string(const char*);
     990Vector<char> asciiDebug(StringImpl* impl);
     991Vector<char> asciiDebug(String& string);
    990992
    991993String* string(const char* s)
    992994{
     995    // leaks memory!
    993996    return new String(s);
    994997}
     998
     999Vector<char> asciiDebug(StringImpl* impl)
     1000{
     1001    if (!impl)
     1002        return asciiDebug(String("[null]").impl());
     1003
     1004    Vector<char> buffer;
     1005    unsigned length = impl->length();
     1006    const UChar* characters = impl->characters();
     1007
     1008    buffer.resize(length);
     1009    for (unsigned i = 0; i < length; ++i) {
     1010        UChar ch = characters[i];
     1011        buffer[i] = ch && (ch < 0x20 || ch > 0x7f) ? '?' : ch;
     1012    }
     1013
     1014    return buffer;
     1015}
     1016
     1017Vector<char> asciiDebug(String& string)
     1018{
     1019    return asciiDebug(string.impl());
     1020}
     1021
    9951022#endif
Note: See TracChangeset for help on using the changeset viewer.