]> git.lyx.org Git - lyx.git/blob - src/support/unicode.h
Fix several filename and environment variable encoding problems
[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 // utf16_to_ucs4
71
72 std::vector<char_type> utf16_to_ucs4(unsigned short const * s, size_t ls);
73
74 // ucs4_to_utf16
75
76 std::vector<unsigned short> ucs4_to_utf16(char_type const * s, size_t ls);
77
78 // ucs4_to_utf8
79
80 std::vector<char> ucs4_to_utf8(lyx::char_type c);
81
82 std::vector<char> ucs4_to_utf8(std::vector<lyx::char_type> const & ucs4str);
83
84 std::vector<char> ucs4_to_utf8(lyx::char_type const * ucs4str, size_t ls);
85
86 /// convert \p s from encoding \p encoding to ucs4.
87 /// \p encoding must be a valid iconv 8bit encoding
88 std::vector<lyx::char_type>
89 eightbit_to_ucs4(char const * s, size_t ls, std::string const & encoding);
90
91 /// convert \p s from ucs4 to encoding \p encoding.
92 /// \p encoding must be a valid iconv 8bit encoding
93 std::vector<char>
94 ucs4_to_eightbit(lyx::char_type const * ucs4str, size_t ls, std::string const & encoding);
95
96 extern char const * ucs4_codeset;
97
98
99 } // namespace lyx
100
101 #endif