[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/KDE/4.6/kdelibs/nepomuk
From: Sebastian Trueg <sebastian () trueg ! de>
Date: 2011-01-20 17:23:42
Message-ID: 20110120172342.0EEA4AC8B7 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1215995 by trueg:
Backport: fixed tests and handling of number literals
M +15 -10 query/queryparser.cpp
M +7 -7 test/queryparsertest.cpp
--- branches/KDE/4.6/kdelibs/nepomuk/query/queryparser.cpp #1215994:1215995
@@ -1,6 +1,6 @@
/*
This file is part of the Nepomuk KDE project.
- Copyright (C) 2007-2010 Sebastian Trueg <trueg@kde.org>
+ Copyright (C) 2007-2011 Sebastian Trueg <trueg@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -131,21 +131,26 @@
}
Soprano::LiteralValue createLiteral( const QString& s, bool globbing ) {
+ // 1. check if it is a number
+ QString clearString(s);
+ clearString.remove(QLatin1Char('\''));
+ clearString.remove(QLatin1Char('"'));
+ bool b = false;
+ int i = clearString.toInt( &b );
+ if ( b )
+ return Soprano::LiteralValue( i );
+ double d = clearString.toDouble( &b );
+ if ( b )
+ return Soprano::LiteralValue( d );
+
+ // 2. no number - continue with the original string
+
// no globbing if we have quotes or if there already is a wildcard
if ( s[0] == QLatin1Char('\'') ||
s[0] == QLatin1Char('\"') ) {
return s;
}
- // at this point we should have a string without spaces in it
- bool b = false;
- int i = s.toInt( &b );
- if ( b )
- return Soprano::LiteralValue( i );
- double d = s.toDouble( &b );
- if ( b )
- return Soprano::LiteralValue( d );
-
//
// we can only do query term globbing for strings longer than 3 chars
//
--- branches/KDE/4.6/kdelibs/nepomuk/test/queryparsertest.cpp #1215994:1215995
@@ -108,8 +108,8 @@
// simple literal queries
QTest::newRow( "simple literal query" ) << QString( "Hello" ) << Query( \
LiteralTerm( "Hello" ) );
- QTest::newRow( "literal with spaces without quotes" ) << QString( "Hello World" \
) << Query( AndTerm( LiteralTerm("Hello"), LiteralTerm("World" ) ) );
- QTest::newRow( "literal with spaces with quotes" ) << QString( "'Hello World'" ) \
<< Query( LiteralTerm( "Hello World" ) ); + QTest::newRow( "literal with spaces \
without quotes" ) << QString( "Hello World" ) << Query( LiteralTerm("Hello AND World" \
) ); + QTest::newRow( "literal with spaces with quotes" ) << QString( "'Hello \
World'" ) << Query( LiteralTerm( "'Hello World'" ) );
// comparison queries
QTest::newRow( "simple field query" ) << QString( "hastag:nepomuk" )
@@ -135,8 +135,8 @@
QTest::newRow( "field negation" ) << QString( "-label:nepomuk" ) << Query( \
NegationTerm::negateTerm( ComparisonTerm( QUrl("onto:/label"), LiteralTerm( "nepomuk" \
) ) ) );
// and query
- QTest::newRow( "and: two literals" ) << QString( "Hello World" ) << \
Query( AndTerm( LiteralTerm( "Hello" ), LiteralTerm( "World" ) ) );
- QTest::newRow( "and: two literals with AND" ) << QString( "Hello AND World" ) << \
Query( AndTerm( LiteralTerm( "Hello" ), LiteralTerm( "World" ) ) ); + \
QTest::newRow( "and: two literals" ) << QString( "Hello World" ) << Query( \
LiteralTerm( "Hello AND World" ) ); + QTest::newRow( "and: two literals with AND" \
) << QString( "Hello AND World" ) << Query( LiteralTerm( "Hello AND World" ) ) ;
// or queries
QTest::newRow( "or: two literals" ) << QString( "Hello OR World" ) << \
Query( OrTerm( LiteralTerm( "Hello" ), LiteralTerm( "World" ) ) ); @@ -161,9 +161,9 \
@@
// simple literal queries
QTest::newRow( "simple literal query" ) << QString( "Hello" ) << Query( \
LiteralTerm( "Hello*" ) );
- QTest::newRow( "simple literal query" ) << QString( "\"Hello\"" ) << Query( \
LiteralTerm( "Hello" ) );
- QTest::newRow( "literal with spaces without quotes" ) << QString( "Hello World" \
) << Query( AndTerm( LiteralTerm("Hello*"), LiteralTerm("World*" ) ) \
);
- QTest::newRow( "literal with spaces with quotes" ) << QString( "'Hello World'" ) \
<< Query( LiteralTerm( "Hello World" ) ); + QTest::newRow( "simple literal query" \
) << QString( "\"Hello\"" ) << Query( LiteralTerm( "\"Hello\"" ) ); + \
QTest::newRow( "literal with spaces without quotes" ) << QString( "Hello World" ) << \
Query( LiteralTerm("Hello* AND World*" ) ); + QTest::newRow( "literal with spaces \
with quotes" ) << QString( "'Hello World'" ) << Query( LiteralTerm( "'Hello World'" ) \
); }
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic