e709aa24c0
We divide character ranges into - BMP, matched normally. - non-BMP, matched as alternatives of surrogate pair ranges. - lone surrogates, matched with lookaround assertion that its indeed lone. R=erik.corry@gmail.com BUG=v8:2952 LOG=N Committed: https://crrev.com/ea820ad5fa282a323a86fe20e64f83ee67ba5f04 Cr-Commit-Position: refs/heads/master@{#33432} Review URL: https://codereview.chromium.org/1578253005 Cr-Commit-Position: refs/heads/master@{#33437}
90 lines
2.1 KiB
C++
90 lines
2.1 KiB
C++
// 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 {
|
|
public:
|
|
explicit OFStreamBase(FILE* f);
|
|
virtual ~OFStreamBase();
|
|
|
|
protected:
|
|
FILE* const f_;
|
|
|
|
virtual int sync();
|
|
virtual int_type overflow(int_type c);
|
|
virtual std::streamsize xsputn(const char* s, std::streamsize n);
|
|
};
|
|
|
|
|
|
// An output stream writing to a file.
|
|
class OFStream : public std::ostream {
|
|
public:
|
|
explicit OFStream(FILE* f);
|
|
virtual ~OFStream();
|
|
|
|
private:
|
|
OFStreamBase buf_;
|
|
};
|
|
|
|
|
|
// Wrappers to disambiguate uint16_t and uc16.
|
|
struct AsUC16 {
|
|
explicit AsUC16(uint16_t v) : value(v) {}
|
|
uint16_t value;
|
|
};
|
|
|
|
|
|
struct AsUC32 {
|
|
explicit AsUC32(int32_t v) : value(v) {}
|
|
int32_t value;
|
|
};
|
|
|
|
|
|
struct AsReversiblyEscapedUC16 {
|
|
explicit AsReversiblyEscapedUC16(uint16_t v) : value(v) {}
|
|
uint16_t value;
|
|
};
|
|
|
|
struct AsEscapedUC16ForJSON {
|
|
explicit AsEscapedUC16ForJSON(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);
|
|
|
|
// Same as AsReversiblyEscapedUC16 with additional escaping of \n, \r, " and '.
|
|
std::ostream& operator<<(std::ostream& os, const AsEscapedUC16ForJSON& c);
|
|
|
|
// Writes the given character to the output escaping everything outside
|
|
// of printable ASCII range.
|
|
std::ostream& operator<<(std::ostream& os, const AsUC16& c);
|
|
|
|
// Writes the given character to the output escaping everything outside
|
|
// of printable ASCII range.
|
|
std::ostream& operator<<(std::ostream& os, const AsUC32& c);
|
|
|
|
} // namespace internal
|
|
} // namespace v8
|
|
|
|
#endif // V8_OSTREAMS_H_
|