Warning: That file was not part of the compilation database. It may have many parsing errors.
1 | /**************************************************************************** |
---|---|
2 | ** |
3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
5 | ** |
6 | ** This file is part of the tools applications of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 2.1 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
24 | ** |
25 | ** In addition, as a special exception, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
36 | ** |
37 | ** |
38 | ** $QT_END_LICENSE$ |
39 | ** |
40 | ****************************************************************************/ |
41 | |
42 | /* |
43 | codechunk.cpp |
44 | */ |
45 | |
46 | #include <qregexp.h> |
47 | #include <qstringlist.h> |
48 | |
49 | #include "codechunk.h" |
50 | |
51 | QT_BEGIN_NAMESPACE |
52 | |
53 | enum { Other, Alnum, Gizmo, Comma, LParen, RParen, RAngle, Colon }; |
54 | |
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, |
61 | // ! " # $ % & ' |
62 | Other, Other, Other, Other, Other, Gizmo, Gizmo, Other, |
63 | // ( ) * + , - . / |
64 | LParen, RParen, Gizmo, Gizmo, Comma, Other, Other, Gizmo, |
65 | // 0 1 2 3 4 5 6 7 |
66 | Alnum, Alnum, Alnum, Alnum, Alnum, Alnum, Alnum, Alnum, |
67 | // 8 9 : ; < = > ? |
68 | Alnum, Alnum, Colon, Other, Other, Gizmo, RAngle, Gizmo, |
69 | // @ A B C D E F G |
70 | Other, Alnum, Alnum, Alnum, Alnum, Alnum, Alnum, Alnum, |
71 | // H I J K L M N O |
72 | Alnum, Alnum, Alnum, Alnum, Alnum, Alnum, Alnum, Alnum, |
73 | // P Q R S T U V W |
74 | Alnum, Alnum, Alnum, Alnum, Alnum, Alnum, Alnum, Alnum, |
75 | // X Y Z [ \ ] ^ _ |
76 | Alnum, Alnum, Alnum, Other, Other, Other, Gizmo, Alnum, |
77 | // ` a b c d e f g |
78 | Other, Alnum, Alnum, Alnum, Alnum, Alnum, Alnum, Alnum, |
79 | // h i j k l m n o |
80 | Alnum, Alnum, Alnum, Alnum, Alnum, Alnum, Alnum, Alnum, |
81 | // p q r s t u v w |
82 | Alnum, Alnum, Alnum, Alnum, Alnum, Alnum, Alnum, Alnum, |
83 | // x y z { | } ~ |
84 | Alnum, Alnum, Alnum, LParen, Gizmo, RParen, Other, Other |
85 | }; |
86 | |
87 | static const bool needSpace[8][8] = { |
88 | /* [ a + , ( ) > : */ |
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 } |
97 | }; |
98 | |
99 | static int category( QChar ch ) |
100 | { |
101 | return charCategory[(int)ch.toLatin1()]; |
102 | } |
103 | |
104 | CodeChunk::CodeChunk() |
105 | : hotspot( -1 ) |
106 | { |
107 | } |
108 | |
109 | CodeChunk::CodeChunk( const QString& str ) |
110 | : s( str ), hotspot( -1 ) |
111 | { |
112 | } |
113 | |
114 | void CodeChunk::append( const QString& lexeme ) |
115 | { |
116 | if ( !s.isEmpty() && !lexeme.isEmpty() ) { |
117 | /* |
118 | Should there be a space or not between the code chunk so far and the |
119 | new lexeme? |
120 | */ |
121 | int cat1 = category(s.at(s.size() - 1)); |
122 | int cat2 = category(lexeme[0]); |
123 | if ( needSpace[cat1][cat2] ) |
124 | s += QLatin1Char( |
125 | } |
126 | s += lexeme; |
127 | } |
128 | |
129 | void CodeChunk::appendHotspot() |
130 | { |
131 | /* |
132 | The first hotspot is the right one. |
133 | */ |
134 | if ( hotspot == -1 ) |
135 | hotspot = s.length(); |
136 | } |
137 | |
138 | QString CodeChunk::toString() const |
139 | { |
140 | return s; |
141 | } |
142 | |
143 | QStringList CodeChunk::toPath() const |
144 | { |
145 | QString t = s; |
146 | t.remove(QRegExp(QLatin1String("<([^<>]|<([^<>]|<[^<>]*>)*>)*>"))); |
147 | return t.split(QLatin1String("::")); |
148 | } |
149 | |
150 | QT_END_NAMESPACE |
151 |
Warning: That file was not part of the compilation database. It may have many parsing errors.