3 using System.Collections.Immutable;
4 using System.Diagnostics;
12 private int languageVersion = 0;
26 private readonly Func<string, string>? postProcess;
27 private readonly
bool shouldParseRichTextData;
36 private bool forceUpperCase =
false;
38 private bool FontOrStyleForceUpperCase
42 public ImmutableArray<RichTextData>?
RichTextData {
get;
private set; }
46 LocalizedString nestedStr,
bool shouldParseRichTextData, Func<string, string>? postProcess =
null,
47 GUIFont? font =
null,
GUIComponentStyle? componentStyle =
null) : this(nestedStr, shouldParseRichTextData, postProcess)
50 this.componentStyle = componentStyle;
54 private RichString(LocalizedString nestedStr,
bool shouldParseRichTextData, Func<string,string>? postProcess =
null)
56 originalStr = nestedStr;
58 this.shouldParseRichTextData = shouldParseRichTextData;
59 this.postProcess = postProcess;
63 this.componentStyle =
null;
74 return new RichString(str,
false, postProcess:
null);
82 if (!lStr.IsNullOrEmpty() && lStr.
Contains(
"‖"))
87 return Plain(lStr ??
string.Empty);
94 ||
language != GameSettings.CurrentConfig.Language
95 || languageVersion != TextManager.LanguageVersion
97 || (FontOrStyleForceUpperCase != forceUpperCase)
105 NestedStr = FontOrStyleForceUpperCase ? originalStr.
ToUpper() : originalStr;
106 forceUpperCase = FontOrStyleForceUpperCase;
108 if (shouldParseRichTextData)
117 language = GameSettings.CurrentConfig.Language;
118 languageVersion = TextManager.LanguageVersion;
125 return new RichString(originalStr, shouldParseRichTextData, postProcess, font, componentStyle);
139 public RichString Replace(
string from,
string to, StringComparison stringComparison = StringComparison.Ordinal)
149 public bool Contains(
string str, StringComparison stringComparison = StringComparison.Ordinal) =>
152 public bool Contains(
char chr, StringComparison stringComparison = StringComparison.Ordinal) =>
157 => a?.SanitizedValue == b?.SanitizedValue
159 && a?.font == b?.font
160 && a?.componentStyle == b?.componentStyle
167 => a?.SanitizedValue == b?.Value;
172 => a?.Value == b?.SanitizedValue;
177 => a?.SanitizedValue == b;
182 => a == b?.SanitizedValue;
bool Contains(string subStr, StringComparison comparison=StringComparison.Ordinal)
LocalizedString ToLower()
virtual LocalizedString ToUpper()
LocalizedString Replace(Identifier find, LocalizedString replace, StringComparison stringComparison=StringComparison.Ordinal)
override string ToString()
bool Contains(string str, StringComparison stringComparison=StringComparison.Ordinal)
RichString Replace(string from, string to, StringComparison stringComparison=StringComparison.Ordinal)
LocalizedString NestedStr
virtual bool MustRetrieveValue()
string cachedSanitizedValue
static RichString Plain(LocalizedString str)
bool Contains(char chr, StringComparison stringComparison=StringComparison.Ordinal)
static RichString Rich(LocalizedString str, Func< string, string >? postProcess=null)
LanguageIdentifier language
readonly LocalizedString SanitizedString
static bool operator==(RichString? a, RichString? b)
static bool operator!=(RichString? a, RichString? b)
RichString CaseTiedToFontAndStyle(GUIFont? font, GUIComponentStyle? componentStyle)
static ? ImmutableArray< RichTextData > GetRichTextData(string text, out string sanitizedText)
static readonly LanguageIdentifier None