]> git.lyx.org Git - lyx.git/blobdiff - src/support/docstream.C
Don't use a global variable for avoiding removal of the system temp dir
[lyx.git] / src / support / docstream.C
index 03ee204633f7fb36abafb43094e37c3ca7f18907..cec49561563f1af43fbc43c7effea12e01c9b883 100644 (file)
 
 
 using lyx::ucs4_codeset;
-using lyx::ucs2_codeset;
 
 using std::string;
 
 
 namespace {
 
-char const * utf8_codeset = "UTF-8";
-
 // We use C IO throughout this file, because the facets might be used with
 // lyxerr in the future.
 
@@ -148,10 +145,13 @@ protected:
        }
        virtual int do_max_length() const throw()
        {
-               // UTF8 uses at most 6 bytes to represent one UCS4 code point.
+               // UTF8 uses at most 4 bytes to represent one UCS4 code point
+               // (see RFC 3629). RFC 2279 specifies 6 bytes, but that
+               // information is outdated, and RFC 2279 has been superseded by
+               // RFC 3629.
                // All other encodings encode one UCS4 code point in one byte
                // (and can therefore only encode a subset of UCS4)
-               return utf8_ ? 6 : 1;
+               return utf8_ ? 4 : 1;
        }
 private:
        /// Do the actual conversion. The interface is equivalent to that of
@@ -197,20 +197,21 @@ const char * iconv_codecvt_facet_exception::what() const throw()
 }
 
 
-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);
 }