]> git.lyx.org Git - lyx.git/blob - src/support/unicode.h
Remove unused macros USE_INCLUDED_STRING and STD_STRING_IS_GOOD
[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 private:
40         /// open iconv.
41         /// \return true if the processor is ready to use.
42         bool init();
43         /// hide internals
44         struct Impl;
45         Impl * pimpl_;
46 };
47
48 // A single codepoint conversion for utf8_to_ucs4 does not make
49 // sense, so that function is left out.
50
51 std::vector<char_type> utf8_to_ucs4(std::vector<char> const & utf8str);
52
53 std::vector<char_type> utf8_to_ucs4(char const * utf8str, size_t ls);
54
55 // utf16_to_ucs4
56
57 std::vector<char_type> utf16_to_ucs4(unsigned short const * s, size_t ls);
58
59 // ucs4_to_utf16
60
61 std::vector<unsigned short> ucs4_to_utf16(char_type const * s, size_t ls);
62
63 // ucs4_to_utf8
64
65 std::vector<char> ucs4_to_utf8(char_type c);
66
67 std::vector<char> ucs4_to_utf8(std::vector<char_type> const & ucs4str);
68
69 std::vector<char> ucs4_to_utf8(char_type const * ucs4str, size_t ls);
70
71 /// convert \p s from encoding \p encoding to ucs4.
72 /// \p encoding must be a valid iconv 8bit encoding
73 std::vector<char_type>
74 eightbit_to_ucs4(char const * s, size_t ls, std::string const & encoding);
75
76 /// convert \p s from ucs4 to encoding \p encoding.
77 /// \p encoding must be a valid iconv 8bit encoding
78 std::vector<char> ucs4_to_eightbit(char_type const * ucs4str,
79         size_t ls, std::string const & encoding);
80
81 /// convert ucs4 character \p c to encoding \p encoding.
82 /// \p encoding must be a valid iconv 8bit encoding
83 char ucs4_to_eightbit(char_type c, std::string const & encoding);
84
85 ///
86 void ucs4_to_multibytes(char_type ucs4, std::vector<char> & out,
87         std::string const & encoding);
88
89 extern char const * ucs4_codeset;
90
91
92 } // namespace lyx
93
94 #endif