Konash / arabic-support-unity

This plugin allows you to use accurate and correct Arabic text in your game or 3D application. Supports Tashkeel and Hindu numbers. Supports C# and JavaScript. Supports 4 Persian Characters.
MIT License
220 stars 64 forks source link

Rich Text formatting work around #45

Open st33d opened 3 years ago

st33d commented 3 years ago

I had to write a script in order to get around the fixer trashing rich text formatting.

Consider the following input:

<size=82%><color=#1FBEFF>أنقاض</color></size>

public static string FormatArabic(string input)
{
    bool inside = true;
    string inner = "";
    string output = "";
    for(int i = 0; i < input.Length; i++)
    {
        var c = input[i];
        switch(c)
        {
            case '<':
                inside = false;
                output += ArabicSupport.ArabicFixer.Fix(inner, false, false);
                inner = "";
                goto default;
            case '>':
                inside = true;
                output += c;
                break;
            default:
                if(inside == false)
                    output += c;
                else
                    inner += c;
                break;
        }
    }
    return output;
}

This appears to solve my problem. Whilst this is trivial to write, a lot of StackOverflow posts would recommend Regex instead.

It would be nice if the fixer supported this by default in some way.