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/strfwd.h"
26 IconvProcessor(char const * tocode = "", char const * fromcode = "");
27 /// copy constructor needed because of pimpl_
28 IconvProcessor(IconvProcessor const &);
29 /// assignment operator needed because of pimpl_
30 void operator=(IconvProcessor const &);
34 /// convert any data from \c fromcode to \c tocode unicode format.
35 /// \return the number of bytes of the converted output buffer.
36 int convert(char const * in_buffer, size_t in_size,
37 char * out_buffer, size_t max_out_size);
40 std::string from() const;
42 std::string to() const;
46 /// \return true if the processor is ready to use.
53 // A single codepoint conversion for utf8_to_ucs4 does not make
54 // sense, so that function is left out.
56 std::vector<char_type> utf8_to_ucs4(std::vector<char> const & utf8str);
58 std::vector<char_type> utf8_to_ucs4(char const * utf8str, size_t ls);
62 std::vector<char_type> utf16_to_ucs4(unsigned short const * s, size_t ls);
66 std::vector<unsigned short> ucs4_to_utf16(char_type const * s, size_t ls);
70 std::vector<char> ucs4_to_utf8(char_type c);
72 std::vector<char> ucs4_to_utf8(std::vector<char_type> const & ucs4str);
74 std::vector<char> ucs4_to_utf8(char_type const * ucs4str, size_t ls);
76 /// convert \p s from encoding \p encoding to ucs4.
77 /// \p encoding must be a valid iconv 8bit encoding
78 std::vector<char_type>
79 eightbit_to_ucs4(char const * s, size_t ls, std::string const & encoding);
81 /// convert \p s from ucs4 to encoding \p encoding.
82 /// \p encoding must be a valid iconv 8bit encoding
83 std::vector<char> ucs4_to_eightbit(char_type const * ucs4str,
84 size_t ls, std::string const & encoding);
86 /// convert ucs4 character \p c to encoding \p encoding.
87 /// \p encoding must be a valid iconv 8bit encoding
88 char ucs4_to_eightbit(char_type c, std::string const & encoding);
91 void ucs4_to_multibytes(char_type ucs4, std::vector<char> & out,
92 std::string const & encoding);
94 extern char const * ucs4_codeset;
96 /// How many bytes does one UCS4 code point use at most in encoding \p encoding?
97 int max_encoded_bytes(std::string const & encoding);