[poppler] qt4/src qt4/tests qt5/src qt5/tests

Adam Reichold adam.reichold at t-online.de
Thu Jan 22 10:47:04 PST 2015


Hello William,

Am 22.01.2015 um 01:28 schrieb William Bader:
> Is it possible to write "const GBool sWords =
> flags.testFlag(WholeWords);" instead of "const GBool sWords =
> flags.testFlag(WholeWords) ? gTrue : gFalse;"?

I think it is possible as the "bool" value returned by "testFlag" would
be casted implicitly to whatever integral type "GBool" could also be,
with "true" being 1 and "false" being "0" as mandated by the standard.

> It does not give a compile warning with g++ 4.8.3 on Fedora 20,
> and goo/gtypes.h has "typedef bool GBool; #define gTrue true #define
> gFalse false".  In theory, someone could change the definitions, but
> wouldn't it break a lot of tests if gTrue or gFalse were defined so that
> C++ considered (gFalse || !gTrue) as true in a condition?

But I also think this only works if people always use statements like
"GBool x; if(x)" instead of testing "if(x == gTrue)" as "gTrue" could
very well be "42" instead of "1" and still keep "if(x)" and "gFalse ||
!gTrue == false" working. So as it may be ugly and noisy, it does not
cost a lot to write "? gTrue : gFalse" and also cover this case.

Personally, I would prefer to just use C++'s standard "bool" and my next
question would be what the actual contract behind "GBool" is? Is it
guaranteed to always be "bool"? But then why have it all?

I this particular case, I just tried to stay as close to the existing
code as possible, so it may just be cargo culting.

> William

Best regards, Adam.

