public static string ClearAngleBracket(string content, bool processImages) { if (content == null || content.Length == 0) { return(content); } if (processImages) { if (imageBracketRegex == null) { imageBracketRegex = new ImageRegex(); } if (emoticonBracketRegex == null) { emoticonBracketRegex = new EmoticonRegex(); } content = imageBracketRegex.Replace(content, "[表情]"); content = emoticonBracketRegex.Replace(content, "[图片]"); } if (angleBracketRegex == null) { angleBracketRegex = new AngleBracketRegex(); } return(angleBracketRegex.Replace(content, string.Empty)); }
public Paragraph LinkifyEmoticons(string messageString) { MatchCollection matchCollection = EmoticonRegex.Matches(messageString); Paragraph p = new Paragraph(); int startIndex = 0; int endIndex = -1; int maxCount = matchCollection.Count < HikeConstants.MAX_EMOTICON_SUPPORTED ? matchCollection.Count : HikeConstants.MAX_EMOTICON_SUPPORTED; for (int i = 0; i < maxCount; i++) { String emoticon = matchCollection[i].ToString(); //Regex never returns an empty string. Still have added an extra check if (String.IsNullOrEmpty(emoticon)) { continue; } int index = matchCollection[i].Index; endIndex = index - 1; if (index > 0) { Run r = new Run(); r.Text = messageString.Substring(startIndex, endIndex - startIndex + 1); p.Inlines.Add(r); } startIndex = index + emoticon.Length; //TODO check if imgPath is null or not Image img = new Image(); img.Source = lookUpFromCache(emoticon); img.Height = 25; img.Width = 25; img.Margin = UI_Utils.Instance.ConvListEmoticonMargin; InlineUIContainer ui = new InlineUIContainer(); ui.Child = img; p.Inlines.Add(ui); } if (startIndex < messageString.Length) { Run r2 = new Run(); r2.Text = messageString.Substring(startIndex, messageString.Length - startIndex); p.Inlines.Add(r2); } return(p); }