Summary: | [patch] greedy matching for emoticons | ||
---|---|---|---|
Product: | [Unmaintained] kopete | Reporter: | Martin Matusiak <juventuz2000> |
Component: | general | Assignee: | Kopete Developers <kopete-bugs-null> |
Status: | RESOLVED FIXED | ||
Severity: | wishlist | ||
Priority: | NOR | ||
Version: | unspecified | ||
Target Milestone: | --- | ||
Platform: | Compiled Sources | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: | |||
Attachments: | greedy_emoticon_parsing.patch |
Description
Martin Matusiak
2006-09-13 09:01:11 UTC
Created attachment 17748 [details]
greedy_emoticon_parsing.patch
thanks for your patch, it looks fine. I hope I will have the time to test it this week. I've described the problem in a more user centric way on my blog (includes screenshots): http://www.matusiak.eu/numerodix/blog/index.php/2006/09/13/fixing-lack-of-greedy-emoticon-matching-in-kopete SVN commit 584918 by ogoffart: Fix emoticon parsing if there are sub-emoticons. BUG: 133995 Patch by Martin Matusiak, thanks. M +18 -0 kopeteemoticons.cpp M +6 -0 kopeteemoticons.h --- branches/KDE/3.5/kdenetwork/kopete/libkopete/private/kopeteemoticons.cpp #584917:584918 @@ -48,6 +48,8 @@ struct Emoticons::Emoticon { Emoticon(){} + /* sort by longest to shortest matchText */ + bool operator< (const Emoticon &e){ return matchText.length() > e.matchText.length(); } QString matchText; QString matchTextEscaped; QString picPath; @@ -424,6 +426,7 @@ node = node.nextSibling(); } mapFile.close(); + sortEmoticons(); } @@ -492,12 +495,27 @@ node = node.nextSibling(); } mapFile.close(); + sortEmoticons(); } +void Emoticons::sortEmoticons() +{ + /* sort strings in order of longest to shortest to provide convenient input for + greedy matching in the tokenizer */ + QValueList<QChar> keys = d->emoticonMap.keys(); + for ( QValueList<QChar>::const_iterator it = keys.begin(); it != keys.end(); ++it ) + { + QChar key = (*it); + QValueList<Emoticon> keyValues = d->emoticonMap[key]; + qHeapSort(keyValues.begin(), keyValues.end()); + d->emoticonMap[key] = keyValues; + } +} + QMap<QString, QString> Emoticons::emoticonAndPicList() { return d->emoticonAndPicList; --- branches/KDE/3.5/kdenetwork/kopete/libkopete/private/kopeteemoticons.h #584917:584918 @@ -156,6 +156,12 @@ * @see initEmoticons */ void initEmoticon_JEP0038( const QString & filename); + + /** + * sorts emoticons for convenient parsing, which yields greedy matching on + * matchText + */ + void sortEmoticons(); struct Emoticon; |