>> To: poppler at lists.freedesktop.org
>> Date: Wed, 21 Jan 2015 13:31:58 -0800
>> From: aacid at kemper.freedesktop.org
>> Subject: [poppler] qt4/src qt4/tests qt5/src qt5/tests
>>
>> qt4/src/poppler-page.cc | 4 ++--
>> qt4/src/poppler-qt4.h | 2 +-
>> qt4/tests/check_search.cpp | 4 ++--
>> qt5/src/poppler-page.cc | 4 ++--
>> qt5/src/poppler-qt5.h | 2 +-
>> qt5/tests/check_search.cpp | 4 ++--
>> 6 files changed, 10 insertions(+), 10 deletions(-)
>>
>> New commits:
>> commit 78abf540057181b708c546aee421f81a1dd58331
>> Author: Adam Reichold <adamreichold at myopera.com>
>> Date: Wed Jan 21 22:30:45 2015 +0100
>>
>> Worlds -> Words
>>
>> diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc
>> index a4536af..49ad871 100644
>> --- a/qt4/src/poppler-page.cc
>> +++ b/qt4/src/poppler-page.cc
>> @@ -508,7 +508,7 @@ bool Page::search(const QString &text, double
> &sLeft, double &sTop, double &sRig
>> bool Page::search(const QString &text, double &sLeft, double &sTop,
> double &sRight, double &sBottom, SearchDirection direction, SearchFlags
> flags, Rotation rotate) const
>> {
>> const GBool sCase = flags.testFlag(IgnoreCase) ? gFalse : gTrue;
>> - const GBool sWords = flags.testFlag(WholeWorlds) ? gTrue : gFalse;
>> + const GBool sWords = flags.testFlag(WholeWords) ? gTrue : gFalse;
>>
>> QVector<Unicode> u;
>> TextPage *textPage = m_page->prepareTextSearch(text, rotate, &u);
>> @@ -555,7 +555,7 @@ QList<QRectF> Page::search(const QString &text,
> SearchMode caseSensitive, Rotati
>> QList<QRectF> Page::search(const QString &text, SearchFlags flags,
> Rotation rotate) const
>> {
>> const GBool sCase = flags.testFlag(IgnoreCase) ? gFalse : gTrue;
>> - const GBool sWords = flags.testFlag(WholeWorlds) ? gTrue : gFalse;
>> + const GBool sWords = flags.testFlag(WholeWords) ? gTrue : gFalse;
>>
>> QVector<Unicode> u;
>> TextPage *textPage = m_page->prepareTextSearch(text, rotate, &u);
>> diff --git a/qt4/src/poppler-qt4.h b/qt4/src/poppler-qt4.h
>> index 48c517a..e5e808d 100644
>> --- a/qt4/src/poppler-qt4.h
>> +++ b/qt4/src/poppler-qt4.h
>> @@ -586,7 +586,7 @@ delete it;
>> enum SearchFlag
>> {
>> IgnoreCase = 0x00000001, ///< Case differences are ignored
>> - WholeWorlds = 0x00000002 ///< Only whole words are matched
>> + WholeWords = 0x00000002 ///< Only whole words are matched
>> };
>> Q_DECLARE_FLAGS( SearchFlags, SearchFlag )
>>
>> diff --git a/qt4/tests/check_search.cpp b/qt4/tests/check_search.cpp
>> index 77e62e3..99659e0 100644
>> --- a/qt4/tests/check_search.cpp
>> +++ b/qt4/tests/check_search.cpp
>> @@ -152,8 +152,8 @@ void TestSearch::testWholeWordsOnly()
>>
>> const Poppler::Page::SearchFlags mode0 = 0;
>> const Poppler::Page::SearchFlags mode1 = Poppler::Page::IgnoreCase;
>> - const Poppler::Page::SearchFlags mode2 = Poppler::Page::WholeWorlds;
>> - const Poppler::Page::SearchFlags mode3 = Poppler::Page::IgnoreCase |
> Poppler::Page::WholeWorlds;
>> + const Poppler::Page::SearchFlags mode2 = Poppler::Page::WholeWords;
>> + const Poppler::Page::SearchFlags mode3 = Poppler::Page::IgnoreCase |
> Poppler::Page::WholeWords;
>>
>> double left, top, right, bottom;
>>
>> diff --git a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc
>> index 88f2e73..408099c 100644
>> --- a/qt5/src/poppler-page.cc
>> +++ b/qt5/src/poppler-page.cc
>> @@ -508,7 +508,7 @@ bool Page::search(const QString &text, double
> &sLeft, double &sTop, double &sRig
>> bool Page::search(const QString &text, double &sLeft, double &sTop,
> double &sRight, double &sBottom, SearchDirection direction, SearchFlags
> flags, Rotation rotate) const
>> {
>> const GBool sCase = flags.testFlag(IgnoreCase) ? gFalse : gTrue;
>> - const GBool sWords = flags.testFlag(WholeWorlds) ? gTrue : gFalse;
>> + const GBool sWords = flags.testFlag(WholeWords) ? gTrue : gFalse;
>>
>> QVector<Unicode> u;
>> TextPage *textPage = m_page->prepareTextSearch(text, rotate, &u);
>> @@ -537,7 +537,7 @@ QList<QRectF> Page::search(const QString &text,
> SearchMode caseSensitive, Rotati
>> QList<QRectF> Page::search(const QString &text, SearchFlags flags,
> Rotation rotate) const
>> {
>> const GBool sCase = flags.testFlag(IgnoreCase) ? gFalse : gTrue;
>> - const GBool sWords = flags.testFlag(WholeWorlds) ? gTrue : gFalse;
>> + const GBool sWords = flags.testFlag(WholeWords) ? gTrue : gFalse;
>>
>> QVector<Unicode> u;
>> TextPage *textPage = m_page->prepareTextSearch(text, rotate, &u);
>> diff --git a/qt5/src/poppler-qt5.h b/qt5/src/poppler-qt5.h
>> index 9ffecff..79c3f74 100644
>> --- a/qt5/src/poppler-qt5.h
>> +++ b/qt5/src/poppler-qt5.h
>> @@ -587,7 +587,7 @@ delete it;
>> enum SearchFlag
>> {
>> IgnoreCase = 0x00000001, ///< Case differences are ignored
>> - WholeWorlds = 0x00000002 ///< Only whole words are matched
>> + WholeWords = 0x00000002 ///< Only whole words are matched
>> };
>> Q_DECLARE_FLAGS( SearchFlags, SearchFlag )
>>
>> diff --git a/qt5/tests/check_search.cpp b/qt5/tests/check_search.cpp
>> index 2f6f022..a24cc72 100644
>> --- a/qt5/tests/check_search.cpp
>> +++ b/qt5/tests/check_search.cpp
>> @@ -151,8 +151,8 @@ void TestSearch::testWholeWordsOnly()
>>
>> const Poppler::Page::SearchFlags mode0 = 0;
>> const Poppler::Page::SearchFlags mode1 = Poppler::Page::IgnoreCase;
>> - const Poppler::Page::SearchFlags mode2 = Poppler::Page::WholeWorlds;
>> - const Poppler::Page::SearchFlags mode3 = Poppler::Page::IgnoreCase |
> Poppler::Page::WholeWorlds;
>> + const Poppler::Page::SearchFlags mode2 = Poppler::Page::WholeWords;
>> + const Poppler::Page::SearchFlags mode3 = Poppler::Page::IgnoreCase |
> Poppler::Page::WholeWords;
>>
>> double left, top, right, bottom;
>>
>> _______________________________________________
>> poppler mailing list
>> poppler at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/poppler
> 
> 
> _______________________________________________
> poppler mailing list
> poppler at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/poppler
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freedesktop.org/archives/poppler/attachments/20150122/4e9cd5fb/attachment-0001.sig>


More information about the poppler mailing list