| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/ostreams.h" | 5 #include "src/ostreams.h" |
| 6 | 6 |
| 7 #if V8_OS_WIN | 7 #if V8_OS_WIN |
| 8 #define snprintf sprintf_s | 8 #define snprintf sprintf_s |
| 9 #endif | 9 #endif |
| 10 | 10 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 | 13 |
| 14 OFStreamBase::OFStreamBase(FILE* f) : f_(f) {} | 14 OFStreamBase::OFStreamBase(FILE* f) : f_(f) {} |
| 15 | 15 |
| 16 | 16 |
| 17 OFStreamBase::~OFStreamBase() {} | 17 OFStreamBase::~OFStreamBase() {} |
| 18 | 18 |
| 19 | 19 |
| 20 OFStreamBase::int_type OFStreamBase::sync() { | 20 int OFStreamBase::sync() { |
| 21 std::fflush(f_); | 21 std::fflush(f_); |
| 22 return 0; | 22 return 0; |
| 23 } | 23 } |
| 24 | 24 |
| 25 | 25 |
| 26 OFStreamBase::int_type OFStreamBase::overflow(int_type c) { | 26 OFStreamBase::int_type OFStreamBase::overflow(int_type c) { |
| 27 return (c != EOF) ? std::fputc(c, f_) : c; | 27 return (c != EOF) ? std::fputc(c, f_) : c; |
| 28 } | 28 } |
| 29 | 29 |
| 30 | 30 |
| 31 OFStream::OFStream(FILE* f) : OFStreamBase(f), std::ostream(this) { | 31 std::streamsize OFStreamBase::xsputn(const char* s, std::streamsize n) { |
| 32 DCHECK_NOT_NULL(f); | 32 return static_cast<std::streamsize>( |
| 33 std::fwrite(s, 1, static_cast<size_t>(n), f_)); |
| 33 } | 34 } |
| 34 | 35 |
| 35 | 36 |
| 37 OFStream::OFStream(FILE* f) : std::ostream(nullptr), buf_(f) { |
| 38 DCHECK_NOT_NULL(f); |
| 39 rdbuf(&buf_); |
| 40 } |
| 41 |
| 42 |
| 36 OFStream::~OFStream() {} | 43 OFStream::~OFStream() {} |
| 37 | 44 |
| 38 | 45 |
| 39 namespace { | 46 namespace { |
| 40 | 47 |
| 41 // Locale-independent predicates. | 48 // Locale-independent predicates. |
| 42 bool IsPrint(uint16_t c) { return 0x20 <= c && c <= 0x7e; } | 49 bool IsPrint(uint16_t c) { return 0x20 <= c && c <= 0x7e; } |
| 43 bool IsSpace(uint16_t c) { return (0x9 <= c && c <= 0xd) || c == 0x20; } | 50 bool IsSpace(uint16_t c) { return (0x9 <= c && c <= 0xd) || c == 0x20; } |
| 44 bool IsOK(uint16_t c) { return (IsPrint(c) || IsSpace(c)) && c != '\\'; } | 51 bool IsOK(uint16_t c) { return (IsPrint(c) || IsSpace(c)) && c != '\\'; } |
| 45 | 52 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 58 return PrintUC16(os, c.value, IsOK); | 65 return PrintUC16(os, c.value, IsOK); |
| 59 } | 66 } |
| 60 | 67 |
| 61 | 68 |
| 62 std::ostream& operator<<(std::ostream& os, const AsUC16& c) { | 69 std::ostream& operator<<(std::ostream& os, const AsUC16& c) { |
| 63 return PrintUC16(os, c.value, IsPrint); | 70 return PrintUC16(os, c.value, IsPrint); |
| 64 } | 71 } |
| 65 | 72 |
| 66 } // namespace internal | 73 } // namespace internal |
| 67 } // namespace v8 | 74 } // namespace v8 |
| OLD | NEW |