2014-06-27 08:42:17 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef V8_OSTREAMS_H_
|
|
|
|
#define V8_OSTREAMS_H_
|
|
|
|
|
2014-09-30 10:29:32 +00:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
|
|
|
#include <ostream> // NOLINT
|
|
|
|
#include <streambuf>
|
2014-06-27 08:42:17 +00:00
|
|
|
|
|
|
|
#include "include/v8config.h"
|
|
|
|
#include "src/base/macros.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2015-01-19 14:41:39 +00:00
|
|
|
|
2014-09-30 10:29:32 +00:00
|
|
|
class OFStreamBase : public std::streambuf {
|
2015-01-19 14:41:39 +00:00
|
|
|
public:
|
2014-09-30 10:29:32 +00:00
|
|
|
explicit OFStreamBase(FILE* f);
|
|
|
|
virtual ~OFStreamBase();
|
2014-06-27 08:42:17 +00:00
|
|
|
|
2015-01-19 14:41:39 +00:00
|
|
|
protected:
|
2014-09-30 10:29:32 +00:00
|
|
|
FILE* const f_;
|
2014-06-27 08:42:17 +00:00
|
|
|
|
2015-01-19 14:41:39 +00:00
|
|
|
virtual int sync();
|
|
|
|
virtual int_type overflow(int_type c);
|
|
|
|
virtual std::streamsize xsputn(const char* s, std::streamsize n);
|
2014-06-27 08:42:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// An output stream writing to a file.
|
2016-09-20 07:12:39 +00:00
|
|
|
class OFStream : public std::ostream {
|
2014-06-27 08:42:17 +00:00
|
|
|
public:
|
2014-09-30 10:29:32 +00:00
|
|
|
explicit OFStream(FILE* f);
|
2015-12-09 04:34:05 +00:00
|
|
|
virtual ~OFStream();
|
2014-06-27 08:42:17 +00:00
|
|
|
|
|
|
|
private:
|
2015-01-19 14:41:39 +00:00
|
|
|
OFStreamBase buf_;
|
2014-06-27 08:42:17 +00:00
|
|
|
};
|
|
|
|
|
2014-07-07 09:57:29 +00:00
|
|
|
|
2014-08-28 07:30:58 +00:00
|
|
|
// Wrappers to disambiguate uint16_t and uc16.
|
2014-07-07 09:57:29 +00:00
|
|
|
struct AsUC16 {
|
|
|
|
explicit AsUC16(uint16_t v) : value(v) {}
|
|
|
|
uint16_t value;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-01-21 13:33:02 +00:00
|
|
|
struct AsUC32 {
|
|
|
|
explicit AsUC32(int32_t v) : value(v) {}
|
|
|
|
int32_t value;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-08-28 07:30:58 +00:00
|
|
|
struct AsReversiblyEscapedUC16 {
|
|
|
|
explicit AsReversiblyEscapedUC16(uint16_t v) : value(v) {}
|
|
|
|
uint16_t value;
|
|
|
|
};
|
|
|
|
|
2015-01-29 12:14:55 +00:00
|
|
|
struct AsEscapedUC16ForJSON {
|
|
|
|
explicit AsEscapedUC16ForJSON(uint16_t v) : value(v) {}
|
|
|
|
uint16_t value;
|
|
|
|
};
|
|
|
|
|
2016-06-16 07:48:32 +00:00
|
|
|
struct AsHex {
|
|
|
|
explicit AsHex(uint64_t v, uint8_t min_width = 0)
|
|
|
|
: value(v), min_width(min_width) {}
|
|
|
|
uint64_t value;
|
|
|
|
uint8_t min_width;
|
|
|
|
};
|
2014-08-28 07:30:58 +00:00
|
|
|
|
2014-09-09 10:33:33 +00:00
|
|
|
// Writes the given character to the output escaping everything outside of
|
|
|
|
// printable/space ASCII range. Additionally escapes '\' making escaping
|
2014-08-28 07:30:58 +00:00
|
|
|
// reversible.
|
2014-09-30 10:29:32 +00:00
|
|
|
std::ostream& operator<<(std::ostream& os, const AsReversiblyEscapedUC16& c);
|
2014-08-28 07:30:58 +00:00
|
|
|
|
2015-01-29 12:14:55 +00:00
|
|
|
// Same as AsReversiblyEscapedUC16 with additional escaping of \n, \r, " and '.
|
|
|
|
std::ostream& operator<<(std::ostream& os, const AsEscapedUC16ForJSON& c);
|
|
|
|
|
2014-08-28 07:30:58 +00:00
|
|
|
// Writes the given character to the output escaping everything outside
|
|
|
|
// of printable ASCII range.
|
2014-09-30 10:29:32 +00:00
|
|
|
std::ostream& operator<<(std::ostream& os, const AsUC16& c);
|
|
|
|
|
2016-01-21 13:33:02 +00:00
|
|
|
// Writes the given character to the output escaping everything outside
|
|
|
|
// of printable ASCII range.
|
|
|
|
std::ostream& operator<<(std::ostream& os, const AsUC32& c);
|
|
|
|
|
2016-06-16 07:48:32 +00:00
|
|
|
// Writes the given number to the output in hexadecimal notation.
|
|
|
|
std::ostream& operator<<(std::ostream& os, const AsHex& v);
|
|
|
|
|
2014-09-30 10:29:32 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
2014-06-27 08:42:17 +00:00
|
|
|
|
|
|
|
#endif // V8_OSTREAMS_H_
|