OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
shared::FileContentsEscaper Struct Reference

#include <misc.h>

Public Member Functions

void quoteAndPrint (std::ostream &) const
 

Public Attributes

char const *const filename
 

Detailed Description

Definition at line 149 of file misc.h.

Member Function Documentation

void shared::FileContentsEscaper::quoteAndPrint ( std::ostream &  os) const

Definition at line 153 of file misc.cpp.

References filename.

Referenced by shared::operator<<().

153  {
154  std::ifstream file(filename);
155  if (!file.is_open()) {
156  os << "\"Unable to open " << filename << '"';
157  return;
158  }
159  char ch;
160  std::ios orig_os_state(nullptr);
161  orig_os_state.copyfmt(os);
162  os << '"';
163  while (file.get(ch)) {
164  if (ch == '"') {
165  os << "\\\"";
166  } else if (ch == '\\') {
167  os << "\\\\";
168  } else if (std::isprint(ch) || ch == ' ') {
169  os << ch;
170  } else {
171  switch (ch) {
172  // clang-format off
173  case '\b': os << "\\b"; break;
174  case '\f': os << "\\f"; break;
175  case '\n': os << "\\n"; break;
176  case '\r': os << "\\r"; break;
177  case '\t': os << "\\t"; break;
178  // clang-format on
179  default:
180  os << "\\u" << std::hex << std::setw(4) << std::setfill('0')
181  << static_cast<unsigned>(static_cast<unsigned char>(ch));
182  break;
183  }
184  }
185  }
186  os << '"';
187  os.copyfmt(orig_os_state);
188 }
char const *const filename
Definition: misc.h:150

+ Here is the caller graph for this function:

Member Data Documentation

char const* const shared::FileContentsEscaper::filename

Definition at line 150 of file misc.h.

Referenced by quoteAndPrint().


The documentation for this struct was generated from the following files: