コード例 #1
0
 public static string Fix(string str, bool showTashkeel, bool useHinduNumbers)
 {
     ArabicFixerTool.showTashkeel    = showTashkeel;
     ArabicFixerTool.useHinduNumbers = useHinduNumbers;
     if (str.Contains("\n"))
     {
         str = str.Replace("\n", Environment.NewLine);
     }
     if (str.Contains(Environment.NewLine))
     {
         string[] separator = new string[] { Environment.NewLine };
         string[] strArray2 = str.Split(separator, StringSplitOptions.None);
         if (strArray2.Length == 0)
         {
             return(ArabicFixerTool.FixLine(str));
         }
         if (strArray2.Length == 1)
         {
             return(ArabicFixerTool.FixLine(str));
         }
         string str2  = ArabicFixerTool.FixLine(strArray2[0]);
         int    index = 1;
         if (strArray2.Length > 1)
         {
             while (index < strArray2.Length)
             {
                 str2 = str2 + Environment.NewLine + ArabicFixerTool.FixLine(strArray2[index]);
                 index++;
             }
         }
         return(str2);
     }
     return(ArabicFixerTool.FixLine(str));
 }
コード例 #2
0
        /// <summary>
        /// Fix the specified string with customization options.
        /// </summary>
        /// <param name='str'>
        /// String to be fixed.
        /// </param>
        /// <param name='showTashkeel'>
        /// Show tashkeel.
        /// </param>
        /// <param name='useHinduNumbers'>
        /// Use hindu numbers.
        /// </param>
        public static string Fix(string str, bool showTashkeel, bool useHinduNumbers)
        {
            ArabicFixerTool.showTashkeel    = showTashkeel;
            ArabicFixerTool.useHinduNumbers = useHinduNumbers;

            str = str.Replace("\n", Environment.NewLine);

            if (!str.Contains(Environment.NewLine))
            {
                return(ArabicFixerTool.FixLine(str));
            }

            string[] stringSeparators = new string[] { Environment.NewLine };
            string[] strSplit         = str.Split(stringSeparators, StringSplitOptions.None);

            switch (strSplit.Length)
            {
            case 0:
            case 1:
                return(ArabicFixerTool.FixLine(str));

            default:
                StringBuilder outputString = new StringBuilder(ArabicFixerTool.FixLine(strSplit[0]));
                for (int iteration = 1; iteration < strSplit.Length; iteration++)
                {
                    outputString.Append(Environment.NewLine + ArabicFixerTool.FixLine(strSplit[iteration]));
                }

                return(outputString.ToString());
            }
        }
コード例 #3
0
        /// <summary>
        /// Fix the specified string with customization options.
        /// </summary>
        /// <param name='str'>
        /// String to be fixed.
        /// </param>
        /// <param name='showTashkeel'>
        /// Show tashkeel.
        /// </param>
        /// <param name='useHinduNumbers'>
        /// Use hindu numbers.
        /// </param>
        public static string Fix(string str, bool showTashkeel, bool useHinduNumbers)
        {
            ArabicFixerTool.showTashkeel    = showTashkeel;
            ArabicFixerTool.useHinduNumbers = useHinduNumbers;

            if (str.IsNullOrEmpty())
            {
                return("");
            }

            if (str.Contains("\n"))
            {
                str = str.Replace("\n", Environment.NewLine);
            }

            if (str.Contains(Environment.NewLine))
            {
                string[] stringSeparators = new string[] { Environment.NewLine };
                string[] strSplit         = str.Split(stringSeparators, StringSplitOptions.None);

                if (strSplit.Length == 0)
                {
                    return(ArabicFixerTool.FixLine(str));
                }
                else if (strSplit.Length == 1)
                {
                    return(ArabicFixerTool.FixLine(str));
                }
                else
                {
                    string outputString = ArabicFixerTool.FixLine(strSplit[0]);
                    int    iteration    = 1;
                    if (strSplit.Length > 1)
                    {
                        while (iteration < strSplit.Length)
                        {
                            outputString += Environment.NewLine + ArabicFixerTool.FixLine(strSplit[iteration]);
                            iteration++;
                        }
                    }
                    return(outputString);
                }
            }
            else
            {
                return(ArabicFixerTool.FixLine(str));
            }
        }
