Page 1 of 1
Qt::CaseInsensitive no longer working
Posted: Sun Mar 24 2024 3:00 pm
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.
Re: Qt::CaseInsensitive no longer working
Posted: Sun Mar 24 2024 3:23 pm
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
Re: Qt::CaseInsensitive no longer working
Posted: Mon Mar 25 2024 4:16 am
by ansel
Thanks for reporting this, we will add a test case and take a look at it.
Re: Qt::CaseInsensitive no longer working
Posted: Tue Mar 26 2024 4:02 am
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
Re: Qt::CaseInsensitive no longer working
Posted: Tue Mar 26 2024 2:04 pm
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.
Re: Qt::CaseInsensitive no longer working
Posted: Wed Mar 27 2024 5:46 pm
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