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)); }
/// <summary> /// 解析图像值。 /// </summary> /// <returns>解析后的字符串。</returns> public string ParseImage(string text) { float fs = GetComponent <Text>().fontSize; int index = 0; m_ImageInfos.Clear(); CacheSB.Length = 0; foreach (Match match in ImageRegex.Matches(text)) { string[] param = match.Groups[1].Value.Trim().Split(','); string innerchar = (param.Length >= 3 && param[2].Length > 0) ? param[2].Substring(0, 1) : "哈"; //默认用哈,最接近正方形 string innertext = innerchar; //图像位置用"M"字符占位 int prelen = 0; if (param.Length >= 2) { float scale; if (float.TryParse(param[1], out scale)) { if (Math.Abs(scale - 1) >= 0.0001f) { int imgsize = (int)(fs * scale); //必须取整 string pre = string.Format("<size={0}>", imgsize); innertext = string.Format("{0}{1}</size>", pre, innerchar); prelen = pre.Length; } } } float imgscale = 1; if (param.Length >= 4) { float scale; if (float.TryParse(param[3], out scale)) { imgscale = scale; } } ImageInfo info = new ImageInfo(); CacheSB.Append(text.Substring(index, match.Index - index)); //匹配目标前的那一部分 info.StartIndex = CacheSB.Length + prelen; info.EndIndex = info.StartIndex + 1; info.Name = param[0]; info.Scale = imgscale; m_ImageInfos.Add(info); CacheSB.Append(innertext); int cut = match.Length - innertext.Length; //匹配调整后缩短的长度 index = match.Index + match.Length; AdujstIndex(m_ColorInfos, info.StartIndex, info.StartIndex + match.Length, cut, 0); AdujstIndex(m_HrefInfos, info.StartIndex, info.StartIndex + match.Length, cut, 0); } CacheSB.Append(text.Substring(index, text.Length - index)); return(CacheSB.ToString()); }