1 /****************************************************************************
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the tools applications of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
47 #include <qstringlist.h>
49 #include "codechunk.h"
53 enum { Other
, Alnum
, Gizmo
, Comma
, LParen
, RParen
, RAngle
, Colon
};
55 // entries 128 and above are Other
56 static const int charCategory
[256] = {
57 Other
, Other
, Other
, Other
, Other
, Other
, Other
, Other
,
58 Other
, Other
, Other
, Other
, Other
, Other
, Other
, Other
,
59 Other
, Other
, Other
, Other
, Other
, Other
, Other
, Other
,
60 Other
, Other
, Other
, Other
, Other
, Other
, Other
, Other
,
62 Other
, Other
, Other
, Other
, Other
, Gizmo
, Gizmo
, Other
,
64 LParen
, RParen
, Gizmo
, Gizmo
, Comma
, Other
, Other
, Gizmo
,
66 Alnum
, Alnum
, Alnum
, Alnum
, Alnum
, Alnum
, Alnum
, Alnum
,
68 Alnum
, Alnum
, Colon
, Other
, Other
, Gizmo
, RAngle
, Gizmo
,
70 Other
, Alnum
, Alnum
, Alnum
, Alnum
, Alnum
, Alnum
, Alnum
,
72 Alnum
, Alnum
, Alnum
, Alnum
, Alnum
, Alnum
, Alnum
, Alnum
,
74 Alnum
, Alnum
, Alnum
, Alnum
, Alnum
, Alnum
, Alnum
, Alnum
,
76 Alnum
, Alnum
, Alnum
, Other
, Other
, Other
, Gizmo
, Alnum
,
78 Other
, Alnum
, Alnum
, Alnum
, Alnum
, Alnum
, Alnum
, Alnum
,
80 Alnum
, Alnum
, Alnum
, Alnum
, Alnum
, Alnum
, Alnum
, Alnum
,
82 Alnum
, Alnum
, Alnum
, Alnum
, Alnum
, Alnum
, Alnum
, Alnum
,
84 Alnum
, Alnum
, Alnum
, LParen
, Gizmo
, RParen
, Other
, Other
87 static const bool needSpace
[8][8] = {
89 /* [ */ { false, false, false, false, false, true, false, false },
90 /* a */ { false, true, true, false, false, true, false, false },
91 /* + */ { false, true, false, false, false, true, false, true },
92 /* , */ { true, true, true, true, true, true, true, true },
93 /* ( */ { true, true, true, false, true, false, true, true },
94 /* ) */ { true, true, true, false, true, true, true, true },
95 /* > */ { true, true, true, false, true, true, true, false },
96 /* : */ { false, false, true, true, true, true, true, false }
99 static int category( QChar ch
)
101 return charCategory
[(int)ch
.toLatin1()];
104 CodeChunk::CodeChunk()
109 CodeChunk::CodeChunk( const QString
& str
)
110 : s( str
), hotspot( -1 )
114 void CodeChunk::append( const QString
& lexeme
)
116 if ( !s
.isEmpty() && !lexeme
.isEmpty() ) {
118 Should there be a space or not between the code chunk so far and the
121 int cat1
= category(s
.at(s
.size() - 1));
122 int cat2
= category(lexeme
[0]);
123 if ( needSpace
[cat1
][cat2
] )
124 s
+= QLatin1Char( ' ' );
129 void CodeChunk::appendHotspot()
132 The first hotspot is the right one.
135 hotspot
= s
.length();
138 QString
CodeChunk::toString() const
143 QStringList
CodeChunk::toPath() const
146 t
.remove(QRegExp(QLatin1String("<([^<>]|<([^<>]|<[^<>]*>)*>)*>")));
147 return t
.split(QLatin1String("::"));