QString KURISearchFilterEngine::formatResult( const QString& url, const QString& cset1, const QString& cset2, const QString& query, bool isMalformed ) const { kdDebug(7023) << "(" << getpid() << ") query='" << query << "', url='" << url << "'\n"; // Return nothing if userquery is empty: if (query.isEmpty()) return QString::null; typedef QMap IKWMap; IKWMap map; QString newurl = url; int pct; // Decode strings for better handling (for ' ' and '='): QString userquery = KURL::decode_string(query); kdDebug(7023) << "(" << getpid() << ") userquery='" << userquery << "', newurl='" << newurl << "'\n"; // Create a codec for the desired encoding so that we can transcode the user's "url". QString cseta = cset1; if (cseta.isEmpty()) { cseta = "iso-8859-1"; } QTextCodec *csetacodec = QTextCodec::codecForName(cseta.latin1()); if (!csetacodec) { cseta = "iso-8859-1"; csetacodec = QTextCodec::codecForName(cseta.latin1()); } // Add charset indicator for the query to substitution map: map.replace("ikw_charset", cseta); // Add charset indicator for the fallback query to substitution map: QString csetb = cset2; if (csetb.isEmpty()) csetb = "iso-8859-1"; map.replace("ikw_responsecharset", csetb); userquery = csetacodec->fromUnicode(userquery); int space_pos; while ((space_pos=userquery.find('+')) != -1 ) userquery=userquery.replace(space_pos, 1, "%2B"); // Add whole query with reference '\0' to substitution map: map.replace("0", KURL::encode_string(userquery)); // Generate IKW substitution map from user query: QStringList l = QStringList::split(" ", userquery.simplifyWhiteSpace()); for (int i=0; i 0) map.replace(v.left(pct), KURL::encode_string(v.right(pct + 2))); } // Substitute references (\refname) from map with the values in the map: for (IKWMap::Iterator it = map.begin(); it != map.end(); ++it) { QString ref = "\\" + it.key(); kdDebug (7023) << "(" << getpid() << ") key='" << it.key() << "' val='" << it.data() << "'\n"; if ((pct = newurl.find(ref)) >= 0) newurl = newurl.replace(pct, ref.length(), it.data()); } kdDebug(7023) << "(" << getpid() << ") userquery='" << userquery << "', url='" << url << "', newurl='" << newurl << "'\n"; return newurl; }