2013-07-20 21:19:36 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
2013-09-13 10:35:29 +00:00
|
|
|
#include "util/escaped.h"
|
2013-07-20 21:19:36 +00:00
|
|
|
|
|
|
|
namespace lean {
|
|
|
|
|
|
|
|
char const * escaped::end() const {
|
|
|
|
if (m_str == 0) return 0;
|
|
|
|
char const * it = m_str;
|
|
|
|
char const * e = m_str;
|
|
|
|
while (*it) {
|
|
|
|
if (!m_trim_nl || *it != '\n') {
|
|
|
|
++it;
|
|
|
|
e = it;
|
2013-08-07 15:17:33 +00:00
|
|
|
} else {
|
2013-07-20 21:19:36 +00:00
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream & operator<<(std::ostream & out, escaped const & s) {
|
|
|
|
char const * it = s.m_str;
|
|
|
|
char const * e = s.end();
|
|
|
|
for (; it != e; ++it) {
|
|
|
|
char c = *it;
|
|
|
|
if (c == '"') {
|
|
|
|
out << '\\';
|
|
|
|
}
|
|
|
|
out << c;
|
|
|
|
if (c == '\n') {
|
|
|
|
for (unsigned i = 0; i < s.m_indent; i++)
|
|
|
|
out << " ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|