Skip to content

Commit

Permalink
Increase constness.
Browse files Browse the repository at this point in the history
  • Loading branch information
steveire committed Jul 15, 2010
1 parent 484a2df commit cc89376
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 101 deletions.
6 changes: 3 additions & 3 deletions corelib/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ContextPrivate
}

Q_DECLARE_PUBLIC( Context )
Context *q_ptr;
Context * const q_ptr;

QList<QVariantHash> m_variantHashStack;
bool m_autoescape;
Expand Down Expand Up @@ -106,7 +106,7 @@ QVariant Context::lookup( const QString &str ) const
// return a variant from the stack.
QListIterator<QVariantHash> i( d->m_variantHashStack );
while ( i.hasNext() ) {
QVariantHash h = i.next();
const QVariantHash h = i.next();
if ( h.contains( str ) ) {
QVariant var = h.value( str );
// If the user passed a string into the context, turn it into a Grantlee::SafeString.
Expand All @@ -124,7 +124,7 @@ void Context::push()
{
Q_D( Context );

QHash<QString, QVariant> hash;
const QHash<QString, QVariant> hash;
d->m_variantHashStack.prepend( hash );
}

Expand Down
20 changes: 10 additions & 10 deletions corelib/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ QPair<QString, QString> Engine::mediaUri( const QString &fileName ) const

QPair<QString, QString> uri;
while ( it.hasNext() ) {
AbstractTemplateLoader::Ptr loader = it.next();
const AbstractTemplateLoader::Ptr loader = it.next();
uri = loader->getMediaUri( fileName );
if ( !uri.second.isEmpty() )
break;
Expand Down Expand Up @@ -211,18 +211,18 @@ TagLibraryInterface* EnginePrivate::loadScriptableLibrary( const QString &name,
pluginDirs = m_pluginDirs;

while ( pluginDirs.size() > pluginIndex ) {
QString nextDir = pluginDirs.at( pluginIndex++ );
const QString nextDir = pluginDirs.at( pluginIndex++ );
libFileName = nextDir + QString( "/grantlee/%1.%2" ).arg( GRANTLEE_VERSION_MAJOR ).arg( minorVersion ) + '/' + name + ".qs";
QFile file( libFileName );
const QFile file( libFileName );
if ( !file.exists() )
continue;

#if 0
PluginPointer<TagLibraryInterface> scriptableTagLibrary = m_libraries.value( __scriptableLibName );
#endif

QHash<QString, AbstractNodeFactory*> factories = m_scriptableTagLibrary->nodeFactories( libFileName );
QHash<QString, Filter*> filters = m_scriptableTagLibrary->filters( libFileName );
const QHash<QString, AbstractNodeFactory*> factories = m_scriptableTagLibrary->nodeFactories( libFileName );
const QHash<QString, Filter*> filters = m_scriptableTagLibrary->filters( libFileName );

TagLibraryInterface *library = new ScriptableLibraryContainer( factories, filters );
m_scriptableLibraries << library;
Expand All @@ -243,13 +243,13 @@ PluginPointer<TagLibraryInterface> EnginePrivate::loadCppLibrary( const QString
pluginDirs = m_pluginDirs;

while ( pluginDirs.size() > pluginIndex ) {
QString nextDir = pluginDirs.at( pluginIndex++ );
QDir pluginDir( nextDir + QString( "/grantlee/%1.%2" ).arg( GRANTLEE_VERSION_MAJOR ).arg( minorVersion ) + '/' );
const QString nextDir = pluginDirs.at( pluginIndex++ );
const QDir pluginDir( nextDir + QString( "/grantlee/%1.%2" ).arg( GRANTLEE_VERSION_MAJOR ).arg( minorVersion ) + '/' );

if ( !pluginDir.exists() )
continue;

QStringList list = pluginDir.entryList( QStringList( name + "*" ) );
const QStringList list = pluginDir.entryList( QStringList( name + "*" ) );

if ( list.isEmpty() )
continue;
Expand All @@ -270,12 +270,12 @@ Template Engine::loadByName( const QString &name ) const

QListIterator<AbstractTemplateLoader::Ptr> it( d->m_loaders );
while ( it.hasNext() ) {
AbstractTemplateLoader::Ptr loader = it.next();
const AbstractTemplateLoader::Ptr loader = it.next();

if ( !loader->canLoadTemplate( name ) )
continue;

Template t = loader->loadByName( name, this );
const Template t = loader->loadByName( name, this );

if ( t ) {
return t;
Expand Down
2 changes: 1 addition & 1 deletion corelib/engine_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class EnginePrivate
PluginPointer<TagLibraryInterface> loadCppLibrary( const QString& name, uint minorVersion );

Q_DECLARE_PUBLIC( Engine )
Engine *q_ptr;
Engine * const q_ptr;

QHash<QString, PluginPointer<TagLibraryInterface> > m_libraries;
QList<TagLibraryInterface*> m_scriptableLibraries;
Expand Down
14 changes: 7 additions & 7 deletions corelib/filterexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class FilterExpressionPrivate
QStringList m_filterNames;

Q_DECLARE_PUBLIC( FilterExpression )
FilterExpression *q_ptr;
FilterExpression * const q_ptr;
};

}
Expand Down Expand Up @@ -104,7 +104,7 @@ FilterExpression::FilterExpression( const QString &varString, Parser *parser )
while ( ( pos = sFilterRe.indexIn( vs, pos ) ) != -1 ) {
len = sFilterRe.matchedLength();
subString = vs.mid( pos, len );
int ssSize = subString.size();
const int ssSize = subString.size();

if ( pos != lastPos ) {
throw Grantlee::Exception( TagSyntaxError,
Expand All @@ -122,7 +122,7 @@ FilterExpression::FilterExpression( const QString &varString, Parser *parser )

} else if ( subString.startsWith( FILTER_ARGUMENT_SEPARATOR ) ) {
subString = subString.right( ssSize - 1 );
int lastFilter = d->m_filters.size();
const int lastFilter = d->m_filters.size();
if ( subString.isEmpty() )
throw Grantlee::Exception( EmptyVariableError,
QString( "Missing argument to filter: %1" ).arg( d->m_filterNames[lastFilter -1] ) );
Expand All @@ -141,7 +141,7 @@ FilterExpression::FilterExpression( const QString &varString, Parser *parser )
lastPos = pos;
}

QString remainder = vs.right( vs.size() - lastPos );
const QString remainder = vs.right( vs.size() - lastPos );
if ( !remainder.isEmpty() ) {
throw Grantlee::Exception( TagSyntaxError,
QString( "Could not parse the remainder, %1 from %2" ).arg( remainder ).arg( varString ) );
Expand Down Expand Up @@ -197,7 +197,7 @@ QVariant FilterExpression::resolve( OutputStream *stream, Context *c ) const
Q_FOREACH( const ArgFilter &argfilter, d->m_filters ) {
Filter::Ptr filter = argfilter.first;
filter->setStream( stream );
Variable argVar = argfilter.second;
const Variable argVar = argfilter.second;
QVariant arg = argVar.resolve( c );

if ( arg.isValid() ) {
Expand All @@ -215,7 +215,7 @@ QVariant FilterExpression::resolve( OutputStream *stream, Context *c ) const
}
}

SafeString varString = getSafeString( var );
const SafeString varString = getSafeString( var );

var = filter->doFilter( var, arg, c->autoEscape() );

Expand All @@ -241,7 +241,7 @@ QVariant FilterExpression::resolve( Context *c ) const

QVariantList FilterExpression::toList( Context *c ) const
{
QVariant var = resolve( c );
const QVariant var = resolve( c );
return variantToList( var );
}

Expand Down
33 changes: 20 additions & 13 deletions corelib/lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,23 @@

using namespace Grantlee;

// In python regex, '.' matches any character except newline, whereas it QRegExp,
// it matches any character including newline. We match 'not newline' instead.
static QRegExp tagRe( QString( "(%1[^\\n]*%2|%3[^\\n]*%4|%5[^\\n]*%6)" )
.arg( QRegExp::escape( BLOCK_TAG_START ) )
.arg( QRegExp::escape( BLOCK_TAG_END ) )
.arg( QRegExp::escape( VARIABLE_TAG_START ) )
.arg( QRegExp::escape( VARIABLE_TAG_END ) )
.arg( QRegExp::escape( COMMENT_TAG_START ) )
.arg( QRegExp::escape( COMMENT_TAG_END ) )
);
static QRegExp getTagRe()
{

// In python regex, '.' matches any character except newline, whereas it QRegExp,
// it matches any character including newline. We match 'not newline' instead.
static QRegExp sTagRe( QString( "(%1[^\\n]*%2|%3[^\\n]*%4|%5[^\\n]*%6)" )
.arg( QRegExp::escape( BLOCK_TAG_START ) )
.arg( QRegExp::escape( BLOCK_TAG_END ) )
.arg( QRegExp::escape( VARIABLE_TAG_START ) )
.arg( QRegExp::escape( VARIABLE_TAG_END ) )
.arg( QRegExp::escape( COMMENT_TAG_START ) )
.arg( QRegExp::escape( COMMENT_TAG_END ) )
);

sTagRe.setMinimal( true ); // Can't use '?', eg '.*?', Have to setMinimal instead
return sTagRe;
}

Lexer::Lexer( const QString &templateString )
: m_templateString( templateString )
Expand All @@ -51,7 +58,7 @@ Lexer::~Lexer()

QList<Token> Lexer::tokenize() const
{
tagRe.setMinimal( true ); // Can't use '?', eg '.*?', Have to setMinimal instead
const QRegExp tagRe = getTagRe();

QList<Token> tokenList;

Expand All @@ -78,8 +85,8 @@ Token Lexer::createToken( const QString &fragment, State inTag, int *linecount )
token.content = fragment;
token.tokenType = TextToken;
} else {
int startTagSize = 2;
int endTagSize = 2;
static const int startTagSize = 2;
static const int endTagSize = 2;
QString content = fragment.mid( startTagSize, fragment.size() - startTagSize - endTagSize );
if ( fragment.startsWith( VARIABLE_TAG_START ) ) {
token.tokenType = VariableToken;
Expand Down
6 changes: 3 additions & 3 deletions corelib/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class NodePrivate

}
Q_DECLARE_PUBLIC( Node )
Node *q_ptr;
Node * const q_ptr;
};

class AbstractNodeFactoryPrivate
Expand Down Expand Up @@ -180,7 +180,7 @@ QList< FilterExpression > AbstractNodeFactory::getFilterExpressionList( const QS
QList<FilterExpression> fes;
QListIterator<QString> it( list );
while ( it.hasNext() ) {
QString varString = it.next();
const QString varString = it.next();
fes << FilterExpression( varString, p );
}
return fes;
Expand Down Expand Up @@ -209,7 +209,7 @@ QStringList AbstractNodeFactory::smartSplit( const QString &str ) const
while (( pos = r.indexIn( str, pos ) ) != -1 ) {
++count;
pos += r.matchedLength();
l << r.capturedTexts().at( 0 );
l << r.capturedTexts().first();
}

return l;
Expand Down
2 changes: 1 addition & 1 deletion corelib/nodebuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ VariableNode::VariableNode( const FilterExpression &fe, QObject *parent )

void VariableNode::render( OutputStream *stream, Context *c )
{
QVariant v = m_filterExpression.resolve( c );
const QVariant v = m_filterExpression.resolve( c );
if ( !v.isValid() )
return;
streamValueInContext( stream, v, c );
Expand Down
18 changes: 9 additions & 9 deletions corelib/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ParserPrivate

void openLibrary( TagLibraryInterface * library );
Q_DECLARE_PUBLIC( Parser )
Parser *q_ptr;
Parser * const q_ptr;

QList<Token> m_tokenList;

Expand Down Expand Up @@ -157,7 +157,7 @@ NodeList ParserPrivate::extendNodeList( NodeList list, Node *node )
void Parser::skipPast( const QString &tag )
{
while ( hasNextToken() ) {
Token token = takeNextToken();
const Token token = takeNextToken();
if ( token.tokenType == BlockToken && token.content.trimmed() == tag )
return;
}
Expand Down Expand Up @@ -196,7 +196,7 @@ NodeList ParserPrivate::parse( QObject *parent, const QStringList &stopAt )
NodeList nodeList;

while ( q->hasNextToken() ) {
Token token = q->takeNextToken();
const Token token = q->takeNextToken();
if ( token.tokenType == TextToken ) {
nodeList = extendNodeList( nodeList, new TextNode( token.content, parent ) );
} else if ( token.tokenType == VariableToken ) {
Expand Down Expand Up @@ -229,7 +229,7 @@ NodeList ParserPrivate::parse( QObject *parent, const QStringList &stopAt )
return nodeList;
}

QStringList tagContents = token.content.split( ' ' );
const QStringList tagContents = token.content.split( ' ' );
if ( tagContents.size() == 0 ) {
QString message;
if ( q->hasNextToken() )
Expand All @@ -239,7 +239,7 @@ NodeList ParserPrivate::parse( QObject *parent, const QStringList &stopAt )

throw Grantlee::Exception( EmptyBlockTagError, message );
}
QString command = tagContents.at( 0 );
const QString command = tagContents.first();
AbstractNodeFactory *nodeFactory = m_nodeFactories[command];

// unknown tag.
Expand Down Expand Up @@ -267,7 +267,7 @@ NodeList ParserPrivate::parse( QObject *parent, const QStringList &stopAt )
}

if ( !stopAt.isEmpty() ) {
QString message = QString( "Unclosed tag in template %1. Expected one of: (%2)" ).arg( q->parent()->objectName() ).arg( stopAt.join( " " ) );
const QString message = QString( "Unclosed tag in template %1. Expected one of: (%2)" ).arg( q->parent()->objectName() ).arg( stopAt.join( " " ) );
throw Grantlee::Exception( UnclosedBlockTagError, message );
}

Expand All @@ -278,20 +278,20 @@ NodeList ParserPrivate::parse( QObject *parent, const QStringList &stopAt )
bool Parser::hasNextToken() const
{
Q_D( const Parser );
return d->m_tokenList.size() > 0;
return !d->m_tokenList.isEmpty();
}

Token Parser::takeNextToken()
{
Q_D( Parser );
return d->m_tokenList.takeAt( 0 );
return d->m_tokenList.takeFirst();
}

void Parser::removeNextToken()
{
Q_D( Parser );
if ( !d->m_tokenList.isEmpty() )
d->m_tokenList.removeAt( 0 );
d->m_tokenList.removeFirst();;
}

void Parser::prependToken( const Token &token )
Expand Down
4 changes: 2 additions & 2 deletions corelib/taglibraryinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class TagLibraryInterface
*/
virtual QHash<QString, AbstractNodeFactory*> nodeFactories( const QString &name = QString() ) {
Q_UNUSED( name );
QHash<QString, AbstractNodeFactory*> h;
static const QHash<QString, AbstractNodeFactory*> h;
return h;
};

Expand All @@ -92,7 +92,7 @@ class TagLibraryInterface
*/
virtual QHash<QString, Filter*> filters( const QString &name = QString() ) {
Q_UNUSED( name );
QHash<QString, Filter*> h;
static const QHash<QString, Filter*> h;
return h;
};
};
Expand Down
2 changes: 1 addition & 1 deletion corelib/template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ using namespace Grantlee;
NodeList TemplatePrivate::compileString( const QString &str )
{
Q_Q( TemplateImpl );
Lexer l( str );
const Lexer l( str );
Parser p( l.tokenize(), q );

return p.parse( q );
Expand Down
2 changes: 1 addition & 1 deletion corelib/template_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class TemplatePrivate
void setError( Error type, const QString &message );

Q_DECLARE_PUBLIC( TemplateImpl )
TemplateImpl *q_ptr;
TemplateImpl * const q_ptr;

qint64 m_settingsToken;
Error m_error;
Expand Down
Loading

0 comments on commit cc89376

Please sign in to comment.