コード例 #4
0
        /// <summary>
        /// Fix the specified string with customization options.
        /// </summary>
        /// <param name='str'>
        /// String to be fixed.
        /// </param>
        /// <param name='showTashkeel'>
        /// Show tashkeel.
        /// </param>
        /// <param name='useHinduNumbers'>
        /// Use hindu numbers.
        /// </param>
        public static string Fix(string str, bool showTashkeel, bool useHinduNumbers)
        {
            ArabicFixerTool.showTashkeel    = showTashkeel;
            ArabicFixerTool.useHinduNumbers = useHinduNumbers;

            if (str.Contains("\n"))
            {
                str = str.Replace("\n", "\r\n");
            }

            if (str.Contains("\r\n"))
            {
                string[] stringSeparators = { "\r\n" };
                string[] strSplit         = str.Split(stringSeparators, StringSplitOptions.None);

                if (strSplit.Length == 0)
                {
                    return(ArabicFixerTool.FixLine(str));
                }
                else if (strSplit.Length == 1)
                {
                    return(ArabicFixerTool.FixLine(str));
                }
                else
                {
                    var outputString = ArabicFixerTool.FixLine(strSplit[0]);
                    var iteration    = 1;
                    if (strSplit.Length <= 1)
                    {
                        return(outputString);
                    }
                    while (iteration < strSplit.Length)
                    {
                        outputString += "\r\n" + ArabicFixerTool.FixLine(strSplit[iteration]);
                        iteration++;
                    }
                    return(outputString);
                }
            }

            return(ArabicFixerTool.FixLine(str));
        }
コード例 #5
0
ファイル: ArabicFixerTool.cs プロジェクト: gsoec/lm-source
    // Token: 0x06000136 RID: 310 RVA: 0x0001402C File Offset: 0x0001222C
    public unsafe string FixLine(string str, bool showTashkeel = false)
    {
        ArabicFixerTool.showTashkeel = showTashkeel;
        string value = this.RemoveTashkeel(str, ref this.tashkeelLocation);

        this.ctext1.ClearString();
        this.ctext2.ClearString();
        this.ctext1.Append(value);
        this.ctext2.Append(value);
        if (this.ctext1.Length == 0)
        {
            return(string.Empty);
        }

        fixed(string text = this.ctext1.ToString())
        {
            fixed(char *ptr = text + RuntimeHelpers.OffsetToStringData / 2)
            {
                fixed(string text2 = this.ctext2.ToString())
                {
                    fixed(char *ptr2 = text2 + RuntimeHelpers.OffsetToStringData / 2)
                    {
                        for (int i = 0; i < this.ctext1.Length; i++)
                        {
                            bool flag = false;
                            if (i == 0)
                            {
                                ptr[i] = (char)ArabicTable.ArabicMapper.Convert((int)ptr[i]);
                            }
                            if (this.ctext1.Length - 1 > i)
                            {
                                ptr[i + 1] = (char)ArabicTable.ArabicMapper.Convert((int)ptr[i + 1]);
                            }
                            if (ptr[i] == 'ﻝ' && this.ctext1.Length - 1 > i)
                            {
                                if (ptr[i + 1] == 'ﺇ')
                                {
                                    ptr[i]      = 'ﻷ';
                                    ptr2[i + 1] = this.SkipChar;
                                    flag        = true;
                                }
                                else if (ptr[i + 1] == 'ﺍ')
                                {
                                    ptr[i]      = 'ﻹ';
                                    ptr2[i + 1] = this.SkipChar;
                                    flag        = true;
                                }
                                else if (ptr[i + 1] == 'ﺃ')
                                {
                                    ptr[i]      = 'ﻵ';
                                    ptr2[i + 1] = this.SkipChar;
                                    flag        = true;
                                }
                                else if (ptr[i + 1] == 'ﺁ')
                                {
                                    ptr[i]      = 'ﻳ';
                                    ptr2[i + 1] = this.SkipChar;
                                    flag        = true;
                                }
                            }
                            if (!ArabicFixerTool.IsIgnoredCharacter(ptr[i]) && ptr[i] != 'A')
                            {
                                if (ArabicFixerTool.IsMiddleLetter(this.ctext1, i))
                                {
                                    ptr2[i] = ptr[i] + '\u0003';
                                }
                                else if (ArabicFixerTool.IsFinishingLetter(this.ctext1, i))
                                {
                                    ptr2[i] = ptr[i] + '\u0001';
                                }
                                else if (ArabicFixerTool.IsLeadingLetter(this.ctext1, i))
                                {
                                    ptr2[i] = ptr[i] + '\u0002';
                                }
                            }
                            if (flag)
                            {
                                i++;
                                if (this.ctext1.Length - 1 > i)
                                {
                                    ptr[i + 1] = (char)ArabicTable.ArabicMapper.Convert((int)ptr[i + 1]);
                                }
                            }
                        }
                        text2 = null;
                        text  = null;
                        if (ArabicFixerTool.showTashkeel)
                        {
                            this.ReturnTashkeel(this.ctext2, this.tashkeelLocation);
                        }
                        this.ctext1.ClearString();
                        this.ctext1.Append(this.ctext2);
                        this.ctext2.ClearString();
                        for (int j = this.ctext1.Length - 1; j >= 0; j--)
                        {
                            this.ctext2.Append(this.ctext1[j]);
                        }
                        return(this.ctext2.ToString());
                    }
                }
            }
        }
    }
