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.
}
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
}
-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);
}