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"
14 #include "support/lstrings.h"
15 #include "support/unicode.h"
26 using lyx::support::contains;
27 using lyx::support::split;
33 void otexrowstream::append(docstring const & str, TexRow const & texrow)
36 texrow_.append(texrow);
40 void otexrowstream::put(char_type const & c)
48 void otexstream::put(char_type const & c)
51 if (!canbreakline_ && c == ' ')
53 protectspace_ = false;
55 otexrowstream::put(c);
61 SafeBreakLine safebreakln;
64 otexstream & operator<<(otexstream & ots, BreakLine)
66 if (ots.canBreakLine()) {
67 ots.otexrowstream::put('\n');
70 ots.protectSpace(false);
75 otexstream & operator<<(otexstream & ots, SafeBreakLine)
77 otexrowstream & otrs = ots;
78 if (ots.canBreakLine()) {
82 ots.protectSpace(false);
87 otexrowstream & operator<<(otexrowstream & ots, odocstream_manip pf)
90 if (pf == static_cast<odocstream_manip>(endl)) {
91 ots.texrow().newline();
96 otexstream & operator<<(otexstream & ots, odocstream_manip pf)
98 otexrowstream & otrs = ots;
100 if (pf == static_cast<odocstream_manip>(endl)) {
107 otexrowstream & operator<<(otexrowstream & ots, docstring const & s)
110 ots.texrow().newlines(count(s.begin(), s.end(), '\n'));
115 otexstream & operator<<(otexstream & ots, docstring const & s)
117 size_t const len = s.length();
119 // Check whether there's something to output
122 otexrowstream & otrs = ots;
123 if (ots.protectSpace()) {
124 if (!ots.canBreakLine() && s[0] == ' ')
126 ots.protectSpace(false);
129 if (contains(s, 0xF0000)) {
130 // Some encoding changes for the underlying stream are embedded
131 // in the docstring. The encoding names to be used are enclosed
132 // between the code points 0xF0000 and 0xF0001, the first two
133 // characters of plane 15, which is a Private Use Area whose
134 // codepoints don't have any associated glyph.
136 docstring s2 = split(s, s1, 0xF0000);
143 docstring const s3 = split(s2, enc, 0xF0001);
144 if (!contains(s2, 0xF0001))
145 s2 = split(enc, s1, 0xF0000);
147 otrs << setEncoding(to_ascii(enc));
148 s2 = split(s3, s1, 0xF0000);
155 ots.canBreakLine(s[len - 2] != '\n');
156 ots.lastChar(s[len - 1]);
161 otexrowstream & operator<<(otexrowstream & ots, string const & s)
168 otexstream & operator<<(otexstream & ots, string const & s)
175 otexrowstream & operator<<(otexrowstream & ots, char const * s)
182 otexstream & operator<<(otexstream & ots, char const * s)
189 otexrowstream & operator<<(otexrowstream & ots, char c)
196 otexstream & operator<<(otexstream & ots, char c)
203 template <typename Type>
204 otexrowstream & operator<<(otexrowstream & ots, Type value)
210 template otexrowstream & operator<< <SetEnc>(otexrowstream & os, SetEnc);
211 template otexrowstream & operator<< <double>(otexrowstream &, double);
212 template otexrowstream & operator<< <int>(otexrowstream &, int);
213 template otexrowstream & operator<< <unsigned int>(otexrowstream &,
215 template otexrowstream & operator<< <unsigned long>(otexrowstream &,
219 template <typename Type>
220 otexstream & operator<<(otexstream & ots, Type value)
224 ots.protectSpace(false);
228 template otexstream & operator<< <SetEnc>(otexstream & os, SetEnc);
229 template otexstream & operator<< <double>(otexstream &, double);
230 template otexstream & operator<< <int>(otexstream &, int);
231 template otexstream & operator<< <unsigned int>(otexstream &, unsigned int);
232 template otexstream & operator<< <unsigned long>(otexstream &, unsigned long);