/// <summary> /// Fixes the provided string /// </summary> /// <param name="input">Text to fix</param> /// <param name="output">Fixed text</param> /// <param name="fixTextTags"></param> /// <param name="preserveNumbers"></param> /// <param name="farsi"></param> /// <returns>Fixed text</returns> public static void FixRTL( string input, FastStringBuilder output, bool farsi = true, bool fixTextTags = true, bool preserveNumbers = false) { inputBuilder.SetValue(input); TashkeelFixer.RemoveTashkeel(inputBuilder); // The shape of the letters in shapeFixedLetters is fixed according to their position in word. But the flow of the text is not fixed. GlyphFixer.Fix(inputBuilder, glyphFixerOutput, preserveNumbers, farsi, fixTextTags); //Restore tashkeel to their places. TashkeelFixer.RestoreTashkeel(glyphFixerOutput); // Fix flow of the text and put the result in FinalLetters field LigatureFixer.Fix(glyphFixerOutput, output, farsi, fixTextTags, preserveNumbers); if (fixTextTags) { RichTextFixer.Fix(output); } inputBuilder.Clear(); }
/// <summary> /// Fixes the shape of letters based on their position. /// </summary> /// <param name="input"></param> /// <param name="output"></param> /// <param name="preserveNumbers"></param> /// <param name="farsi"></param> /// <returns></returns> public static void Fix(FastStringBuilder input, FastStringBuilder output, bool preserveNumbers, bool farsi) { FixYah(input, farsi); output.SetValue(input); for (int i = 0; i < input.Length; i++) { bool skipNext = false; char iChar = input.Get(i); // For special Lam Letter connections. if (iChar == (char)GeneralLetters.Lam) { if (i < input.Length - 1) { skipNext = HandleSpecialLam(input, output, i); if (skipNext) iChar = output.Get(i); } } // We don't want to fix tatweel or zwnj character if (iChar == (int)GeneralLetters.ArabicTatweel || iChar == (int)GeneralLetters.ZeroWidthNoJoiner) { continue; } if (TextUtils.IsRTLCharacter(iChar)) { char converted = GlyphTable.Convert(iChar); if (IsMiddleLetter(input, i)) { output.Set(i, (char)(converted + 3)); } else if (IsFinishingLetter(input, i)) { output.Set(i, (char)(converted + 1)); } else if (IsLeadingLetter(input, i)) { output.Set(i, (char)(converted + 2)); } } // If this letter as Lam and special Lam-Alef connection was made, We want to skip the Alef // (Lam-Alef occupies 1 space) if (skipNext) { i++; } } if (!preserveNumbers) { FixNumbers(output, farsi); } }
public void SetValue_IncreasesCapacity_AsNeeded() { var builder = new FastStringBuilder(0); builder.SetValue("abcd"); Assert.AreEqual("abcd", builder.ToString()); }
public void SetValue_SetsTheValueOfStringBuilderWithProvidedText() { var builder = new FastStringBuilder(10); builder.SetValue("abcd"); Assert.AreEqual("abcd", builder.ToString()); }
public void SetValue_CanCopyValueOfAnotherStringBuilder() { var builder1 = new FastStringBuilder("my holy moly text"); var builder2 = new FastStringBuilder(10); builder2.SetValue(builder1); Assert.AreEqual(builder1.ToString(), builder2.ToString()); }
public void SetValue_MakesIndependentCopies() { var builder1 = new FastStringBuilder("my holy moly text"); var builder2 = new FastStringBuilder(10); builder2.SetValue(builder1); builder1.Set(5, 'f'); Assert.AreNotEqual(builder1.ToString(), builder2.ToString()); }