| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 private: | 67 private: |
| 68 unsigned size_; | 68 unsigned size_; |
| 69 char* space_; | 69 char* space_; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 | 72 |
| 73 class FmtElm { | 73 class FmtElm { |
| 74 public: | 74 public: |
| 75 FmtElm(int value) : type_(INT) { data_.u_int_ = value; } // NOLINT | 75 FmtElm(int value) : type_(INT) { data_.u_int_ = value; } // NOLINT |
| 76 FmtElm(const char* value) : type_(C_STR) { data_.u_c_str_ = value; } // NOLIN
T | 76 FmtElm(const char* value) : type_(C_STR) { data_.u_c_str_ = value; } // NOLIN
T |
| 77 FmtElm(const Vector<const uc16>& value) : type_(LC_STR) { data_.u_lc_str_ = &v
alue; } // NOLINT |
| 77 FmtElm(Object* value) : type_(OBJ) { data_.u_obj_ = value; } // NOLINT | 78 FmtElm(Object* value) : type_(OBJ) { data_.u_obj_ = value; } // NOLINT |
| 78 FmtElm(Handle<Object> value) : type_(HANDLE) { data_.u_handle_ = value.locatio
n(); } // NOLINT | 79 FmtElm(Handle<Object> value) : type_(HANDLE) { data_.u_handle_ = value.locatio
n(); } // NOLINT |
| 79 FmtElm(void* value) : type_(INT) { data_.u_int_ = reinterpret_cast<int>(value)
; } // NOLINT | 80 FmtElm(void* value) : type_(INT) { data_.u_int_ = reinterpret_cast<int>(value)
; } // NOLINT |
| 80 private: | 81 private: |
| 81 friend class StringStream; | 82 friend class StringStream; |
| 82 enum Type { INT, C_STR, OBJ, HANDLE }; | 83 enum Type { INT, C_STR, LC_STR, OBJ, HANDLE }; |
| 83 Type type_; | 84 Type type_; |
| 84 union { | 85 union { |
| 85 int u_int_; | 86 int u_int_; |
| 86 const char* u_c_str_; | 87 const char* u_c_str_; |
| 88 const Vector<const uc16>* u_lc_str_; |
| 87 Object* u_obj_; | 89 Object* u_obj_; |
| 88 Object** u_handle_; | 90 Object** u_handle_; |
| 89 } data_; | 91 } data_; |
| 90 }; | 92 }; |
| 91 | 93 |
| 92 | 94 |
| 93 class StringStream { | 95 class StringStream { |
| 94 public: | 96 public: |
| 95 explicit StringStream(StringAllocator* allocator): | 97 explicit StringStream(StringAllocator* allocator): |
| 96 allocator_(allocator), | 98 allocator_(allocator), |
| 97 capacity_(kInitialCapacity), | 99 capacity_(kInitialCapacity), |
| 98 length_(0), | 100 length_(0), |
| 99 buffer_(allocator_->allocate(kInitialCapacity)) { | 101 buffer_(allocator_->allocate(kInitialCapacity)) { |
| 100 buffer_[0] = 0; | 102 buffer_[0] = 0; |
| 101 } | 103 } |
| 102 | 104 |
| 103 ~StringStream() { | 105 ~StringStream() { |
| 104 } | 106 } |
| 105 | 107 |
| 106 bool Put(char c); | 108 bool Put(char c); |
| 107 bool Put(String* str); | 109 bool Put(String* str); |
| 108 bool Put(String* str, int start, int end); | 110 bool Put(String* str, int start, int end); |
| 109 void Add(const char* format, Vector<FmtElm> elms); | 111 void Add(Vector<const char> format, Vector<FmtElm> elms); |
| 110 void Add(const char* format); | 112 void Add(const char* format); |
| 113 void Add(Vector<const char> format); |
| 111 void Add(const char* format, FmtElm arg0); | 114 void Add(const char* format, FmtElm arg0); |
| 112 void Add(const char* format, FmtElm arg0, FmtElm arg1); | 115 void Add(const char* format, FmtElm arg0, FmtElm arg1); |
| 113 void Add(const char* format, FmtElm arg0, FmtElm arg1, FmtElm arg2); | 116 void Add(const char* format, FmtElm arg0, FmtElm arg1, FmtElm arg2); |
| 114 | 117 |
| 115 // Getting the message out. | 118 // Getting the message out. |
| 116 void OutputToStdOut(); | 119 void OutputToStdOut(); |
| 117 void Log(); | 120 void Log(); |
| 118 Handle<String> ToString(); | 121 Handle<String> ToString(); |
| 119 SmartPointer<char> ToCString(); | 122 SmartPointer<char> ToCString(); |
| 120 | 123 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 int space() const { return capacity_ - length_; } | 158 int space() const { return capacity_ - length_; } |
| 156 char* cursor() const { return buffer_ + length_; } | 159 char* cursor() const { return buffer_ + length_; } |
| 157 | 160 |
| 158 DISALLOW_IMPLICIT_CONSTRUCTORS(StringStream); | 161 DISALLOW_IMPLICIT_CONSTRUCTORS(StringStream); |
| 159 }; | 162 }; |
| 160 | 163 |
| 161 | 164 |
| 162 } } // namespace v8::internal | 165 } } // namespace v8::internal |
| 163 | 166 |
| 164 #endif // V8_STRING_STREAM_H_ | 167 #endif // V8_STRING_STREAM_H_ |
| OLD | NEW |