Lars Gullik Bjønnes wrote:
> Perhaps we should go that way anyway. If the underlying systems can
> support what we want (32bit char_types) then we use that, else we have
> to use our own solution.
I dug out the patch. It will use wchar_t if it is a 32bit type.
Maybe we should eliminate hardcoded boost::uint32_t except in docstring.h
even if we don't use wchar_t. What do others think?
Georg
Index: src/lyxlex_pimpl.C
===================================================================
--- src/lyxlex_pimpl.C (Revision 14982)
+++ src/lyxlex_pimpl.C (Arbeitskopie)
@@ -73,7 +73,7 @@ string const LyXLex::Pimpl::getString()
lyx::docstring const LyXLex::Pimpl::getDocString() const
{
- std::vector<boost::uint32_t> res = utf8_to_ucs4(buff);
+ std::vector<lyx::char_type> res = utf8_to_ucs4(buff);
lyx::docstring dstr(res.begin(), res.end());
return dstr;
}
Index: src/frontends/qt3/QLPainter.C
===================================================================
--- src/frontends/qt3/QLPainter.C (Revision 14982)
+++ src/frontends/qt3/QLPainter.C (Arbeitskopie)
@@ -222,7 +222,7 @@ void QLPainter::text(int x, int y, lyx::
// Brain-dead MSVC wants at(i) rather than operator[]
str.at(i) = QChar(encoding->ucs(s[i]));
#else
- //std::vector<boost::uint32_t> in(s, s + ls);
+ //std::vector<lyx::char_type> in(s, s + ls);
//std::vector<unsigned short> ucs2 = ucs4_to_ucs2(in);
std::vector<unsigned short> ucs2 = ucs4_to_ucs2(s, ls);
ucs2.push_back(0);
Index: src/frontends/qt4/qt_helpers.C
===================================================================
--- src/frontends/qt4/qt_helpers.C (Revision 14982)
+++ src/frontends/qt4/qt_helpers.C (Arbeitskopie)
@@ -159,13 +159,13 @@ void qstring_to_ucs4(QString const & qst
int const ls = qstr.size();
ucs4.clear();
for (int i = 0; i < ls; ++i)
- ucs4.push_back(static_cast<boost::uint32_t>(qstr[i].unicode()));
+ ucs4.push_back(static_cast<lyx::char_type>(qstr[i].unicode()));
}
char_type const qchar_to_ucs4(QChar const & qchar)
{
- return static_cast<boost::uint32_t>(qchar.unicode());
+ return static_cast<lyx::char_type>(qchar.unicode());
}
Index: src/support/unicode.C
===================================================================
--- src/support/unicode.C (Revision 14982)
+++ src/support/unicode.C (Arbeitskopie)
@@ -124,60 +124,60 @@ iconv_convert(iconv_t * cd,
} // anon namespace
-std::vector<boost::uint32_t> utf8_to_ucs4(std::vector<char> const & utf8str)
+std::vector<lyx::char_type> utf8_to_ucs4(std::vector<char> const & utf8str)
{
return utf8_to_ucs4(&utf8str[0], utf8str.size());
}
-std::vector<boost::uint32_t>
+std::vector<lyx::char_type>
utf8_to_ucs4(char const * utf8str, size_t ls)
{
static iconv_t cd = (iconv_t)(-1);
- return iconv_convert<boost::uint32_t>(&cd, ucs4_codeset, "UTF-8",
+ return iconv_convert<lyx::char_type>(&cd, ucs4_codeset, "UTF-8",
utf8str, ls);
}
-boost::uint32_t
+lyx::char_type
ucs2_to_ucs4(unsigned short c)
{
return ucs2_to_ucs4(&c, 1)[0];
}
-std::vector<boost::uint32_t>
+std::vector<lyx::char_type>
ucs2_to_ucs4(std::vector<unsigned short> const & ucs2str)
{
return ucs2_to_ucs4(&ucs2str[0], ucs2str.size());
}
-std::vector<boost::uint32_t>
+std::vector<lyx::char_type>
ucs2_to_ucs4(unsigned short const * ucs2str, size_t ls)
{
static iconv_t cd = (iconv_t)(-1);
- return iconv_convert<boost::uint32_t>(&cd, ucs4_codeset, ucs2_codeset,
+ return iconv_convert<lyx::char_type>(&cd, ucs4_codeset, ucs2_codeset,
ucs2str, ls);
}
unsigned short
-ucs4_to_ucs2(boost::uint32_t c)
+ucs4_to_ucs2(lyx::char_type c)
{
return ucs4_to_ucs2(&c, 1)[0];
}
std::vector<unsigned short>
-ucs4_to_ucs2(std::vector<boost::uint32_t> const & ucs4str)
+ucs4_to_ucs2(std::vector<lyx::char_type> const & ucs4str)
{
return ucs4_to_ucs2(&ucs4str[0], ucs4str.size());
}
std::vector<unsigned short>
-ucs4_to_ucs2(boost::uint32_t const * s, size_t ls)
+ucs4_to_ucs2(lyx::char_type const * s, size_t ls)
{
static iconv_t cd = (iconv_t)(-1);
return iconv_convert<unsigned short>(&cd, ucs2_codeset, ucs4_codeset,
@@ -186,7 +186,7 @@ ucs4_to_ucs2(boost::uint32_t const * s,
std::vector<char>
-ucs4_to_utf8(boost::uint32_t c)
+ucs4_to_utf8(lyx::char_type c)
{
static iconv_t cd = (iconv_t)(-1);
return iconv_convert<char>(&cd, "UTF-8", ucs4_codeset, &c, 1);
@@ -194,14 +194,14 @@ ucs4_to_utf8(boost::uint32_t c)
std::vector<char>
-ucs4_to_utf8(std::vector<boost::uint32_t> const & ucs4str)
+ucs4_to_utf8(std::vector<lyx::char_type> const & ucs4str)
{
return ucs4_to_utf8(&ucs4str[0], ucs4str.size());
}
std::vector<char>
-ucs4_to_utf8(boost::uint32_t const * ucs4str, size_t ls)
+ucs4_to_utf8(lyx::char_type const * ucs4str, size_t ls)
{
static iconv_t cd = (iconv_t)(-1);
return iconv_convert<char>(&cd, "UTF-8", ucs4_codeset,
Index: src/support/docstring.C
===================================================================
--- src/support/docstring.C (Revision 14982)
+++ src/support/docstring.C (Arbeitskopie)
@@ -38,7 +38,7 @@ docstring const from_ascii(std::string c
docstring const from_utf8(std::string const & utf8)
{
- std::vector<boost::uint32_t> const ucs4 =
+ std::vector<lyx::char_type> const ucs4 =
utf8_to_ucs4(utf8.data(), utf8.size());
return docstring(ucs4.begin(), ucs4.end());
}
Index: src/support/types.h
===================================================================
--- src/support/types.h (Revision 14982)
+++ src/support/types.h (Arbeitskopie)
@@ -18,20 +18,10 @@
#include "docstring.h"
-#include <boost/cstdint.hpp>
-
#include <cstddef>
-#include <string>
namespace lyx {
- // The type used to hold characters in paragraphs
- typedef boost::uint32_t char_type; // Possibly the ucs-4 type we will use
- //typedef wchar_t char_type; // The wide char type CJK-LyX uses
- //typedef char char_type; // Current narrow char type in use
-
- //typedef std::wstring docstring;
-
/// a type for positions used in paragraphs
// needs to be signed for a while to hold the special value -1 that is
// used there
Index: src/support/unicode.h
===================================================================
--- src/support/unicode.h (Revision 14982)
+++ src/support/unicode.h (Arbeitskopie)
@@ -13,7 +13,8 @@
#ifndef LYX_SUPPORT_UNICODE_H
#define LYX_SUPPORT_UNICODE_H
-#include <boost/cstdint.hpp>
+#include "support/types.h"
+
#include <vector>
// utf8_to_ucs4
@@ -21,43 +22,43 @@
// A single codepoint conversion for utf8_to_ucs4 does not make
// sense, so that function is left out.
-std::vector<boost::uint32_t>
+std::vector<lyx::char_type>
utf8_to_ucs4(std::vector<char> const & utf8str);
-std::vector<boost::uint32_t>
+std::vector<lyx::char_type>
utf8_to_ucs4(char const * utf8str, size_t ls);
// ucs2_to_ucs4
-boost::uint32_t
+lyx::char_type
ucs2_to_ucs4(unsigned short c);
-std::vector<boost::uint32_t>
+std::vector<lyx::char_type>
ucs2_to_ucs4(std::vector<unsigned short> const & ucs2str);
-std::vector<boost::uint32_t>
+std::vector<lyx::char_type>
ucs2_to_ucs4(unsigned short const * ucs2str, size_t ls);
// ucs4_to_ucs2
unsigned short
-ucs4_to_ucs2(boost::uint32_t c);
+ucs4_to_ucs2(lyx::char_type c);
std::vector<unsigned short>
-ucs4_to_ucs2(std::vector<boost::uint32_t> const & ucs4str);
+ucs4_to_ucs2(std::vector<lyx::char_type> const & ucs4str);
std::vector<unsigned short>
-ucs4_to_ucs2(boost::uint32_t const * s, size_t ls);
+ucs4_to_ucs2(lyx::char_type const * s, size_t ls);
// ucs4_to_utf8
std::vector<char>
-ucs4_to_utf8(boost::uint32_t c);
+ucs4_to_utf8(lyx::char_type c);
std::vector<char>
-ucs4_to_utf8(std::vector<boost::uint32_t> const & ucs4str);
+ucs4_to_utf8(std::vector<lyx::char_type> const & ucs4str);
std::vector<char>
-ucs4_to_utf8(boost::uint32_t const * ucs4str, size_t ls);
+ucs4_to_utf8(lyx::char_type const * ucs4str, size_t ls);
#endif
Index: src/support/docstring.h
===================================================================
--- src/support/docstring.h (Revision 14982)
+++ src/support/docstring.h (Arbeitskopie)
@@ -18,8 +18,19 @@
namespace lyx {
+/// The type used to hold characters in paragraphs
+#if defined(HAVE_WCHAR_T) && SIZEOF_WCHAR_T == 4
+// Prefer this if possible because GNU libstdc++ has usable std::ctype<wchar_t>
+// locale facets but not std::ctype<boost::uint32_t>. gcc older than 3.4 is
+// also missing usable std::char_traits<boost::uint32_t>.
+typedef wchar_t char_type;
+#else
+// This works on msvc
+typedef boost::uint32_t char_type;
+#endif
+
/// String type for storing the main text in UCS4 encoding
-typedef std::basic_string<boost::uint32_t> docstring;
+typedef std::basic_string<lyx::char_type> docstring;
/// Creates a docstring from a C string of ASCII characters
docstring const from_ascii(char const *);
@@ -60,7 +77,7 @@ lyx::docstring operator+(lyx::docstring
lyx::docstring operator+(char l, lyx::docstring const & r);
-#if defined(__GNUC__) && defined(__GNUC_MINOR__) && __GNUC__ == 3 && __GNUC_MINOR__ < 4
+#if 0 && defined(__GNUC__) && defined(__GNUC_MINOR__) && __GNUC__ == 3 && __GNUC_MINOR__ < 4
// Missing char_traits methods in gcc 3.3 and older. Taken from gcc 4.2svn.
namespace std {
Index: configure.ac
===================================================================
--- configure.ac (Revision 14982)
+++ configure.ac (Arbeitskopie)
@@ -147,6 +147,9 @@ AC_SUBST(AIKSAURUS_LIBS)
LYX_USE_INCLUDED_BOOST
+# Needed for our char_type
+AC_CHECK_SIZEOF(wchar_t)
+
### Setup libtool
dnl Dirty trick ahead: disable libtool checking for a fortran compiler
dnl see http://permalink.gmane.org/gmane.comp.gnu.libtool.general/6699