]> git.lyx.org Git - features.git/commitdiff
* docstream: factorize out some code and introduce odocfstream::reset()
authorAbdelrazak Younes <younes@lyx.org>
Wed, 5 Dec 2007 13:56:53 +0000 (13:56 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Wed, 5 Dec 2007 13:56:53 +0000 (13:56 +0000)
* Buffer::makeLaTeXFile(): try to catch one more iconv exception. Fix bug 4385 (http://bugzilla.lyx.org/show_bug.cgi?id=4385)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21967 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/output_plaintext.cpp
src/support/docstream.cpp
src/support/docstream.h

index 0b2c71b1cc86111e305c21950318032de4ea180a..7ab95e8f0ea53360609a82439d2add74e86ac26e 100644 (file)
@@ -1009,7 +1009,15 @@ bool Buffer::makeLaTeXFile(FileName const & fname,
        string const encoding = runparams.encoding->iconvName();
        LYXERR(Debug::LATEX, "makeLaTeXFile encoding: " << encoding << "...");
 
-       odocfstream ofs(encoding);
+       odocfstream ofs;
+       try { ofs.reset(encoding); }
+       catch (iconv_codecvt_facet_exception & e) {
+               lyxerr << "Caught iconv exception: " << e.what() << endl;
+               Alert::error(_("Iconv software exception Detected"), bformat(_("Please "
+                       "verify that the support software for your encoding (%1$s) is "
+                       "properly installed"), from_ascii(encoding)));
+               return false;
+       }
        if (!openFileWrite(ofs, fname))
                return false;
 
index 0ab78d17f9b8d001f0352063472a84f82094aa76..eb11c576600a1bfa558f709c2cc7f6b79375f32e 100644 (file)
@@ -42,7 +42,7 @@ using std::string;
 void writePlaintextFile(Buffer const & buf, FileName const & fname,
        OutputParams const & runparams)
 {
-       odocfstream ofs;
+       odocfstream ofs("UTF-8");
        if (!openFileWrite(ofs, fname))
                return;
        writePlaintextFile(buf, ofs, runparams);
index 69de4160d0a5cc7ee50b702392fd17b210e0adc2..481fd8555af396a1a104d832225502d013ffbfee 100644 (file)
@@ -267,6 +267,15 @@ private:
 
 namespace lyx {
 
+template<class Ios>
+void setEncoding(Ios & ios, string const & encoding, std::ios_base::openmode mode)
+{
+       // We must imbue the stream before openening the file
+       std::locale global;
+       std::locale locale(global, new iconv_codecvt_facet(encoding, mode));
+       ios.imbue(locale);
+}
+
 
 const char * iconv_codecvt_facet_exception::what() const throw()
 {
@@ -276,9 +285,7 @@ const char * iconv_codecvt_facet_exception::what() const throw()
 
 idocfstream::idocfstream(string const & encoding) : base()
 {
-       std::locale global;
-       std::locale locale(global, new iconv_codecvt_facet(encoding, in));
-       imbue(locale);
+       setEncoding(*this, encoding, in);
 }
 
 
@@ -286,19 +293,19 @@ idocfstream::idocfstream(const char* s, std::ios_base::openmode mode,
                         string const & encoding)
        : base()
 {
-       // We must imbue the stream before openening the file
-       std::locale global;
-       std::locale locale(global, new iconv_codecvt_facet(encoding, in));
-       imbue(locale);
+       setEncoding(*this, encoding, in);
        open(s, mode);
 }
 
 
+odocfstream::odocfstream(): base()
+{
+}
+
+
 odocfstream::odocfstream(string const & encoding) : base()
 {
-       std::locale global;
-       std::locale locale(global, new iconv_codecvt_facet(encoding, out));
-       imbue(locale);
+       setEncoding(*this, encoding, out);
 }
 
 
@@ -306,14 +313,18 @@ odocfstream::odocfstream(const char* s, std::ios_base::openmode mode,
                         string const & encoding)
        : base()
 {
-       // We must imbue the stream before openening the file
-       std::locale global;
-       std::locale locale(global, new iconv_codecvt_facet(encoding, out));
-       imbue(locale);
+       setEncoding(*this, encoding, out);
        open(s, mode);
 }
 
 
+void odocfstream::reset(string const & encoding)
+{
+       setEncoding(*this, encoding, out);
+}
+
+
+
 SetEnc setEncoding(string const & encoding)
 {
        return SetEnc(encoding);
index ed49a726cf0cd3da94bf02033df992d6374efa28..50fb82b7bc3974087acf19084db542036f8e6f56 100644 (file)
@@ -57,11 +57,14 @@ public:
 class odocfstream : public std::basic_ofstream<char_type> {
        typedef std::basic_ofstream<char_type> base;
 public:
-       odocfstream(std::string const & encoding = "UTF-8");
+       odocfstream();
+       odocfstream(std::string const & encoding);
        explicit odocfstream(const char* s,
                std::ios_base::openmode mode = std::ios_base::out|std::ios_base::trunc,
                std::string const & encoding = "UTF-8");
        ~odocfstream() {}
+       ///
+       void reset(std::string const & encoding);
 };
 
 /// UCS4 input stringstream