Changeset 55093 in webkit for trunk/JavaScriptCore/runtime/JSStringBuilder.h
- Timestamp:
- Feb 22, 2010, 11:12:01 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/JSStringBuilder.h
r54571 r55093 29 29 #include "ExceptionHelpers.h" 30 30 #include "JSString.h" 31 #include " StringBuilder.h"31 #include "Vector.h" 32 32 33 33 namespace JSC { 34 34 35 class JSStringBuilder : public StringBuilder{35 class JSStringBuilder { 36 36 public: 37 JSStringBuilder() 38 : m_okay(true) 39 { 40 } 41 42 void append(const UChar u) 43 { 44 m_okay &= buffer.tryAppend(&u, 1); 45 } 46 47 void append(const char* str) 48 { 49 append(str, strlen(str)); 50 } 51 52 void append(const char* str, size_t len) 53 { 54 m_okay &= buffer.tryReserveCapacity(buffer.size() + len); 55 for (size_t i = 0; i < len; i++) { 56 UChar u = static_cast<unsigned char>(str[i]); 57 m_okay &= buffer.tryAppend(&u, 1); 58 } 59 } 60 61 void append(const UChar* str, size_t len) 62 { 63 m_okay &= buffer.tryAppend(str, len); 64 } 65 66 void append(const UString& str) 67 { 68 m_okay &= buffer.tryAppend(str.data(), str.size()); 69 } 70 37 71 JSValue build(ExecState* exec) 38 72 { 73 if (!m_okay) 74 return throwOutOfMemoryError(exec); 39 75 buffer.shrinkToFit(); 40 76 if (!buffer.data()) … … 43 79 } 44 80 45 private: 46 // Make attempts to call this compile error - if you only wanted a UString, 47 // Why didn't you just use a StringBuilder?! (This may change, maybe at some 48 // point in the future we'll need to start building a string not knowing whether 49 // we'll want a UString or a JSValue - but until we have this requirement, 50 // block this). 51 UString build() 52 { 53 ASSERT_NOT_REACHED(); 54 return StringBuilder::build(); 55 } 81 protected: 82 Vector<UChar, 64> buffer; 83 bool m_okay; 56 84 }; 57 85
Note:
See TracChangeset
for help on using the changeset viewer.