/// <summary> /// Correct the text between tags, including nested richtext tags (if any) /// </summary> /// <param name="text"></param> /// <param name="TMPro">is TextMesh Pro text?</param> /// <returns></returns> static string CorrectBetweenTags(string text, bool TMPro = false) { string finalString = ""; int startIdx = text.IndexOf('>'); int endIdx = text.LastIndexOf("</"); string startTag = text.Substring(0, startIdx + 1); string endTag = text.Substring(endIdx, text.Length - endIdx); // text between tags (may or may not include nested richtext) <>abc</> or <><>abc</></> string betweenStr = text.Substring(startTag.Length, text.Length - startTag.Length - endTag.Length); // recursively extract nested richtext if (StartsWithTag(betweenStr) && EndsWithTag(betweenStr)) { betweenStr = CorrectBetweenTags(betweenStr); } else // no richtext, correct { betweenStr = EasyArabicInternals.Correct(betweenStr.ToCharArray(), (int)NumCase); if (!TMPro) { betweenStr = ReverseArabic(betweenStr); } } // append the strings finalString += betweenStr; // insert the start tag at the start, and end tag at the end. <>abc abc</> ==> <>abc</> finalString = finalString.Insert(0, startTag); finalString = finalString.Insert(finalString.Length, endTag); return(finalString); }
/// <summary> /// Correct each string in the list whether the text is normal or between tags (richtext) /// </summary> /// <param name="inputStrings"></param> /// <param name="TMPro">is TextMesh Pro text?</param> /// <returns></returns> static string CorrectText(List <string> inputStrings, bool TMPro = false) { string finalString = ""; if (!TMPro) { inputStrings.Reverse(); } for (int i = 0; i < inputStrings.Count; i++) { // richtext string. extract the text between tags, correct it and replace the old one with it if (StartsWithTag(inputStrings[i]) && EndsWithTag(inputStrings[i])) { if (!TMPro) { inputStrings[i] = CorrectBetweenTags(inputStrings[i], false); } else { inputStrings[i] = CorrectBetweenTags(inputStrings[i], true); } } else { inputStrings[i] = EasyArabicInternals.Correct(inputStrings[i].ToCharArray(), (int)NumCase); // correct the string if (!TMPro) { inputStrings[i] = ReverseArabic(inputStrings[i]); // don't reverse textmesh pro text } } // concatenate the corrected strings finalString += inputStrings[i]; } return(finalString); }