Qt::CaseInsensitive no longer working

Report any problems with CopperSpice
Post Reply
seasoned_geek
Posts: 257
Joined: Thu Jun 11 2020 12:18 pm

Qt::CaseInsensitive no longer working

Post by seasoned_geek »

Code: Select all

    qDebug() << ";;;;;;;;;;;;;;;; exists for bug report\n";
    QString lcCommand = "gist /name=\"some_file.txt\" /desc=\"test of command line gist\" sel ";
    qDebug() << "lccommand: " << lcCommand << "\n";
    QString::size_type somePos = lcCommand.indexOf( QString( "/na" ), Qt::CaseInsensitive );
    qDebug() << "somePos: " << somePos << " after searching for /na  \n";
    somePos = lcCommand.indexOf( QString( "/NA" ), Qt::CaseInsensitive );
    qDebug() << "somePos: " << somePos << " after searching for /NA  \n";
    somePos = lcCommand.indexOf( QString( "/des" ), Qt::CaseInsensitive );
    qDebug() << "somePos: " << somePos << " after searching for /des  \n";
    somePos = lcCommand.indexOf( QString( "/DES" ), Qt::CaseInsensitive );
    qDebug() << "somePos: " << somePos << " after searching for /DES  \n";
    qDebug() << ";;;;;;;;;;;;;;;; end bug report\n";
Produces

Code: Select all

;;;;;;;;;;;;;;;; exists for bug report

lccommand:  gist /name="some_file.txt" /desc="test of command line gist" sel  

somePos:  5  after searching for /na  

somePos:  -1  after searching for /NA  

somePos:  27  after searching for /des  

somePos:  -1  after searching for /DES  

;;;;;;;;;;;;;;;; end bug report
If Qt::CaseInsensitive was actually working all four calls should succeed. Due to case sensitive file names, etc. one cannot just force the input to upper or lower case without changing the behavior. Prior to my January merge, Qt::CaseInsensitive used to work. Will have to go back and retest a whole bunch of code now.
seasoned_geek
Posts: 257
Joined: Thu Jun 11 2020 12:18 pm

Re: Qt::CaseInsensitive no longer working

Post by seasoned_geek »

The only work around is to needlessly burden the application with RegEx.

Code: Select all


QString EdtBaseWidget::stripGistName( QString &text, bool &validCommand )
{
    qDebug() << ";;;;;;;;;;;;;;;; exists for bug report\n";
    QRegularExpression regExpna( "/na", QPatternOption::CaseInsensitiveOption );
    QRegularExpression regExpNA( "/NA", QPatternOption::CaseInsensitiveOption );
    QRegularExpression regExpdes( "/des", QPatternOption::CaseInsensitiveOption );
    QRegularExpression regExpDES( "/DES", QPatternOption::CaseInsensitiveOption );
    QString lcCommand = "gist /name=\"some_file.txt\" /desc=\"test of command line gist\" sel ";
    qDebug() << "lccommand: " << lcCommand << "\n";
    QString::size_type somePos = lcCommand.indexOf( QString( "/na" ), Qt::CaseInsensitive );
    qDebug() << "somePos: " << somePos << " after searching for /na  \n";
    somePos = lcCommand.indexOf( regExpna );
    qDebug() << "somePos: " << somePos << " after searching for /na via regex  \n";
    somePos = lcCommand.indexOf( QString( "/NA" ), Qt::CaseInsensitive );
    qDebug() << "somePos: " << somePos << " after searching for /NA  \n";
    somePos = lcCommand.indexOf( regExpNA );
    qDebug() << "somePos: " << somePos << " after searching for /NA via regex  \n";
    somePos = lcCommand.indexOf( QString( "/des" ), Qt::CaseInsensitive );
    qDebug() << "somePos: " << somePos << " after searching for /des  \n";
    somePos = lcCommand.indexOf( regExpdes );
    qDebug() << "somePos: " << somePos << " after searching for /des via regex \n";
    somePos = lcCommand.indexOf( QString( "/DES" ), Qt::CaseInsensitive );
    qDebug() << "somePos: " << somePos << " after searching for /DES  \n";
    somePos = lcCommand.indexOf( regExpDES );
    qDebug() << "somePos: " << somePos << " after searching for /DES via regex  \n";
    qDebug() << ";;;;;;;;;;;;;;;; end bug report\n";
    // don't allow an empty file name
prints

Code: Select all

;;;;;;;;;;;;;;;; exists for bug report

lccommand:  gist /name="some_file.txt" /desc="test of command line gist" sel  

somePos:  5  after searching for /na  

somePos:  5  after searching for /na via regex  

somePos:  -1  after searching for /NA  

somePos:  5  after searching for /NA via regex  

somePos:  27  after searching for /des  

somePos:  27  after searching for /des via regex 

somePos:  -1  after searching for /DES  

somePos:  27  after searching for /DES via regex  

;;;;;;;;;;;;;;;; end bug report

ansel
Posts: 153
Joined: Fri Apr 10 2015 8:23 am

Re: Qt::CaseInsensitive no longer working

Post by ansel »

Thanks for reporting this, we will add a test case and take a look at it.
Ansel Sermersheim
CopperSpice Cofounder
barbara
Posts: 454
Joined: Sat Apr 04 2015 2:32 am
Contact:

Re: Qt::CaseInsensitive no longer working

Post by barbara »

We took another look at this and I noticed you are missing the second parameter. The API shows three parameters with the second and third having default values. If you want to pass Qt::CaseInsensitive for the third parameter you must pass 0 (default value) for the second parameter.

When all three parameters are provided everything passes our new unit tests.

Barbara
seasoned_geek
Posts: 257
Joined: Thu Jun 11 2020 12:18 pm

Re: Qt::CaseInsensitive no longer working

Post by seasoned_geek »

This this shouldn't compile.

https://www.copperspice.com/docs/cs_api/class_qt.html#aa2ba2914e203bc3a4cad512b57cc7ab8

Should be an enum class so this cannot compile. Yes, I looked again, you are correct. The documentation is mushed together so it is difficult to see for people wearing glasses, but if the project really is pushing C++17 then all of the enums should have long ago been replaced by enum classes. The fact is this compiled and ran incorrectly because everything masks back to an int.

Putting my new "workspace progressive" lenses back in their case and digging out my older "standard" computer glasses.
barbara
Posts: 454
Joined: Sat Apr 04 2015 2:32 am
Contact:

Re: Qt::CaseInsensitive no longer working

Post by barbara »

CopperSpice currently requires C++17 and we are moving to C++20 this year. We are continually migrating the code base to a more modern version of the language. However, our team is careful when making changes which will affect our user base. I can assure you we have changed some enums to enum classes and some enums now specify an underlying integer type.

What you may not have realized if we change enums like this one to an enum class it would break a lot of user code, including yours. Every place in your code would need to be modified as shown.

// prior syntax
text.indexOf( "findThis" , 0, Qt::CaseInsensitive );

// new syntax
text.indexOf( "findThis" , 0, Qt::CaseSensitivity::CaseInsensitive )

The API from our predecessor did not change so we have maintained source compatibility. A much better solution for code like this is simply to add an overload which takes the first and third parameters.

Barbara
Post Reply