2006-10-11 19:40:50 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file docstream.h
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Georg Baum
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LYX_DOCSTREAM_H
|
|
|
|
#define LYX_DOCSTREAM_H
|
|
|
|
|
|
|
|
#include "support/docstring.h"
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2006-10-26 15:01:45 +00:00
|
|
|
class iconv_codecvt_facet_exception : public std::exception {
|
|
|
|
public:
|
|
|
|
virtual ~iconv_codecvt_facet_exception() throw() {}
|
|
|
|
virtual const char * what() const throw();
|
|
|
|
};
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
/// Base class for UCS4 input streams
|
|
|
|
typedef std::basic_istream<char_type> idocstream;
|
|
|
|
|
|
|
|
/** Base class for UCS4 output streams.
|
|
|
|
If you want to output a single UCS4 character, use \code
|
|
|
|
os.put(c);
|
|
|
|
\endcode, not \code
|
|
|
|
os << c;
|
|
|
|
\endcode . The latter will not output the character, but the code point
|
2011-04-11 20:11:27 +00:00
|
|
|
as number if USE_WCHAR_T is not defined. This is because we can't overload
|
|
|
|
operator<< (our character type is not always a real type but sometimes a
|
|
|
|
typedef). Narrow characters of type char can be output as usual.
|
2006-10-11 19:40:50 +00:00
|
|
|
*/
|
|
|
|
typedef std::basic_ostream<char_type> odocstream;
|
|
|
|
|
|
|
|
/// File stream for reading UTF8-encoded files with automatic conversion to
|
|
|
|
/// UCS4.
|
2008-11-16 12:21:29 +00:00
|
|
|
class ifdocstream : public std::basic_ifstream<char_type> {
|
2006-10-11 19:40:50 +00:00
|
|
|
typedef std::basic_ifstream<char_type> base;
|
|
|
|
public:
|
2009-04-20 15:40:01 +00:00
|
|
|
ifdocstream();
|
2008-11-16 12:21:29 +00:00
|
|
|
explicit ifdocstream(const char* s,
|
2006-12-15 16:09:05 +00:00
|
|
|
std::ios_base::openmode mode = std::ios_base::in,
|
|
|
|
std::string const & encoding = "UTF-8");
|
2008-11-16 12:21:29 +00:00
|
|
|
~ifdocstream() {}
|
2006-10-11 19:40:50 +00:00
|
|
|
};
|
|
|
|
|
2006-10-26 15:01:45 +00:00
|
|
|
/// File stream for writing files in 8bit encoding \p encoding with automatic
|
|
|
|
/// conversion from UCS4.
|
2010-04-22 11:16:58 +00:00
|
|
|
|
2008-11-16 12:21:29 +00:00
|
|
|
class ofdocstream : public std::basic_ofstream<char_type> {
|
2006-10-11 19:40:50 +00:00
|
|
|
typedef std::basic_ofstream<char_type> base;
|
|
|
|
public:
|
2008-11-16 12:21:29 +00:00
|
|
|
ofdocstream();
|
|
|
|
explicit ofdocstream(const char* s,
|
2006-10-26 15:01:45 +00:00
|
|
|
std::ios_base::openmode mode = std::ios_base::out|std::ios_base::trunc,
|
|
|
|
std::string const & encoding = "UTF-8");
|
2008-11-16 12:21:29 +00:00
|
|
|
~ofdocstream() {}
|
2007-12-05 13:56:53 +00:00
|
|
|
///
|
|
|
|
void reset(std::string const & encoding);
|
2006-10-11 19:40:50 +00:00
|
|
|
};
|
|
|
|
|
2010-04-22 11:16:58 +00:00
|
|
|
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
/// UCS4 input stringstream
|
|
|
|
typedef std::basic_istringstream<char_type> idocstringstream;
|
|
|
|
|
2011-02-14 17:09:39 +00:00
|
|
|
/// UCS4 output manipulator
|
|
|
|
typedef odocstream & (*odocstream_manip)(odocstream &);
|
|
|
|
|
Introduce a wrapper class for odocstream to help ensuring that no
blank lines may be inadvertently output. This is achieved by using two
special iomanip-like variables (breakln and safebreakln) in the lyx::
namespace. When they are inserted in the stream, a newline is output
only if not already at the beginning of a line. The difference between
breakln and safebreakln is that, if needed, the former outputs '\n'
and the latter "%\n".
In future, the new class will also be used for counting the number of
newlines issued. Even if the infractrure for doing that is already in
place, the counting is essentially still done the old way.
There are still places in the code where the functionality of the
class could be used, most probably. ATM, it is used for InsetTabular,
InsetListings, InsetFloat, and InsetText.
The Comment and GreyedOut insets required a special treatment and a
new InsetLayout parameter (Display) has been introduced. The default
for Display is "true", meaning that the corresponding latex
environment is of "display" type, i.e., it stands on its own, whereas
"false" means that the contents appear inline with the text. The
latter is the case for both Comment and GreyedOut insets.
Mostly, the only visible effects on latex exports should be the
disappearing of some redundant % chars and the appearing/disappearing
of null {} latex groups after a comment or lyxgreyedout environments
(they are related to the presence or absence of a space immediately
after those environments), as well as the fact that math environments
are now started on their own lines.
As a last thing, only the latex code between \begin{document} and
\end{document} goes through the new class, the preamble being directly
output through odocstream, as usual.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37360 a592a061-630c-0410-9148-cb99ea01b6c8
2011-01-29 02:41:13 +00:00
|
|
|
|
2007-01-09 19:25:40 +00:00
|
|
|
/// Helper struct for changing stream encoding
|
|
|
|
struct SetEnc {
|
2015-10-15 18:52:28 +00:00
|
|
|
/**
|
|
|
|
* It is important that this constructor is explicit.
|
|
|
|
* Otherwise the attempt to output a std::string to an odocstream
|
|
|
|
* would compile, but cause a (probably failing) encoding change
|
|
|
|
* instead of string output (we do not define
|
|
|
|
* operator<<(odocstream &, std::string) since we want to avoid
|
|
|
|
* outputting strings with unspecified encoding)
|
|
|
|
*/
|
|
|
|
explicit SetEnc(std::string const & e) : encoding(e) {}
|
2007-01-09 19:25:40 +00:00
|
|
|
std::string encoding;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Helper function for changing stream encoding
|
|
|
|
SetEnc setEncoding(std::string const & encoding);
|
|
|
|
|
|
|
|
/** Change the encoding of \p os to \p e.encoding.
|
|
|
|
\p e.encoding must be a valid iconv name of an 8bit encoding.
|
|
|
|
This does nothing if the stream is not a file stream, since only
|
|
|
|
file streams do have an associated 8bit encoding.
|
|
|
|
Usage: \code
|
|
|
|
os << setEncoding("ISO-8859-1");
|
|
|
|
\endcode
|
|
|
|
*/
|
|
|
|
odocstream & operator<<(odocstream & os, SetEnc e);
|
2008-11-16 19:25:26 +00:00
|
|
|
idocstream & operator<<(idocstream & os, SetEnc e);
|
2007-01-09 19:25:40 +00:00
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
}
|
2006-10-19 21:00:33 +00:00
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
#endif
|