| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 212 |
| 213 int WriteBytes(const char* filename, | 213 int WriteBytes(const char* filename, |
| 214 const byte* bytes, | 214 const byte* bytes, |
| 215 int size, | 215 int size, |
| 216 bool verbose) { | 216 bool verbose) { |
| 217 const char* str = reinterpret_cast<const char*>(bytes); | 217 const char* str = reinterpret_cast<const char*>(bytes); |
| 218 return WriteChars(filename, str, size, verbose); | 218 return WriteChars(filename, str, size, verbose); |
| 219 } | 219 } |
| 220 | 220 |
| 221 | 221 |
| 222 StringBuilder::StringBuilder(int size) { | |
| 223 buffer_ = Vector<char>::New(size); | |
| 224 position_ = 0; | |
| 225 } | |
| 226 | |
| 227 | |
| 228 void StringBuilder::AddString(const char* s) { | |
| 229 AddSubstring(s, StrLength(s)); | |
| 230 } | |
| 231 | |
| 232 | |
| 233 void StringBuilder::AddSubstring(const char* s, int n) { | |
| 234 ASSERT(!is_finalized() && position_ + n < buffer_.length()); | |
| 235 ASSERT(static_cast<size_t>(n) <= strlen(s)); | |
| 236 memcpy(&buffer_[position_], s, n * kCharSize); | |
| 237 position_ += n; | |
| 238 } | |
| 239 | |
| 240 | 222 |
| 241 void StringBuilder::AddFormatted(const char* format, ...) { | 223 void StringBuilder::AddFormatted(const char* format, ...) { |
| 242 va_list arguments; | 224 va_list arguments; |
| 243 va_start(arguments, format); | 225 va_start(arguments, format); |
| 244 AddFormattedList(format, arguments); | 226 AddFormattedList(format, arguments); |
| 245 va_end(arguments); | 227 va_end(arguments); |
| 246 } | 228 } |
| 247 | 229 |
| 248 | 230 |
| 249 void StringBuilder::AddFormattedList(const char* format, va_list list) { | 231 void StringBuilder::AddFormattedList(const char* format, va_list list) { |
| 250 ASSERT(!is_finalized() && position_ < buffer_.length()); | 232 ASSERT(!is_finalized() && position_ < buffer_.length()); |
| 251 int n = OS::VSNPrintF(buffer_ + position_, format, list); | 233 int n = OS::VSNPrintF(buffer_ + position_, format, list); |
| 252 if (n < 0 || n >= (buffer_.length() - position_)) { | 234 if (n < 0 || n >= (buffer_.length() - position_)) { |
| 253 position_ = buffer_.length(); | 235 position_ = buffer_.length(); |
| 254 } else { | 236 } else { |
| 255 position_ += n; | 237 position_ += n; |
| 256 } | 238 } |
| 257 } | 239 } |
| 258 | 240 |
| 259 | 241 |
| 260 void StringBuilder::AddPadding(char c, int count) { | |
| 261 for (int i = 0; i < count; i++) { | |
| 262 AddCharacter(c); | |
| 263 } | |
| 264 } | |
| 265 | |
| 266 | |
| 267 char* StringBuilder::Finalize() { | |
| 268 ASSERT(!is_finalized() && position_ < buffer_.length()); | |
| 269 buffer_[position_] = '\0'; | |
| 270 // Make sure nobody managed to add a 0-character to the | |
| 271 // buffer while building the string. | |
| 272 ASSERT(strlen(buffer_.start()) == static_cast<size_t>(position_)); | |
| 273 position_ = -1; | |
| 274 ASSERT(is_finalized()); | |
| 275 return buffer_.start(); | |
| 276 } | |
| 277 | |
| 278 | |
| 279 MemoryMappedExternalResource::MemoryMappedExternalResource(const char* filename) | 242 MemoryMappedExternalResource::MemoryMappedExternalResource(const char* filename) |
| 280 : filename_(NULL), | 243 : filename_(NULL), |
| 281 data_(NULL), | 244 data_(NULL), |
| 282 length_(0), | 245 length_(0), |
| 283 remove_file_on_cleanup_(false) { | 246 remove_file_on_cleanup_(false) { |
| 284 Init(filename); | 247 Init(filename); |
| 285 } | 248 } |
| 286 | 249 |
| 287 | 250 |
| 288 MemoryMappedExternalResource:: | 251 MemoryMappedExternalResource:: |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 start_of_line = p; | 325 start_of_line = p; |
| 363 line_no++; | 326 line_no++; |
| 364 } | 327 } |
| 365 } | 328 } |
| 366 | 329 |
| 367 return is_ascii; | 330 return is_ascii; |
| 368 } | 331 } |
| 369 | 332 |
| 370 | 333 |
| 371 } } // namespace v8::internal | 334 } } // namespace v8::internal |
| OLD | NEW |