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.
9 * Full author contact details are available in file CREDITS.
12 #ifndef QSTRING_HELPERS_H
13 #define QSTRING_HELPERS_H
15 #include "support/docstring.h"
22 * toqstr - convert a UTF8 encoded char * into a QString
24 * This should not be used, since all possibly non-ASCII stuff should be
25 * stored in a docstring.
27 inline QString const toqstr(char const * str)
29 return QString::fromUtf8(str);
34 * toqstr - convert a UTF8 encoded std::string into a QString
36 * This should not be used, since all possibly non-ASCII stuff should be
37 * stored in a docstring.
39 inline QString const toqstr(std::string const & str)
41 return toqstr(str.c_str());
45 /// Is \p c a valid utf16 char?
46 inline bool is_utf16(char_type c)
48 // 0xd800 ... 0xdfff is the range of surrogate pairs.
49 return c < 0xd800 || (c > 0xdfff && c < 0x10000);
54 * toqstr - convert a UCS4 encoded docstring into a QString
56 * This is the preferred method of converting anything that possibly
57 * contains non-ASCII stuff to QString.
59 #if QT_VERSION >= 0x040200
60 inline QString const toqstr(docstring const & ucs4)
62 // If possible we let qt do the work, since this version does not
63 // need to be superfast.
64 return QString::fromUcs4(reinterpret_cast<uint const *>(ucs4.data()), ucs4.length());
67 QString const toqstr(docstring const & ucs4);
72 * qstring_to_ucs4 - convert a QString into a UCS4 encoded docstring
74 * This is the preferred method of converting anything that possibly
75 * contains non-ASCII stuff to docstring.
77 docstring const qstring_to_ucs4(QString const & qstr);
81 * fromqstr - convert a QString into a UTF8 encoded std::string
83 * This should not be used except for output to lyxerr, since all possibly
84 * non-ASCII stuff should be stored in a docstring.
86 std::string const fromqstr(QString const & str);
90 #endif // QSTRING_HELPERS_H