25 static const size_t ConsoleWidth = 79;
30 Printer(
const string& msg,
const string& prepend):
31 _pos(0), _lineSize(0), _msg(msg), _prefix(prepend) {
33 string wordSpacePrefix;
35 while (_pos < _msg.size()) {
40 printRaw(_indentation);
42 if (_pos == _msg.size())
44 if (_msg[_pos] ==
'\n') {
50 wordSpacePrefix.clear();
51 while (_pos < _msg.size()) {
52 if (_msg[_pos] ==
'\n') {
56 if (isspace(_msg[_pos])) {
57 wordSpacePrefix += _msg[_pos];
61 ASSERT(!isspace(_msg[_pos]));
62 ASSERT(_msg[_pos] !=
'\n');
63 ASSERT(_pos < _msg.size());
66 while (_pos < _msg.size() &&
68 !isspace(_msg[_pos])) {
73 printWord(wordSpacePrefix, word);
74 wordSpacePrefix.clear();
87 void readIndentation() {
90 while (_pos < _msg.size() && _msg[_pos] !=
'\n' && isspace(_msg[_pos])) {
91 _indentation += _msg[_pos];
96 void printWord(
const string& wordSpacePrefix,
const string& word) {
102 size_t wordAndPrefixSize = word.size() + wordSpacePrefix.size();
103 if (_lineSize != 0 && _lineSize + wordAndPrefixSize > ConsoleWidth) {
107 printRaw(_indentation);
109 printRaw(wordSpacePrefix);
113 void printRaw(
const string& word) {
114 fputs(word.c_str(), stderr);
115 _lineSize += word.size();
118 void printRaw(
char c) {
126 const string& _prefix;
131 void display(
const string& msg,
const string& prepend) {
132 Printer(msg, prepend);
136 display(
"NOTE: " + msg +
"\n");
140 display(
"ERROR: " + msg +
"\n");
144 display(
"INTERNAL ERROR: " + msg +
"\n");
151 fputs(
"\n\n*** Error while printing error! ***\n", stderr);
153 fputs(
"*** Retrying display of error using simpler display method. ***\n",
156 fputs(exception.what(), stderr);
void display(const string &msg, const string &prepend)
Display msg to standard error with automatic line breaking.
void displayError(const string &msg)
Display msg to standard error in a way that indicates that it is an error.
void displayNote(const string &msg)
Display msg to standard error in a way that indicates that this is something that the user should tak...
void displayInternalError(const string &msg)
Display msg to standard in a way that indicates that it is an internal error.
void displayException(const std::exception &exception)
Display the message of exception.
This file contains functions for printing strings to standard error.