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"
27 IconvProcessor(char const * tocode = "", char const * fromcode = "");
28 /// copy constructor needed because of pimpl_
29 IconvProcessor(IconvProcessor const &);
30 /// assignment operator needed because of pimpl_
31 void operator=(IconvProcessor const &);
35 /// convert any data from \c fromcode to \c tocode unicode format.
36 /// \return the number of bytes of the converted output buffer.
37 int convert(char const * in_buffer, size_t in_size,
38 char * out_buffer, size_t max_out_size);
41 std::string from() const;
43 std::string to() const;
47 /// \return true if the processor is ready to use.
54 // A single codepoint conversion for utf8_to_ucs4 does not make
55 // sense, so that function is left out.
57 std::vector<char_type> utf8_to_ucs4(std::vector<char> const & utf8str);
59 std::vector<char_type> utf8_to_ucs4(char const * utf8str, size_t ls);
63 std::vector<char_type> utf16_to_ucs4(unsigned short const * s, size_t ls);
67 std::vector<unsigned short> ucs4_to_utf16(char_type const * s, size_t ls);
71 std::vector<char> ucs4_to_utf8(char_type c);
73 std::vector<char> ucs4_to_utf8(std::vector<char_type> const & ucs4str);
75 std::vector<char> ucs4_to_utf8(char_type const * ucs4str, size_t ls);
77 /// convert \p s from encoding \p encoding to ucs4.
78 /// \p encoding must be a valid iconv 8bit encoding
79 std::vector<char_type>
80 eightbit_to_ucs4(char const * s, size_t ls, std::string const & encoding);
82 /// convert \p s from ucs4 to encoding \p encoding.
83 /// \p encoding must be a valid iconv 8bit encoding
84 std::vector<char> ucs4_to_eightbit(char_type const * ucs4str,
85 size_t ls, std::string const & encoding);
87 /// convert ucs4 character \p c to encoding \p encoding.
88 /// \p encoding must be a valid iconv 8bit encoding
89 char ucs4_to_eightbit(char_type c, std::string const & encoding);
92 void ucs4_to_multibytes(char_type ucs4, std::vector<char> & out,
93 std::string const & encoding);
95 extern char const * ucs4_codeset;
97 /// How many bytes does one UCS4 code point use at most in encoding \p encoding?
98 int max_encoded_bytes(std::string const & encoding);