static bool IsStyleTag(string tag, RichTextType type) { if (string.IsNullOrEmpty(tag)) { return(false); } if (type == RichTextType.gui_style) { if (tag == "<i>" || tag == "</i>" || tag == "<b>" || tag == "</b>") { return(true); } else if (tag.Length > 8 && tag.StartsWith("<color=")) { return(false); } else if (tag.StartsWith("<size=")) { return(false); } else { return(false); } } else if (type == RichTextType.ngui_style) { return(false); } else { return(false); } }
private static string RichTextTypeToString(RichTextType richTextType) { return(richTextType switch { RichTextType.Equation => "equation", RichTextType.Mention => "mention", RichTextType.Text => "text", _ => throw new ArgumentOutOfRangeException(nameof(richTextType), richTextType, null) });
public static string Convert(string input, RichTextType type) { switch (type) { case RichTextType.Item: return(Regex.Replace(input, pattern, ItemMatchEvaluator)); case RichTextType.Npc: return(Regex.Replace(input, pattern, NpcMatchEvaluator)); default: return(string.Empty); } }
public TextTag EndTag(RichTextType type) { if (type == RichTextType.gui_style) { return(GUIEndTag); } else if (type == RichTextType.ngui_style) { return(NGUIEndTag); } else { return(default(TextTag)); } }
public static string UseStyles(LinkedList <RichTextStyle> styles, string text, RichTextType type = RichTextType.gui_style, int offset = 0) { if (text == null || styles == null || styles.Count == 0) { return(text); } int len = text.Length; System.Text.StringBuilder builder = new System.Text.StringBuilder(text); LinkedListNode <RichTextStyle> node = styles.Last; while (node != null) { RichTextStyle set = node.Value; node = node.Previous; if (set.start + offset >= len) { continue; } TextTag tag = set.EndTag(type); if (!string.IsNullOrEmpty(tag.tag)) { builder.Insert(Mathf.Clamp(tag.offset + offset, 0, len), tag.tag); } tag = set.StartTag(type); if (!string.IsNullOrEmpty(tag.tag)) { builder.Insert(Mathf.Clamp(tag.offset + offset, 0, len), tag.tag); } } return(builder.ToString()); }