3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS.
10 * A collection of unicode conversion functions, using iconv.
13 #ifndef LYX_SUPPORT_UNICODE_H
14 #define LYX_SUPPORT_UNICODE_H
16 #include "support/types.h"
18 #include <boost/scoped_ptr.hpp>
30 char const * tocode = "",
31 char const * fromcode = "");
32 /// copy constructor needed because of pimpl_
33 IconvProcessor(IconvProcessor const &);
34 /// assignment operator needed because of pimpl_
35 IconvProcessor & operator=(IconvProcessor const &);
36 /// destructor (needs to be implemented in the .C file because the
37 /// boost::scoped_ptr destructor needs a fully defined type
40 /// convert any data from \c fromcode to \c tocode unicode format.
41 /// \return the number of bytes of the converted output buffer.
43 char const * in_buffer,
49 /// \return true if the processor is ready to use.
53 std::string fromcode_;
56 boost::scoped_ptr<Private> pimpl_;
61 // A single codepoint conversion for utf8_to_ucs4 does not make
62 // sense, so that function is left out.
64 std::vector<lyx::char_type> utf8_to_ucs4(std::vector<char> const & utf8str);
66 std::vector<lyx::char_type> utf8_to_ucs4(char const * utf8str, size_t ls);
70 lyx::char_type ucs2_to_ucs4(unsigned short c);
72 std::vector<lyx::char_type>
73 ucs2_to_ucs4(std::vector<unsigned short> const & ucs2str);
75 std::vector<lyx::char_type>
76 ucs2_to_ucs4(unsigned short const * ucs2str, size_t ls);
80 unsigned short ucs4_to_ucs2(lyx::char_type c);
82 std::vector<unsigned short>
83 ucs4_to_ucs2(std::vector<lyx::char_type> const & ucs4str);
85 std::vector<unsigned short> ucs4_to_ucs2(lyx::char_type const * s, size_t ls);
89 std::vector<char> ucs4_to_utf8(lyx::char_type c);
91 std::vector<char> ucs4_to_utf8(std::vector<lyx::char_type> const & ucs4str);
93 std::vector<char> ucs4_to_utf8(lyx::char_type const * ucs4str, size_t ls);
95 /// convert \p s from encoding \p encoding to ucs4.
96 /// \p encoding must be a valid iconv 8bit encoding
97 std::vector<lyx::char_type>
98 eightbit_to_ucs4(char const * s, size_t ls, std::string const & encoding);
100 /// convert \p s from ucs4 to encoding \p encoding.
101 /// \p encoding must be a valid iconv 8bit encoding
103 ucs4_to_eightbit(lyx::char_type const * ucs4str, size_t ls, std::string const & encoding);
105 extern char const * ucs4_codeset;
106 extern char const * ucs2_codeset;