]> git.lyx.org Git - lyx.git/blob - src/support/qstring_helpers.h
d5f2921af7a8ac617be2739664e8de71e8c06bb8
[lyx.git] / src / support / qstring_helpers.h
1 // -*- C++ -*-
2 /**
3  * \file qstring_helpers.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Dekel Tsur
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef QSTRING_HELPERS_H
13 #define QSTRING_HELPERS_H
14
15 #include "support/strfwd.h"
16
17 class QString;
18
19 namespace lyx {
20
21 /**
22  * toqstr - convert a UTF8 encoded char * into a QString
23  *
24  * This should not be used, since all possibly non-ASCII stuff should be
25  * stored in a docstring.
26  */
27 QString toqstr(char const * str);
28
29
30 /**
31  * toqstr - convert a UTF8 encoded std::string into a QString
32  *
33  * This should not be used, since all possibly non-ASCII stuff should be
34  * stored in a docstring.
35  */
36 QString toqstr(std::string const & str);
37
38
39 /// Is \p c a valid utf16 char?
40 inline bool is_utf16(unsigned int c)
41 {
42         // 0xd800 ... 0xdfff is the range of surrogate pairs.
43         return c < 0xd800 || (c > 0xdfff && c < 0x10000);
44 }
45
46
47 /**
48  * toqstr - convert a UCS4 encoded docstring into a QString
49  *
50  * This is the preferred method of converting anything that possibly
51  * contains non-ASCII stuff to QString.
52  */
53 QString toqstr(docstring const & ucs4);
54
55 /**
56  * toqstr - convert a UCS4 encoded character into a QString
57  *
58  * This is the preferred method of converting anything that possibly
59  * contains non-ASCII stuff to QString.
60  */
61 QString toqstr(char_type ucs4);
62
63 /**
64  * qstring_to_ucs4 - convert a QString into a UCS4 encoded docstring
65  *
66  * This is the preferred method of converting anything that possibly
67  * contains non-ASCII stuff to docstring.
68  */
69 docstring qstring_to_ucs4(QString const & qstr);
70
71 /**
72  * fromqstr - convert a QString into a UTF8 encoded std::string
73  *
74  * This should not be used except for output to lyxerr, since all possibly
75  * non-ASCII stuff should be stored in a docstring.
76  */
77 std::string fromqstr(QString const & str);
78
79 } // namespace lyx
80
81 #endif // QSTRING_HELPERS_H