| OLD | NEW |
| 1 // Copyright 2011 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. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include <stdarg.h> | 28 #include <stdarg.h> |
| 29 #include <sys/stat.h> | |
| 30 | 29 |
| 31 #include "v8.h" | 30 #include "v8.h" |
| 32 | 31 |
| 33 #include "checks.h" | |
| 34 #include "platform.h" | 32 #include "platform.h" |
| 35 #include "utils.h" | 33 |
| 34 #include "sys/stat.h" |
| 36 | 35 |
| 37 namespace v8 { | 36 namespace v8 { |
| 38 namespace internal { | 37 namespace internal { |
| 39 | 38 |
| 40 | 39 |
| 41 SimpleStringBuilder::SimpleStringBuilder(int size) { | |
| 42 buffer_ = Vector<char>::New(size); | |
| 43 position_ = 0; | |
| 44 } | |
| 45 | |
| 46 | |
| 47 void SimpleStringBuilder::AddString(const char* s) { | |
| 48 AddSubstring(s, StrLength(s)); | |
| 49 } | |
| 50 | |
| 51 | |
| 52 void SimpleStringBuilder::AddSubstring(const char* s, int n) { | |
| 53 ASSERT(!is_finalized() && position_ + n <= buffer_.length()); | |
| 54 ASSERT(static_cast<size_t>(n) <= strlen(s)); | |
| 55 OS::MemCopy(&buffer_[position_], s, n * kCharSize); | |
| 56 position_ += n; | |
| 57 } | |
| 58 | |
| 59 | |
| 60 void SimpleStringBuilder::AddPadding(char c, int count) { | |
| 61 for (int i = 0; i < count; i++) { | |
| 62 AddCharacter(c); | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 | |
| 67 void SimpleStringBuilder::AddDecimalInteger(int32_t value) { | |
| 68 uint32_t number = static_cast<uint32_t>(value); | |
| 69 if (value < 0) { | |
| 70 AddCharacter('-'); | |
| 71 number = static_cast<uint32_t>(-value); | |
| 72 } | |
| 73 int digits = 1; | |
| 74 for (uint32_t factor = 10; digits < 10; digits++, factor *= 10) { | |
| 75 if (factor > number) break; | |
| 76 } | |
| 77 position_ += digits; | |
| 78 for (int i = 1; i <= digits; i++) { | |
| 79 buffer_[position_ - i] = '0' + static_cast<char>(number % 10); | |
| 80 number /= 10; | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 | |
| 85 char* SimpleStringBuilder::Finalize() { | |
| 86 ASSERT(!is_finalized() && position_ <= buffer_.length()); | |
| 87 // If there is no space for null termination, overwrite last character. | |
| 88 if (position_ == buffer_.length()) { | |
| 89 position_--; | |
| 90 // Print ellipsis. | |
| 91 for (int i = 3; i > 0 && position_ > i; --i) buffer_[position_ - i] = '.'; | |
| 92 } | |
| 93 buffer_[position_] = '\0'; | |
| 94 // Make sure nobody managed to add a 0-character to the | |
| 95 // buffer while building the string. | |
| 96 ASSERT(strlen(buffer_.start()) == static_cast<size_t>(position_)); | |
| 97 position_ = -1; | |
| 98 ASSERT(is_finalized()); | |
| 99 return buffer_.start(); | |
| 100 } | |
| 101 | |
| 102 | |
| 103 void PrintF(const char* format, ...) { | 40 void PrintF(const char* format, ...) { |
| 104 va_list arguments; | 41 va_list arguments; |
| 105 va_start(arguments, format); | 42 va_start(arguments, format); |
| 106 OS::VPrint(format, arguments); | 43 OS::VPrint(format, arguments); |
| 107 va_end(arguments); | 44 va_end(arguments); |
| 108 } | 45 } |
| 109 | 46 |
| 110 | 47 |
| 111 void PrintF(FILE* out, const char* format, ...) { | 48 void PrintF(FILE* out, const char* format, ...) { |
| 112 va_list arguments; | 49 va_list arguments; |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 void StringBuilder::AddFormattedList(const char* format, va_list list) { | 266 void StringBuilder::AddFormattedList(const char* format, va_list list) { |
| 330 ASSERT(!is_finalized() && position_ <= buffer_.length()); | 267 ASSERT(!is_finalized() && position_ <= buffer_.length()); |
| 331 int n = OS::VSNPrintF(buffer_ + position_, format, list); | 268 int n = OS::VSNPrintF(buffer_ + position_, format, list); |
| 332 if (n < 0 || n >= (buffer_.length() - position_)) { | 269 if (n < 0 || n >= (buffer_.length() - position_)) { |
| 333 position_ = buffer_.length(); | 270 position_ = buffer_.length(); |
| 334 } else { | 271 } else { |
| 335 position_ += n; | 272 position_ += n; |
| 336 } | 273 } |
| 337 } | 274 } |
| 338 | 275 |
| 339 | |
| 340 } } // namespace v8::internal | 276 } } // namespace v8::internal |
| OLD | NEW |