OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / texteditor / generichighlighter / reuse.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef REUSE_H
34 #define REUSE_H
35
36 #include <Qt>
37 #include <QtCore/QString>
38 #include <QtCore/QLatin1String>
39 #include <QtCore/QChar>
40 #include <QtGui/QFont>
41
42 namespace TextEditor {
43 namespace Internal {
44
45 inline bool toBool(const QString &s)
46 {
47     static const QLatin1String kTrue("true");
48     static const QLatin1String k1("1");
49
50     if (s.toLower() == kTrue || s == k1)
51         return true;
52     return false;
53 }
54
55
56 inline Qt::CaseSensitivity toCaseSensitivity(const bool sensitive)
57 {
58     if (sensitive)
59         return Qt::CaseSensitive;
60     return Qt::CaseInsensitive;
61 }
62
63 inline QFont::Weight toFontWeight(const bool bold)
64 {
65     if (bold)
66         return QFont::Bold;
67     else
68         return QFont::Normal;
69 }
70
71 inline bool isOctalDigit(const QChar &c)
72 {
73     static const QLatin1Char k0('0');
74     static const QLatin1Char k7('7');
75
76     return c >= k0 && c <= k7;
77 }
78
79 inline bool isHexDigit(const QChar &c)
80 {
81     static const QLatin1Char k0('0');
82     static const QLatin1Char k9('9');
83     static const QLatin1Char kA('A');
84     static const QLatin1Char kF('F');
85     static const QLatin1Char ka('a');
86     static const QLatin1Char kf('f');
87
88     if ((c >= k0 && c <= k9) || (c >= kA && c <= kF) || (c >= ka && c <= kf))
89         return true;
90
91     return false;
92 }
93
94 inline void setStartCharacter(QChar *c, const QString &character)
95 {
96     if (!character.isEmpty())
97         *c = character.at(0);
98 }
99
100 } // namespace Internal
101 } // namespace TextEditor
102
103 #endif // REUSE_H