Error when calling Amarok::decapitateString()
Bart Cerneels
bart.cerneels at kde.org
Wed Jan 14 13:17:49 UTC 2009
On Thu, Jan 8, 2009 at 10:56 PM, Pavel Shved <pavel.shved at gmail.com> wrote:
> Mark Kretschmann wrote:
>
>> Cool. It would be great if you could send us a patch when you are done
>> fixing it :)
>
> Hm, now i tihnk i should've just sent a patch instead of long description.
>
> Please, check the file attached and test cases there--in case i
> misunderstood the function's purpose. If it's OK, commit it to appropriate
> place; don't think you allow anonymous users into your svn.
>
>
>
>
> #include <iostream>
>
> #include <qt4/QtCore/QString>
>
> /* Strip the common prefix of two strings from the first one and trim
> * whitespaces from the beginning of the resultant string.
> * Case-insensitive.
> *
> * @param input the string being processed
> * @param ref the string used to determine prefix
> */
> QString decapitateString( const QString &input, const QString &ref )
> {
> //Sometimes it's good to be c-like...
> int len; //the length of common prefix calculated so far
> for (len = 0; len<input.length() && len<ref.length(); len++){
> if (input.at(len).toUpper() != ref.at(len).toUpper())
> break;
> }
>
> return input.right(input.length() - len).trimmed();
> }
>
>
>
> int main()
> {
> using namespace std;
> //let's test it
> QString p[][3] = {
> //argument1, argument2, correct answer
> {"simple prefix","simple test","prefix"},
> {"just", "test", "just"},
> {"ContainsOther","Contains","Other"},
> {"Contains","ContainsOther",""},
> {"Equals","Equals",""},
> {"","",""},
> {"","AnotherIsEmpty",""},
> {"AnotherIsEmpty","","AnotherIsEmpty"},
> {"","something",""},
> {"something","","something"},
> {" \t "," whatever",""},
> {"sEvERal wOrDs in One StrinG","several words indeed!","One StrinG"},
> {"sEvERal wOrDs -- now it's more simple","several words, yeah!","--
> now it's more simple"},
> };
> int const num = 13;
> int failed = num;
> for (int i = 0; i<num ; i++){
> cout << "Test "<<(i+1)<<" ";
> QString res = decapitateString(p[i][0],p[i][1]);
> if (res == p[i][2]){
> cout <<"ok"<<endl;
> failed--;
> }else{
> cout <<"FAIL:
> "<<"f(`"<<p[i][0].toStdString()<<"',`"<<p[i][1].toStdString()<<"')"<<endl
> <<" yields "<<res.toStdString()<<endl
> <<" must be "<<p[i][2].toStdString()<<endl;
> }
> }
> cerr << failed << " tests failed."<<endl;
> return failed;
> }
>
Hey Pavel,
If you can also solve these cases I'll probably use your code.
{"This Podcast","This Podcast: January 14, 2009","January 14, 2009"}
{"Podcast Title","Podcast Title #001","#001"}
{"The funnycast","Funnycast 042: The Answer","042: The Answer"}
Perhaps you have suggestions of how to solve these without false positives:
{"::Title with ascii art::","::Title with ascii art:: for January 14,
2009","January 14, 2009"}
Look here to find more examples of the "creative" naming Podcasters
practice: http://podcastpickle.com/index/featured.php?id=top100audio
Remember, the reason we have decapitateString is because the
PlaylistBrowser has a limited width. We try to strip common data in
titles so we don't lose all relevant info to
QFontMetrics::elidedText().
Bart
More information about the Amarok
mailing list