]> git.lyx.org Git - lyx.git/blob - src/support/unicode.h
Make it possible to uses non-ascii labelstring, endlabelstring and
[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/types.h"
17
18 #include <string>
19 #include <vector>
20
21
22 namespace lyx {
23
24 class IconvProcessor
25 {
26 public:
27         IconvProcessor(
28                 char const * tocode = "",
29                 char const * fromcode = "");
30         ~IconvProcessor();
31
32         /// convert any data from \c fromcode to \c tocode unicode format.
33         /// \return the number of bytes of the converted output buffer.
34         int convert(
35                 char const * in_buffer,
36                 size_t in_size,
37                 char * out_buffer,
38                 size_t max_out_size);
39 private:
40         /// open iconv.
41         /// \return true if the processor is ready to use.
42         bool init();
43
44         std::string tocode_;
45         std::string fromcode_;
46
47         struct Private;
48         Private * pimpl_;
49 };
50
51 // utf8_to_ucs4
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<lyx::char_type> utf8_to_ucs4(std::vector<char> const & utf8str);
57
58 std::vector<lyx::char_type> utf8_to_ucs4(char const * utf8str, size_t ls);
59
60 // ucs2_to_ucs4
61
62 lyx::char_type ucs2_to_ucs4(unsigned short c);
63
64 std::vector<lyx::char_type>
65 ucs2_to_ucs4(std::vector<unsigned short> const & ucs2str);
66
67 std::vector<lyx::char_type>
68 ucs2_to_ucs4(unsigned short const * ucs2str, size_t ls);
69
70 // ucs4_to_ucs2
71
72 unsigned short ucs4_to_ucs2(lyx::char_type c);
73
74 std::vector<unsigned short>
75 ucs4_to_ucs2(std::vector<lyx::char_type> const & ucs4str);
76
77 std::vector<unsigned short> ucs4_to_ucs2(lyx::char_type const * s, size_t ls);
78
79 // ucs4_to_utf8
80
81 std::vector<char> ucs4_to_utf8(lyx::char_type c);
82
83 std::vector<char> ucs4_to_utf8(std::vector<lyx::char_type> const & ucs4str);
84
85 std::vector<char> ucs4_to_utf8(lyx::char_type const * ucs4str, size_t ls);
86
87 /// convert \p s from encoding \p encoding to ucs4.
88 /// \p encoding must be a valid iconv 8bit encoding
89 std::vector<lyx::char_type>
90 eightbit_to_ucs4(char const * s, size_t ls, std::string const & encoding);
91
92 /// convert \p s from ucs4 to encoding \p encoding.
93 /// \p encoding must be a valid iconv 8bit encoding
94 std::vector<char>
95 ucs4_to_eightbit(lyx::char_type const * ucs4str, size_t ls, std::string const & encoding);
96
97 extern char const * ucs4_codeset;
98 extern char const * ucs2_codeset;
99
100
101 } // namespace lyx
102
103 #endif