コード例 #6
0
        private string FixRichTextTag(string str)
        {
            string[]                 stringSeparators = new string[] { Environment.NewLine };
            string[]                 strSplit         = str.Split(stringSeparators, StringSplitOptions.None);
            Stack <string>           tagStack         = new Stack <string>();
            List <List <TextBlock> > lineBlocks       = new List <List <TextBlock> >();

            for (int i = 0; i < strSplit.Length; i++)
            {
                List <TextBlock> lineBlock = new List <TextBlock>();
                if (ArabicFixerTool.IsRtl(strSplit[i]))
                {
                    MatchCollection matches = Regex.Matches(strSplit[i], @"<[^>]+>");
                    int             cPos    = strSplit[i].Length;
                    for (int j = matches.Count - 1; j >= 0; j--)
                    {
                        var tag      = matches[j].Value;
                        int idx      = strSplit[i].LastIndexOf(matches[j].Value, cPos);
                        int idxStart = idx + matches[j].Value.Length;
                        var text     = strSplit[i].Substring(idxStart, cPos - idxStart);
                        cPos = idx;
                        TextBlock block;
                        if (tag[tag.Length - 2] == '/')
                        {
                            block = new TextBlock(text, tagStack.ToArray());
                            tag   = tagStack.Pop();
                        }
                        else
                        {
                            char chTag = tag[tag.Length - 2];
                            switch (chTag)
                            {
                            case 'r':
                            {
                                int n     = tag.IndexOf("=color");
                                var color = tag.Substring(1, n - 1);
                                tag = $"<color={color}>";
                            }
                            break;

                            case 'e':
                            {
                                int n    = tag.IndexOf("=size");
                                var size = tag.Substring(1, n - 1);
                                tag = $"<size={size}>";
                            }
                            break;

                            case 'i':
                                tag = "<i>";
                                break;

                            case 'b':
                                tag = "<b>";
                                break;
                            }

                            if (tagStack.Count == 0)
                            {
                                block = new TextBlock(text);
                            }
                            else
                            {
                                block = new TextBlock(text, tagStack.ToArray());
                            }
                            tagStack.Push(tag);
                        }
                        if (text.Length > 0)
                        {
                            lineBlock.Add(block);
                        }
                    }

                    if (cPos != 0)
                    {
                        var text = strSplit[i].Substring(0, cPos);

                        TextBlock block;
                        if (tagStack.Count == 0)
                        {
                            block = new TextBlock(text);
                        }
                        else
                        {
                            block = new TextBlock(text, tagStack.ToArray());
                        }
                        lineBlock.Add(block);
                    }
                }
                else
                {
                    MatchCollection matches = Regex.Matches(strSplit[i], @"<[^>]+>");
                    int             cPos    = 0;
                    for (int j = 0; j < matches.Count; j++)
                    {
                        var tag  = matches[j].Value;
                        int idx  = strSplit[i].IndexOf(matches[j].Value, cPos);
                        var text = strSplit[i].Substring(cPos, idx - cPos);
                        cPos = idx + matches[j].Value.Length;
                        TextBlock block;
                        if (tag[1] == '/')
                        {
                            block = new TextBlock(text, tagStack.ToArray());
                            tag   = tagStack.Pop();
                        }
                        else
                        {
                            if (tagStack.Count == 0)
                            {
                                block = new TextBlock(text);
                            }
                            else
                            {
                                block = new TextBlock(text, tagStack.ToArray());
                            }
                            tagStack.Push(tag);
                        }
                        //if (text.Length > 0)
                        {
                            lineBlock.Insert(0, block);
                        }
                    }

                    if (cPos != strSplit[i].Length)
                    {
                        var text = strSplit[i].Substring(cPos);

                        TextBlock block;
                        if (tagStack.Count == 0)
                        {
                            block = new TextBlock(text);
                        }
                        else
                        {
                            block = new TextBlock(text, tagStack.ToArray());
                        }
                        lineBlock.Insert(0, block);
                    }
                }

                lineBlocks.Add(lineBlock);
            }


            StringBuilder fixTest = new StringBuilder();

            for (int l = 0; l < lineBlocks.Count; l++)
            {
                var lines = lineBlocks[l];
                for (int i = lines.Count - 1; i >= 0; i--)
                {
                    var bolck = lines[i];
                    if (bolck.tags != null)
                    {
                        for (int j = bolck.tags.Length - 1; j >= 0; j--)
                        {
                            fixTest.Append(bolck.tags[j]);
                        }
                    }
                    fixTest.Append(bolck.text);
                    if (bolck.tags != null)
                    {
                        for (int j = 0; j < bolck.tags.Length; j++)
                        {
                            char cTag = bolck.tags[j][1];
                            switch (cTag)
                            {
                            case 'c':
                                fixTest.Append("</color>");
                                break;

                            case 's':
                                fixTest.Append("</size>");
                                break;

                            case 'b':
                                fixTest.Append("</b>");
                                break;

                            case 'i':
                                fixTest.Append("</i>");
                                break;
                            }
                        }
                    }
                }
                fixTest.Append(Environment.NewLine);
            }

            return(fixTest.ToString());
        }