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, bool enable)
37 : os_(os), texrow_(make_unique<TexRow>(enable))
41 otexrowstream::~otexrowstream() = default;
44 unique_ptr<TexRow> otexrowstream::releaseTexRow()
46 auto p = make_unique<TexRow>();
52 void otexrowstream::append(docstring const & str, TexRow texrow)
55 texrow_->append(move(texrow));
59 void otexrowstream::put(char_type const & c)
67 void otexstream::put(char_type const & c)
70 if (!canbreakline_ && c == ' ')
72 protectspace_ = false;
74 otexrowstream::put(c);
80 SafeBreakLine safebreakln;
83 otexstream & operator<<(otexstream & ots, BreakLine)
85 if (ots.canBreakLine()) {
86 ots.otexrowstream::put('\n');
89 ots.protectSpace(false);
94 otexstream & operator<<(otexstream & ots, SafeBreakLine)
96 otexrowstream & otrs = ots;
97 if (ots.canBreakLine()) {
101 ots.protectSpace(false);
106 otexrowstream & operator<<(otexrowstream & ots, odocstream_manip pf)
109 if (pf == static_cast<odocstream_manip>(endl)) {
110 ots.texrow().newline();
115 otexstream & operator<<(otexstream & ots, odocstream_manip pf)
117 otexrowstream & otrs = ots;
119 if (pf == static_cast<odocstream_manip>(endl)) {
126 otexrowstream & operator<<(otexrowstream & ots, docstring const & s)
129 ots.texrow().newlines(count(s.begin(), s.end(), '\n'));
134 otexstream & operator<<(otexstream & ots, docstring const & s)
136 size_t const len = s.length();
138 // Check whether there's something to output
141 otexrowstream & otrs = ots;
142 if (ots.protectSpace()) {
143 if (!ots.canBreakLine() && s[0] == ' ')
145 ots.protectSpace(false);
148 if (contains(s, 0xF0000)) {
149 // Some encoding changes for the underlying stream are embedded
150 // in the docstring. The encoding names to be used are enclosed
151 // between the code points 0xF0000 and 0xF0001, the first two
152 // characters of plane 15, which is a Private Use Area whose
153 // codepoints don't have any associated glyph.
155 docstring s2 = split(s, s1, 0xF0000);
162 docstring const s3 = split(s2, enc, 0xF0001);
163 if (!contains(s2, 0xF0001))
164 s2 = split(enc, s1, 0xF0000);
166 otrs << setEncoding(to_ascii(enc));
167 s2 = split(s3, s1, 0xF0000);
174 ots.canBreakLine(s[len - 2] != '\n');
175 ots.lastChar(s[len - 1]);
180 otexrowstream & operator<<(otexrowstream & ots, string const & s)
187 otexstream & operator<<(otexstream & ots, string const & s)
194 otexrowstream & operator<<(otexrowstream & ots, char const * s)
201 otexstream & operator<<(otexstream & ots, char const * s)
208 otexrowstream & operator<<(otexrowstream & ots, char c)
215 otexstream & operator<<(otexstream & ots, char c)
222 template <typename Type>
223 otexrowstream & operator<<(otexrowstream & ots, Type value)
229 template otexrowstream & operator<< <SetEnc>(otexrowstream & os, SetEnc);
230 template otexrowstream & operator<< <double>(otexrowstream &, double);
231 template otexrowstream & operator<< <int>(otexrowstream &, int);
232 template otexrowstream & operator<< <unsigned int>(otexrowstream &,
234 template otexrowstream & operator<< <unsigned long>(otexrowstream &,
237 #ifdef LYX_USE_LONG_LONG
238 template otexrowstream & operator<< <unsigned long long>(otexrowstream &,
243 template <typename Type>
244 otexstream & operator<<(otexstream & ots, Type value)
248 ots.protectSpace(false);
252 template otexstream & operator<< <SetEnc>(otexstream & os, SetEnc);
253 template otexstream & operator<< <double>(otexstream &, double);
254 template otexstream & operator<< <int>(otexstream &, int);
255 template otexstream & operator<< <unsigned int>(otexstream &, unsigned int);
256 template otexstream & operator<< <unsigned long>(otexstream &, unsigned long);
257 #ifdef LYX_USE_LONG_LONG
258 template otexstream & operator<< <unsigned long long>(otexstream &, unsigned long long);