public static string ParseRichText(string text, int fontSize, RichTextFlags flags) { if (text == null) { return(text); } if ((flags & RichTextFlags.Bold) == 0) { text = Regex.Replace(text, TextComponent.RICHTEXT_B_BEGIN, string.Empty); text = Regex.Replace(text, TextComponent.RICHTEXT_B_END, string.Empty); } if ((flags & RichTextFlags.Italic) == 0) { text = Regex.Replace(text, TextComponent.RICHTEXT_I_BEGIN, string.Empty); text = Regex.Replace(text, TextComponent.RICHTEXT_I_END, string.Empty); } if ((flags & RichTextFlags.Size) == 0) { text = Regex.Replace(text, TextComponent.RICHTEXT_SIZE_BEGIN, string.Empty); text = Regex.Replace(text, TextComponent.RICHTEXT_SIZE_END, string.Empty); } else { text = Regex.Replace(text, TextComponent.RICHTEXT_SIZEPERCENT, new MatchEvaluator((Match match) => { var value = match.Groups[TextComponent.RICHTEXT_SIZEPERCENT_GROUP].Value; var newValue = value; float fValue; if (float.TryParse(value, out fValue) == true) { newValue = ((int)(fontSize * (fValue / 100f))).ToString(); } return(string.Format(TextComponent.RICHTEXT_SIZEPERCENT_GROUPRESULT, newValue)); })); } if ((flags & RichTextFlags.Color) == 0) { text = Regex.Replace(text, TextComponent.RICHTEXT_COLOR_BEGIN, string.Empty); text = Regex.Replace(text, TextComponent.RICHTEXT_COLOR_END, string.Empty); } if ((flags & RichTextFlags.Material) == 0) { text = Regex.Replace(text, TextComponent.RICHTEXT_MATERIAL_BEGIN, string.Empty); text = Regex.Replace(text, TextComponent.RICHTEXT_MATERIAL_END, string.Empty); } if ((flags & RichTextFlags.Quad) == 0) { text = Regex.Replace(text, TextComponent.RICHTEXT_QUAD, string.Empty); } return(text); }
public static string ParseRichText(string text, int fontSize, RichTextFlags flags) { if (text == null) { return(text); } if ((flags & RichTextFlags.Bold) == 0) { text = Regex.Replace(text, @"<b>", String.Empty); text = Regex.Replace(text, @"</b>", String.Empty); } if ((flags & RichTextFlags.Italic) == 0) { text = Regex.Replace(text, @"<i>", String.Empty); text = Regex.Replace(text, @"</i>", String.Empty); } if ((flags & RichTextFlags.Size) == 0) { text = Regex.Replace(text, @"<size=[0-9]+>", String.Empty); text = Regex.Replace(text, @"</size>", String.Empty); } else { text = Regex.Replace(text, @"<size=(?<Percent>[0-9]+)%>", new MatchEvaluator((Match match) => { var value = match.Groups["Percent"].Value; var newValue = value; float fValue; if (float.TryParse(value, out fValue) == true) { newValue = ((int)(fontSize * (fValue / 100f))).ToString(); } return(string.Format("<size={0}>", newValue)); })); } if ((flags & RichTextFlags.Color) == 0) { text = Regex.Replace(text, @"<color=[^>]+>", String.Empty); text = Regex.Replace(text, @"</color>", String.Empty); } if ((flags & RichTextFlags.Material) == 0) { text = Regex.Replace(text, @"<material=[^>]+>", String.Empty); text = Regex.Replace(text, @"</material>", String.Empty); } if ((flags & RichTextFlags.Quad) == 0) { text = Regex.Replace(text, @"<quad [^>]+>", String.Empty); } return(text); }
public static string ParseRichText(string text, RichTextFlags flags) { if (text == null) return text; if ((flags & RichTextFlags.Bold) == 0) { text = Regex.Replace(text, @"<b>", String.Empty); text = Regex.Replace(text, @"</b>", String.Empty); } if ((flags & RichTextFlags.Italic) == 0) { text = Regex.Replace(text, @"<i>", String.Empty); text = Regex.Replace(text, @"</i>", String.Empty); } if ((flags & RichTextFlags.Size) == 0) { text = Regex.Replace(text, @"<size=[0-9]+>", String.Empty); text = Regex.Replace(text, @"</size>", String.Empty); } if ((flags & RichTextFlags.Color) == 0) { text = Regex.Replace(text, @"<color=[^>]+>", String.Empty); text = Regex.Replace(text, @"</color>", String.Empty); } if ((flags & RichTextFlags.Material) == 0) { text = Regex.Replace(text, @"<material=[^>]+>", String.Empty); text = Regex.Replace(text, @"</material>", String.Empty); } if ((flags & RichTextFlags.Quad) == 0) { text = Regex.Replace(text, @"<quad [^>]+>", String.Empty); } return text; }
public static string ParseRichText(string text, int fontSize, RichTextFlags flags) { if (text == null) return text; if ((flags & RichTextFlags.Bold) == 0) { text = Regex.Replace(text, @"<b>", String.Empty); text = Regex.Replace(text, @"</b>", String.Empty); } if ((flags & RichTextFlags.Italic) == 0) { text = Regex.Replace(text, @"<i>", String.Empty); text = Regex.Replace(text, @"</i>", String.Empty); } if ((flags & RichTextFlags.Size) == 0) { text = Regex.Replace(text, @"<size=[0-9]+>", String.Empty); text = Regex.Replace(text, @"</size>", String.Empty); } else { text = Regex.Replace(text, @"<size=(?<Percent>[0-9]+)%>", new MatchEvaluator((Match match) => { var value = match.Groups["Percent"].Value; var newValue = value; float fValue; if (float.TryParse(value, out fValue) == true) { newValue = ((int)(fontSize * (fValue / 100f))).ToString(); } return string.Format("<size={0}>", newValue); })); } if ((flags & RichTextFlags.Color) == 0) { text = Regex.Replace(text, @"<color=[^>]+>", String.Empty); text = Regex.Replace(text, @"</color>", String.Empty); } if ((flags & RichTextFlags.Material) == 0) { text = Regex.Replace(text, @"<material=[^>]+>", String.Empty); text = Regex.Replace(text, @"</material>", String.Empty); } if ((flags & RichTextFlags.Quad) == 0) { text = Regex.Replace(text, @"<quad [^>]+>", String.Empty); } return text; }