]> git.lyx.org Git - lyx.git/blob - src/support/unicode.h
add onoff support for "inset-modify changetype xxx" in include inset
[lyx.git] / src / support / unicode.h
1 /**
2  * \file unicode.h
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  *
8  * Full author contact details are available in file CREDITS.
9  *
10  * A collection of unicode conversion functions, using iconv.
11  */
12
13 #ifndef LYX_SUPPORT_UNICODE_H
14 #define LYX_SUPPORT_UNICODE_H
15
16 #include "support/strfwd.h"
17
18 #include <vector>
19
20
21 namespace lyx {
22
23 class IconvProcessor
24 {
25 public:
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 &);
31         /// destructor
32         ~IconvProcessor();
33
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);
38
39         /// source encoding
40         std::string from() const;
41         /// target encoding
42         std::string to() const;
43
44 private:
45         /// open iconv.
46         /// \return true if the processor is ready to use.
47         bool init();
48         /// hide internals
49         struct Impl;
50         Impl * pimpl_;
51 };
52
53 // A single codepoint conversion for utf8_to_ucs4 does not make
54 // sense, so that function is left out.
55
56 std::vector<char_type> utf8_to_ucs4(std::vector<char> const & utf8str);
57
58 std::vector<char_type> utf8_to_ucs4(char const * utf8str, size_t ls);
59
60 // utf16_to_ucs4
61
62 std::vector<char_type> utf16_to_ucs4(unsigned short const * s, size_t ls);
63
64 // ucs4_to_utf16
65
66 std::vector<unsigned short> ucs4_to_utf16(char_type const * s, size_t ls);
67
68 // ucs4_to_utf8
69
70 std::vector<char> ucs4_to_utf8(char_type c);
71
72 std::vector<char> ucs4_to_utf8(std::vector<char_type> const & ucs4str);
73
74 std::vector<char> ucs4_to_utf8(char_type const * ucs4str, size_t ls);
75
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);
80
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);
85
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);
89
90 ///
91 void ucs4_to_multibytes(char_type ucs4, std::vector<char> & out,
92         std::string const & encoding);
93
94 extern char const * ucs4_codeset;
95
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);
98
99 } // namespace lyx
100
101 #endif