]> git.lyx.org Git - features.git/blob - src/support/qstring_helpers.h
Mode [un]locLengthString() methods to support/qstring_helpers
[features.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 class LyXErr;
22
23 LyXErr & operator<<(LyXErr &, QString const &);
24
25 /**
26  * toqstr - convert a UTF8 encoded char * into a QString
27  *
28  * This should not be used, since all possibly non-ASCII stuff should be
29  * stored in a docstring.
30  */
31 QString toqstr(char const * str);
32
33
34 /**
35  * toqstr - convert a UTF8 encoded std::string into a QString
36  *
37  * This should not be used, since all possibly non-ASCII stuff should be
38  * stored in a docstring.
39  */
40 QString toqstr(std::string const & str);
41
42
43 /// Is \p c a valid utf16 char?
44 inline bool is_utf16(char_type c)
45 {
46         // 0xd800 ... 0xdfff is the range of surrogate pairs.
47         return c < 0xd800 || (c > 0xdfff && c < 0x10000);
48 }
49
50
51 /**
52  * toqstr - convert a UCS4 encoded docstring into a QString
53  *
54  * This is the preferred method of converting anything that possibly
55  * contains non-ASCII stuff to QString.
56  */
57 QString toqstr(docstring const & ucs4);
58
59 /**
60  * toqstr - convert a UCS4 encoded character into a QString
61  *
62  * This is the preferred method of converting anything that possibly
63  * contains non-ASCII stuff to QString.
64  */
65 QString toqstr(char_type ucs4);
66
67 /**
68  * qstring_to_ucs4 - convert a QString into a UCS4 encoded docstring
69  *
70  * This is the preferred method of converting anything that possibly
71  * contains non-ASCII stuff to docstring.
72  */
73 docstring qstring_to_ucs4(QString const & qstr);
74
75 /**
76  * fromqstr - convert a QString into a UTF8 encoded std::string
77  *
78  * This should not be used except for output to lyxerr, since all possibly
79  * non-ASCII stuff should be stored in a docstring.
80  */
81 std::string fromqstr(QString const & str);
82
83 /**
84  * constructs a regex to filter on consecutive characters
85  * matches lower- and uppercase on lowercase characters,
86  * and just uppercase for uppercase
87  */
88 QString charFilterRegExp(QString const & filter);
89
90 /**
91  * as above, but constructs a capturing regex for a sequence of characters
92  */
93 QString charFilterRegExpC(QString const & filter);
94
95 /// Method to replace dot with localized decimal separator
96 QString locLengthString(QString const & str);
97
98 /// Same for doscstring
99 docstring locLengthDocString(docstring const str);
100
101 /// Method to replace localized decimal separator by dot
102 QString unlocLengthString(QString const & str);
103
104 } // namespace lyx
105
106 #endif // QSTRING_HELPERS_H