]> git.lyx.org Git - lyx.git/blob - src/support/unicode.h
add comment about location of the implementation.
[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 <boost/scoped_ptr.hpp>
19
20 #include <string>
21 #include <vector>
22
23
24 namespace lyx {
25
26 class IconvProcessor
27 {
28 public:
29         IconvProcessor(
30                 char const * tocode = "",
31                 char const * fromcode = "");
32         /// copy constructor needed because of pimpl_
33         IconvProcessor(IconvProcessor const &);
34         /// assignment operator needed because of pimpl_
35         IconvProcessor & operator=(IconvProcessor const &);
36         /// destructor (needs to be implemented in the .C file because the
37         /// boost::scoped_ptr destructor needs a fully defined type
38         ~IconvProcessor();
39
40         /// convert any data from \c fromcode to \c tocode unicode format.
41         /// \return the number of bytes of the converted output buffer.
42         int convert(
43                 char const * in_buffer,
44                 size_t in_size,
45                 char * out_buffer,
46                 size_t max_out_size);
47 private:
48         /// open iconv.
49         /// \return true if the processor is ready to use.
50         bool init();
51
52         std::string tocode_;
53         std::string fromcode_;
54
55         struct Private;
56         boost::scoped_ptr<Private> pimpl_;
57 };
58
59 /// This is implemented in lyx_main.C for the LyX program 
60 /// and in client.C for the LyX client program.
61 extern IconvProcessor & utf8ToUcs4();
62
63 // A single codepoint conversion for utf8_to_ucs4 does not make
64 // sense, so that function is left out.
65
66 std::vector<lyx::char_type> utf8_to_ucs4(std::vector<char> const & utf8str);
67
68 std::vector<lyx::char_type> utf8_to_ucs4(char const * utf8str, size_t ls);
69
70 // ucs2_to_ucs4
71
72 lyx::char_type ucs2_to_ucs4(unsigned short c);
73
74 std::vector<lyx::char_type>
75 ucs2_to_ucs4(std::vector<unsigned short> const & ucs2str);
76
77 std::vector<lyx::char_type>
78 ucs2_to_ucs4(unsigned short const * ucs2str, size_t ls);
79
80 // ucs4_to_ucs2
81
82 unsigned short ucs4_to_ucs2(lyx::char_type c);
83
84 std::vector<unsigned short>
85 ucs4_to_ucs2(std::vector<lyx::char_type> const & ucs4str);
86
87 std::vector<unsigned short> ucs4_to_ucs2(lyx::char_type const * s, size_t ls);
88
89 // ucs4_to_utf8
90
91 std::vector<char> ucs4_to_utf8(lyx::char_type c);
92
93 std::vector<char> ucs4_to_utf8(std::vector<lyx::char_type> const & ucs4str);
94
95 std::vector<char> ucs4_to_utf8(lyx::char_type const * ucs4str, size_t ls);
96
97 /// convert \p s from encoding \p encoding to ucs4.
98 /// \p encoding must be a valid iconv 8bit encoding
99 std::vector<lyx::char_type>
100 eightbit_to_ucs4(char const * s, size_t ls, std::string const & encoding);
101
102 /// convert \p s from ucs4 to encoding \p encoding.
103 /// \p encoding must be a valid iconv 8bit encoding
104 std::vector<char>
105 ucs4_to_eightbit(lyx::char_type const * ucs4str, size_t ls, std::string const & encoding);
106
107 extern char const * ucs4_codeset;
108 extern char const * ucs2_codeset;
109
110
111 } // namespace lyx
112
113 #endif