Merge branch 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into master-integration
[qt-netbsd.git] / tools / qdoc3 / codechunk.cpp
blob0028af5d3b38f8b671409ad17b33080989827f3c
1 /****************************************************************************
2 **
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the tools applications of the Qt Toolkit.
8 **
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
14 ** this package.
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.
38 ** $QT_END_LICENSE$
40 ****************************************************************************/
43 codechunk.cpp
46 #include <qregexp.h>
47 #include <qstringlist.h>
49 #include "codechunk.h"
51 QT_BEGIN_NAMESPACE
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,
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
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 }
99 static int category( QChar ch )
101 return charCategory[(int)ch.toLatin1()];
104 CodeChunk::CodeChunk()
105 : hotspot( -1 )
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
119 new lexeme?
121 int cat1 = category(s.at(s.size() - 1));
122 int cat2 = category(lexeme[0]);
123 if ( needSpace[cat1][cat2] )
124 s += QLatin1Char( ' ' );
126 s += lexeme;
129 void CodeChunk::appendHotspot()
132 The first hotspot is the right one.
134 if ( hotspot == -1 )
135 hotspot = s.length();
138 QString CodeChunk::toString() const
140 return s;
143 QStringList CodeChunk::toPath() const
145 QString t = s;
146 t.remove(QRegExp(QLatin1String("<([^<>]|<([^<>]|<[^<>]*>)*>)*>")));
147 return t.split(QLatin1String("::"));
150 QT_END_NAMESPACE