summaryrefslogtreecommitdiff
path: root/deps/v8/src/ostreams.h
blob: 56787f7c126a2d1ff0be295652b247354816170c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// 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_

#include <cstddef>
#include <cstdio>
#include <cstring>
#include <ostream>  // NOLINT
#include <streambuf>

#include "include/v8config.h"
#include "src/base/macros.h"

namespace v8 {
namespace internal {

class OFStreamBase : public std::streambuf {
 protected:
  explicit OFStreamBase(FILE* f);
  virtual ~OFStreamBase();

  int_type sync() FINAL;
  int_type overflow(int_type c) FINAL;

 private:
  FILE* const f_;

  DISALLOW_COPY_AND_ASSIGN(OFStreamBase);
};


// An output stream writing to a file.
class OFStream FINAL : private virtual OFStreamBase, public std::ostream {
 public:
  explicit OFStream(FILE* f);
  ~OFStream();

 private:
  DISALLOW_COPY_AND_ASSIGN(OFStream);
};


// Wrappers to disambiguate uint16_t and uc16.
struct AsUC16 {
  explicit AsUC16(uint16_t v) : value(v) {}
  uint16_t value;
};


struct AsReversiblyEscapedUC16 {
  explicit AsReversiblyEscapedUC16(uint16_t v) : value(v) {}
  uint16_t value;
};


// Writes the given character to the output escaping everything outside of
// printable/space ASCII range. Additionally escapes '\' making escaping
// reversible.
std::ostream& operator<<(std::ostream& os, const AsReversiblyEscapedUC16& c);

// Writes the given character to the output escaping everything outside
// of printable ASCII range.
std::ostream& operator<<(std::ostream& os, const AsUC16& c);

}  // namespace internal
}  // namespace v8

#endif  // V8_OSTREAMS_H_