i did some quick no-brain copy-pasting. this doesn't work. could you have a look at some point? thanks

Georg Baum wrote:
Edwin Leuven wrote:

the insert citation dialog crashes here with attached bib entry

hints anyone?

Yes. The contents of .bib files is implicitly treated as UTF8, and your file
is encoded in latin1. What we need to do is to convert them from the
encoding that will be used for LaTeX export to ucs4 when we read them.
It would be nice if you could do these changes. The best method would be
IMHO to make idocfstream symmetric to odocfstream by adding an encoding
argument, and open .bib files with idocfstream instead of std::ifstream.
Then the conversion will be done automatically when you read from the
stream. The only reason why I did not add the encoding argument to
idocfstream yet is that it was not needed so far.


Georg


Index: src/insets/insetbibtex.C
===================================================================
--- src/insets/insetbibtex.C    (revision 16276)
+++ src/insets/insetbibtex.C    (working copy)
@@ -24,6 +24,7 @@
 
 #include "frontends/Alert.h"
 
+#include "support/docstream.h"
 #include "support/filetools.h"
 #include "support/lstrings.h"
 #include "support/lyxlib.h"
@@ -32,7 +33,6 @@
 
 #include <boost/tokenizer.hpp>
 
-#include <fstream>
 #include <sstream>
 
 
@@ -66,7 +66,6 @@
 using std::endl;
 using std::getline;
 using std::string;
-using std::ifstream;
 using std::ostream;
 using std::pair;
 using std::vector;
@@ -342,7 +341,7 @@
                // files. All it does is to look for lines starting
                // in @ and not being @preamble and @string entries.
                // It does NOT do any syntax checking!
-               ifstream ifs(it->toFilesystemEncoding().c_str());
+               idocfstream ifs(it->toFilesystemEncoding().c_str());
                string linebuf0;
                while (getline(ifs, linebuf0)) {
                        string linebuf = trim(linebuf0);
Index: src/support/docstream.C
===================================================================
--- src/support/docstream.C     (revision 16276)
+++ src/support/docstream.C     (working copy)
@@ -199,20 +199,21 @@
 }
 
 
-idocfstream::idocfstream() : base()
+idocfstream::idocfstream(string const & encoding) : base()
 {
        std::locale global;
-       std::locale locale(global, new iconv_codecvt_facet(utf8_codeset, in));
+       std::locale locale(global, new iconv_codecvt_facet(encoding, in));
        imbue(locale);
 }
 
        
-idocfstream::idocfstream(const char* s, std::ios_base::openmode mode)
+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(utf8_codeset, in));
+       std::locale locale(global, new iconv_codecvt_facet(encoding, in));
        imbue(locale);
        open(s, mode);
 }
Index: src/support/docstream.h
===================================================================
--- src/support/docstream.h     (revision 16276)
+++ src/support/docstream.h     (working copy)
@@ -45,9 +45,10 @@
 class idocfstream : public std::basic_ifstream<char_type> {
        typedef std::basic_ifstream<char_type> base;
 public:
-       idocfstream();
+       idocfstream(std::string const & encoding = "UTF-8");
        explicit idocfstream(const char* s,
-               std::ios_base::openmode mode = std::ios_base::in);
+               std::ios_base::openmode mode = std::ios_base::in,
+               std::string const & encoding = "UTF-8");
        ~idocfstream() {}
 };
 

Reply via email to