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;
32 void otexstream::put(char_type const & c)
35 if (!canbreakline_ && c == ' ')
37 protectspace_ = false;
47 SafeBreakLine safebreakln;
50 otexstream & operator<<(otexstream & ots, BreakLine)
52 if (ots.canBreakLine()) {
55 ots.texrow().newline();
57 ots.protectSpace(false);
62 otexstream & operator<<(otexstream & ots, SafeBreakLine)
64 if (ots.canBreakLine()) {
67 ots.texrow().newline();
69 ots.protectSpace(false);
74 otexstream & operator<<(otexstream & ots, odocstream_manip pf)
77 if (pf == static_cast<odocstream_manip>(endl)) {
79 ots.texrow().newline();
85 otexstream & operator<<(otexstream & ots, docstring const & s)
87 size_t const len = s.length();
89 // Check whether there's something to output
93 if (ots.protectSpace()) {
94 if (!ots.canBreakLine() && s[0] == ' ')
96 ots.protectSpace(false);
99 if (contains(s, 0xF0000)) {
100 // Some encoding changes for the underlying stream are embedded
101 // in the docstring. The encoding names to be used are enclosed
102 // between the code points 0xF0000 and 0xF0001, the first two
103 // characters of plane 15, which is a Private Use Area whose
104 // codepoints don't have any associated glyph.
106 docstring s2 = split(s, s1, 0xF0000);
113 docstring const s3 = split(s2, enc, 0xF0001);
114 if (!contains(s2, 0xF0001))
115 s2 = split(enc, s1, 0xF0000);
117 ots.os() << setEncoding(to_ascii(enc));
118 s2 = split(s3, s1, 0xF0000);
125 ots.canBreakLine(s[len - 2] != '\n');
126 ots.lastChar(s[len - 1]);
127 ots.texrow().newlines(count(s.begin(), s.end(), '\n'));
132 otexstream & operator<<(otexstream & ots, string const & s)
139 otexstream & operator<<(otexstream & ots, char const * s)
146 otexstream & operator<<(otexstream & ots, char c)
148 if (ots.protectSpace()) {
149 if (!ots.canBreakLine() && c == ' ')
151 ots.protectSpace(false);
156 ots.texrow().newline();
161 template <typename Type>
162 otexstream & operator<<(otexstream & ots, Type value)
166 ots.protectSpace(false);
170 template otexstream & operator<< <SetEnc>(otexstream & os, SetEnc);
171 template otexstream & operator<< <double>(otexstream &, double);
172 template otexstream & operator<< <int>(otexstream &, int);
173 template otexstream & operator<< <unsigned int>(otexstream &, unsigned int);
174 template otexstream & operator<< <unsigned long>(otexstream &, unsigned long);