Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: src/string-stream.cc

Issue 12427: Merge regexp2000 back into bleeding_edge (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 switch (c) { 86 switch (c) {
87 case '0': case '1': case '2': case '3': case '4': case '5': 87 case '0': case '1': case '2': case '3': case '4': case '5':
88 case '6': case '7': case '8': case '9': case '.': case '-': 88 case '6': case '7': case '8': case '9': case '.': case '-':
89 return true; 89 return true;
90 default: 90 default:
91 return false; 91 return false;
92 } 92 }
93 } 93 }
94 94
95 95
96 void StringStream::Add(const char* format, Vector<FmtElm> elms) { 96 void StringStream::Add(Vector<const char> format, Vector<FmtElm> elms) {
97 // If we already ran out of space then return immediately. 97 // If we already ran out of space then return immediately.
98 if (space() == 0) 98 if (space() == 0)
99 return; 99 return;
100 int offset = 0; 100 int offset = 0;
101 int elm = 0; 101 int elm = 0;
102 while (format[offset] != '\0') { 102 while (offset < format.length()) {
103 if (format[offset] != '%' || elm == elms.length()) { 103 if (format[offset] != '%' || elm == elms.length()) {
104 Put(format[offset]); 104 Put(format[offset]);
105 offset++; 105 offset++;
106 continue; 106 continue;
107 } 107 }
108 // Read this formatting directive into a temporary buffer 108 // Read this formatting directive into a temporary buffer
109 EmbeddedVector<char, 24> temp; 109 EmbeddedVector<char, 24> temp;
110 int format_length = 0; 110 int format_length = 0;
111 // Skip over the whole control character sequence until the 111 // Skip over the whole control character sequence until the
112 // format element type 112 // format element type
113 temp[format_length++] = format[offset++]; 113 temp[format_length++] = format[offset++];
114 // '\0' is not a control character so we don't have to 114 while (offset < format.length() && IsControlChar(format[offset]))
115 // explicitly check for the end of the string
116 while (IsControlChar(format[offset]))
117 temp[format_length++] = format[offset++]; 115 temp[format_length++] = format[offset++];
116 if (offset >= format.length())
117 return;
118 char type = format[offset]; 118 char type = format[offset];
119 if (type == '\0') return;
120 temp[format_length++] = type; 119 temp[format_length++] = type;
121 temp[format_length] = '\0'; 120 temp[format_length] = '\0';
122 offset++; 121 offset++;
123 FmtElm current = elms[elm++]; 122 FmtElm current = elms[elm++];
124 switch (type) { 123 switch (type) {
125 case 's': { 124 case 's': {
126 ASSERT_EQ(FmtElm::C_STR, current.type_); 125 ASSERT_EQ(FmtElm::C_STR, current.type_);
127 const char* value = current.data_.u_c_str_; 126 const char* value = current.data_.u_c_str_;
128 Add(value); 127 Add(value);
129 break; 128 break;
130 } 129 }
130 case 'w': {
131 ASSERT_EQ(FmtElm::LC_STR, current.type_);
132 Vector<const uc16> value = *current.data_.u_lc_str_;
133 for (int i = 0; i < value.length(); i++)
134 Put(static_cast<char>(value[i]));
135 break;
136 }
131 case 'o': { 137 case 'o': {
132 ASSERT_EQ(FmtElm::OBJ, current.type_); 138 ASSERT_EQ(FmtElm::OBJ, current.type_);
133 Object* obj = current.data_.u_obj_; 139 Object* obj = current.data_.u_obj_;
134 PrintObject(obj); 140 PrintObject(obj);
135 break; 141 break;
136 } 142 }
137 case 'i': case 'd': case 'u': case 'x': case 'c': case 'p': { 143 case 'k': {
144 ASSERT_EQ(FmtElm::INT, current.type_);
145 int value = current.data_.u_int_;
146 if (0x20 <= value && value <= 0x7F) {
147 Put(value);
148 } else if (value <= 0xff) {
149 Add("\\x%02x", value);
150 } else {
151 Add("\\u%04x", value);
152 }
153 break;
154 }
155 case 'i': case 'd': case 'u': case 'x': case 'c': case 'p': case 'X': {
138 int value = current.data_.u_int_; 156 int value = current.data_.u_int_;
139 EmbeddedVector<char, 24> formatted; 157 EmbeddedVector<char, 24> formatted;
140 OS::SNPrintF(formatted, temp.start(), value); 158 int length = OS::SNPrintF(formatted, temp.start(), value);
141 Add(formatted.start()); 159 Add(Vector<const char>(formatted.start(), length));
142 break; 160 break;
143 } 161 }
144 case 'f': case 'g': case 'G': case 'e': case 'E': { 162 case 'f': case 'g': case 'G': case 'e': case 'E': {
145 double value = current.data_.u_double_; 163 double value = current.data_.u_double_;
146 EmbeddedVector<char, 28> formatted; 164 EmbeddedVector<char, 28> formatted;
147 OS::SNPrintF(formatted, temp.start(), value); 165 OS::SNPrintF(formatted, temp.start(), value);
148 Add(formatted.start()); 166 Add(formatted.start());
149 break; 167 break;
150 } 168 }
151 default: 169 default:
152 UNREACHABLE(); 170 UNREACHABLE();
153 break; 171 break;
154 } 172 }
155 } 173 }
156 174
157 // Verify that the buffer is 0-terminated and doesn't contain any 175 // Verify that the buffer is 0-terminated
158 // other 0-characters.
159 ASSERT(buffer_[length_] == '\0'); 176 ASSERT(buffer_[length_] == '\0');
160 ASSERT(strlen(buffer_) == length_);
161 } 177 }
162 178
163 179
164 void StringStream::PrintObject(Object* o) { 180 void StringStream::PrintObject(Object* o) {
165 o->ShortPrint(this); 181 o->ShortPrint(this);
166 if (o->IsString()) { 182 if (o->IsString()) {
167 if (String::cast(o)->length() <= String::kMaxMediumStringSize) { 183 if (String::cast(o)->length() <= String::kMaxMediumStringSize) {
168 return; 184 return;
169 } 185 }
170 } else if (o->IsNumber() || o->IsOddball()) { 186 } else if (o->IsNumber() || o->IsOddball()) {
(...skipping 10 matching lines...) Expand all
181 Add("#%d#", debug_object_cache->length()); 197 Add("#%d#", debug_object_cache->length());
182 debug_object_cache->Add(HeapObject::cast(o)); 198 debug_object_cache->Add(HeapObject::cast(o));
183 } else { 199 } else {
184 Add("@%p", o); 200 Add("@%p", o);
185 } 201 }
186 } 202 }
187 } 203 }
188 204
189 205
190 void StringStream::Add(const char* format) { 206 void StringStream::Add(const char* format) {
207 Add(CStrVector(format));
208 }
209
210
211 void StringStream::Add(Vector<const char> format) {
191 Add(format, Vector<FmtElm>::empty()); 212 Add(format, Vector<FmtElm>::empty());
192 } 213 }
193 214
194 215
195 void StringStream::Add(const char* format, FmtElm arg0) { 216 void StringStream::Add(const char* format, FmtElm arg0) {
196 const char argc = 1; 217 const char argc = 1;
197 FmtElm argv[argc] = { arg0 }; 218 FmtElm argv[argc] = { arg0 };
198 Add(format, Vector<FmtElm>(argv, argc)); 219 Add(CStrVector(format), Vector<FmtElm>(argv, argc));
199 } 220 }
200 221
201 222
202 void StringStream::Add(const char* format, FmtElm arg0, FmtElm arg1) { 223 void StringStream::Add(const char* format, FmtElm arg0, FmtElm arg1) {
203 const char argc = 2; 224 const char argc = 2;
204 FmtElm argv[argc] = { arg0, arg1 }; 225 FmtElm argv[argc] = { arg0, arg1 };
205 Add(format, Vector<FmtElm>(argv, argc)); 226 Add(CStrVector(format), Vector<FmtElm>(argv, argc));
206 } 227 }
207 228
208 229
209 void StringStream::Add(const char* format, FmtElm arg0, FmtElm arg1, 230 void StringStream::Add(const char* format, FmtElm arg0, FmtElm arg1,
210 FmtElm arg2) { 231 FmtElm arg2) {
211 const char argc = 3; 232 const char argc = 3;
212 FmtElm argv[argc] = { arg0, arg1, arg2 }; 233 FmtElm argv[argc] = { arg0, arg1, arg2 };
213 Add(format, Vector<FmtElm>(argv, argc)); 234 Add(CStrVector(format), Vector<FmtElm>(argv, argc));
235 }
236
237
238 void StringStream::Add(const char* format, FmtElm arg0, FmtElm arg1,
239 FmtElm arg2, FmtElm arg3) {
240 const char argc = 4;
241 FmtElm argv[argc] = { arg0, arg1, arg2, arg3 };
242 Add(CStrVector(format), Vector<FmtElm>(argv, argc));
214 } 243 }
215 244
216 245
217 SmartPointer<const char> StringStream::ToCString() { 246 SmartPointer<const char> StringStream::ToCString() {
218 char* str = NewArray<char>(length_ + 1); 247 char* str = NewArray<char>(length_ + 1);
219 memcpy(str, buffer_, length_); 248 memcpy(str, buffer_, length_);
220 str[length_] = '\0'; 249 str[length_] = '\0';
221 return SmartPointer<const char>(str); 250 return SmartPointer<const char>(str);
222 } 251 }
223 252
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 unsigned new_bytes = *bytes * 2; 568 unsigned new_bytes = *bytes * 2;
540 if (new_bytes > size_) { 569 if (new_bytes > size_) {
541 new_bytes = size_; 570 new_bytes = size_;
542 } 571 }
543 *bytes = new_bytes; 572 *bytes = new_bytes;
544 return space_; 573 return space_;
545 } 574 }
546 575
547 576
548 } } // namespace v8::internal 577 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698