QDomText EmoticonExpander::expandFirstEmoticon(QDomText textNode) const { QString text = textNode.nodeValue().toLower(); int textLength = text.length(); if (0 == textLength) return QDomText(); int currentEmoticonStart = -1; Emoticon currentEmoticon; EmoticonWalker walker(m_tree); for (int i = 0; i < textLength; i++) { Emoticon emoticon = walker.matchEmoticon(text.at(i), (i < textLength - 1) && text.at(i + 1).isLetter()); if (emoticon.isNull()) continue; // TODO: remove this dependency int emoticonStart = i - emoticon.triggerText().length() + 1; if (currentEmoticon.isNull() || currentEmoticonStart >= emoticonStart) { currentEmoticon = emoticon; currentEmoticonStart = emoticonStart; continue; } return insertEmoticon(textNode, currentEmoticon, currentEmoticonStart); } if (!currentEmoticon.isNull()) insertEmoticon(textNode, currentEmoticon, currentEmoticonStart); return QDomText(); }