3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Enrico Forestieri
8 * Full author contact details are available in file CREDITS.
13 #include "texstream.h"
17 #include "support/lstrings.h"
18 #include "support/unicode.h"
29 using lyx::support::contains;
30 using lyx::support::split;
36 otexrowstream::otexrowstream(odocstream & os)
37 : os_(os), texrow_(make_unique<TexRow>())
41 otexrowstream::~otexrowstream() = default;
44 unique_ptr<TexRow> otexrowstream::releaseTexRow()
46 auto p = make_unique<TexRow>();
52 void otexrowstream::put(char_type const & c)
60 void otexstream::put(char_type const & c)
63 if (!canbreakline_ && c == ' ')
65 protectspace_ = false;
67 otexrowstream::put(c);
72 size_t otexstringstream::length()
74 auto pos = ods_.tellp();
75 return (pos >= 0) ? size_t(pos) : 0;
79 TexString otexstringstream::release()
81 TexString ts(ods_.str(), move(texrow()));
85 ods_.str(docstring());
91 SafeBreakLine safebreakln;
94 otexstream & operator<<(otexstream & ots, BreakLine)
96 if (ots.canBreakLine()) {
97 ots.otexrowstream::put('\n');
100 ots.protectSpace(false);
105 otexstream & operator<<(otexstream & ots, SafeBreakLine)
107 otexrowstream & otrs = ots;
108 if (ots.canBreakLine()) {
112 ots.protectSpace(false);
117 otexrowstream & operator<<(otexrowstream & ots, odocstream_manip pf)
120 if (pf == static_cast<odocstream_manip>(endl)) {
121 ots.texrow().newline();
127 otexstream & operator<<(otexstream & ots, odocstream_manip pf)
129 otexrowstream & otrs = ots;
131 if (pf == static_cast<odocstream_manip>(endl)) {
138 otexrowstream & operator<<(otexrowstream & ots, TexString ts)
141 ots.os() << move(ts.str);
142 ots.texrow().append(move(ts.texrow));
147 otexstream & operator<<(otexstream & ots, TexString ts)
149 size_t const len = ts.str.length();
150 // Check whether there is something to output
154 otexrowstream & otrs = ots;
155 if (ots.protectSpace()) {
156 if (!ots.canBreakLine() && ts.str[0] == ' ')
158 ots.protectSpace(false);
162 ots.canBreakLine(ts.str[len - 2] != '\n');
163 ots.lastChar(ts.str[len - 1]);
170 otexrowstream & operator<<(otexrowstream & ots, docstring const & s)
173 ots.texrow().newlines(count(s.begin(), s.end(), '\n'));
178 otexstream & operator<<(otexstream & ots, docstring const & s)
180 size_t const len = s.length();
182 // Check whether there's something to output
185 otexrowstream & otrs = ots;
186 if (ots.protectSpace()) {
187 if (!ots.canBreakLine() && s[0] == ' ')
189 ots.protectSpace(false);
192 if (contains(s, 0xF0000)) {
193 // Some encoding changes for the underlying stream are embedded
194 // in the docstring. The encoding names to be used are enclosed
195 // between the code points 0xF0000 and 0xF0001, the first two
196 // characters of plane 15, which is a Private Use Area whose
197 // codepoints don't have any associated glyph.
199 docstring s2 = split(s, s1, 0xF0000);
206 docstring const s3 = split(s2, enc, 0xF0001);
207 if (!contains(s2, 0xF0001))
208 s2 = split(enc, s1, 0xF0000);
210 otrs << setEncoding(to_ascii(enc));
211 s2 = split(s3, s1, 0xF0000);
218 ots.canBreakLine(s[len - 2] != '\n');
219 ots.lastChar(s[len - 1]);
224 otexrowstream & operator<<(otexrowstream & ots, string const & s)
231 otexstream & operator<<(otexstream & ots, string const & s)
238 otexrowstream & operator<<(otexrowstream & ots, char const * s)
245 otexstream & operator<<(otexstream & ots, char const * s)
252 otexrowstream & operator<<(otexrowstream & ots, char c)
259 otexstream & operator<<(otexstream & ots, char c)
266 template <typename Type>
267 otexrowstream & operator<<(otexrowstream & ots, Type value)
273 template otexrowstream & operator<< <SetEnc>(otexrowstream & os, SetEnc);
274 template otexrowstream & operator<< <double>(otexrowstream &, double);
275 template otexrowstream & operator<< <int>(otexrowstream &, int);
276 template otexrowstream & operator<< <unsigned int>(otexrowstream &,
278 template otexrowstream & operator<< <unsigned long>(otexrowstream &,
281 #ifdef LYX_USE_LONG_LONG
282 template otexrowstream & operator<< <unsigned long long>(otexrowstream &,
287 template <typename Type>
288 otexstream & operator<<(otexstream & ots, Type value)
292 ots.protectSpace(false);
296 template otexstream & operator<< <SetEnc>(otexstream & os, SetEnc);
297 template otexstream & operator<< <double>(otexstream &, double);
298 template otexstream & operator<< <int>(otexstream &, int);
299 template otexstream & operator<< <unsigned int>(otexstream &, unsigned int);
300 template otexstream & operator<< <unsigned long>(otexstream &, unsigned long);
301 #ifdef LYX_USE_LONG_LONG
302 template otexstream & operator<< <unsigned long long>(otexstream &, unsigned long long);