Exemplo n.º 1
0
 /// <summary>
 /// Copy the content of a BidiRun instance
 /// </summary>
 ///
 /// @draft ICU 3.8
 internal void CopyFrom(BidiRun run)
 {
     this.start        = run.start;
     this.limit        = run.limit;
     this.level        = run.level;
     this.insertRemove = run.insertRemove;
 }
Exemplo n.º 2
0
        static internal String WriteReordered(Bidi bidi, int options)
        {
            int           run, runCount;
            StringBuilder dest;

            char[] text = bidi.text;
            runCount = bidi.CountRuns();

            /*
             * Option "insert marks" implies Bidi.INSERT_LRM_FOR_NUMERIC if the
             * reordering mode (checked below) is appropriate.
             */
            if ((bidi.reorderingOptions & IBM.ICU.Text.Bidi.OPTION_INSERT_MARKS) != 0)
            {
                options |= IBM.ICU.Text.Bidi.INSERT_LRM_FOR_NUMERIC;
                options &= ~IBM.ICU.Text.Bidi.REMOVE_BIDI_CONTROLS;
            }

            /*
             * Option "remove controls" implies Bidi.REMOVE_BIDI_CONTROLS and
             * cancels Bidi.INSERT_LRM_FOR_NUMERIC.
             */
            if ((bidi.reorderingOptions & IBM.ICU.Text.Bidi.OPTION_REMOVE_CONTROLS) != 0)
            {
                options |= IBM.ICU.Text.Bidi.REMOVE_BIDI_CONTROLS;
                options &= ~IBM.ICU.Text.Bidi.INSERT_LRM_FOR_NUMERIC;
            }

            /*
             * If we do not perform the "inverse Bidi" algorithm, then we don't need
             * to insert any LRMs, and don't need to test for it.
             */
            if ((bidi.reorderingMode != IBM.ICU.Text.Bidi.REORDER_INVERSE_NUMBERS_AS_L) &&
                (bidi.reorderingMode != IBM.ICU.Text.Bidi.REORDER_INVERSE_LIKE_DIRECT) &&
                (bidi.reorderingMode != IBM.ICU.Text.Bidi.REORDER_INVERSE_FOR_NUMBERS_SPECIAL) &&
                (bidi.reorderingMode != IBM.ICU.Text.Bidi.REORDER_RUNS_ONLY))
            {
                options &= ~IBM.ICU.Text.Bidi.INSERT_LRM_FOR_NUMERIC;
            }
            dest = new StringBuilder(
                ((options & IBM.ICU.Text.Bidi.INSERT_LRM_FOR_NUMERIC) != 0) ? bidi.length * 2
                                : bidi.length);

            /*
             * Iterate through all visual runs and copy the run text segments to the
             * destination, according to the options.
             *
             * The tests for where to insert LRMs ignore the fact that there may be
             * BN codes or non-BMP code points at the beginning and end of a run;
             * they may insert LRMs unnecessarily but the tests are faster this way
             * (this would have to be improved for UTF-8).
             */
            if ((options & IBM.ICU.Text.Bidi.OUTPUT_REVERSE) == 0)
            {
                /* forward output */
                if ((options & IBM.ICU.Text.Bidi.INSERT_LRM_FOR_NUMERIC) == 0)
                {
                    /* do not insert Bidi controls */
                    for (run = 0; run < runCount; ++run)
                    {
                        BidiRun bidiRun = bidi.GetVisualRun(run);
                        if (bidiRun.IsEvenRun())
                        {
                            dest.Append(DoWriteForward(text, bidiRun.start,
                                                       bidiRun.limit, options & ~IBM.ICU.Text.Bidi.DO_MIRRORING));
                        }
                        else
                        {
                            dest.Append(DoWriteReverse(text, bidiRun.start,
                                                       bidiRun.limit, options));
                        }
                    }
                }
                else
                {
                    /* insert Bidi controls for "inverse Bidi" */
                    sbyte[] dirProps = bidi.dirProps;
                    char    uc;
                    int     markFlag;

                    for (run = 0; run < runCount; ++run)
                    {
                        BidiRun bidiRun_0 = bidi.GetVisualRun(run);
                        markFlag = 0;
                        /* check if something relevant in insertPoints */
                        markFlag = bidi.runs[run].insertRemove;
                        if (markFlag < 0)       /* bidi controls count */
                        {
                            markFlag = 0;
                        }
                        if (bidiRun_0.IsEvenRun())
                        {
                            if (bidi.IsInverse() &&
                                dirProps[bidiRun_0.start] != IBM.ICU.Text.Bidi.L)
                            {
                                markFlag |= IBM.ICU.Text.Bidi.LRM_BEFORE;
                            }
                            if ((markFlag & IBM.ICU.Text.Bidi.LRM_BEFORE) != 0)
                            {
                                uc = LRM_CHAR;
                            }
                            else if ((markFlag & IBM.ICU.Text.Bidi.RLM_BEFORE) != 0)
                            {
                                uc = RLM_CHAR;
                            }
                            else
                            {
                                uc = ((Char)0);
                            }
                            if (uc != 0)
                            {
                                dest.Append(uc);
                            }
                            dest.Append(DoWriteForward(text, bidiRun_0.start,
                                                       bidiRun_0.limit, options & ~IBM.ICU.Text.Bidi.DO_MIRRORING));

                            if (bidi.IsInverse() &&
                                dirProps[bidiRun_0.limit - 1] != IBM.ICU.Text.Bidi.L)
                            {
                                markFlag |= IBM.ICU.Text.Bidi.LRM_AFTER;
                            }
                            if ((markFlag & IBM.ICU.Text.Bidi.LRM_AFTER) != 0)
                            {
                                uc = LRM_CHAR;
                            }
                            else if ((markFlag & IBM.ICU.Text.Bidi.RLM_AFTER) != 0)
                            {
                                uc = RLM_CHAR;
                            }
                            else
                            {
                                uc = ((Char)0);
                            }
                            if (uc != 0)
                            {
                                dest.Append(uc);
                            }
                        }
                        else         /* RTL run */
                        {
                            if (bidi.IsInverse() &&
                                !bidi.TestDirPropFlagAt(MASK_R_AL,
                                                        bidiRun_0.limit - 1))
                            {
                                markFlag |= IBM.ICU.Text.Bidi.RLM_BEFORE;
                            }
                            if ((markFlag & IBM.ICU.Text.Bidi.LRM_BEFORE) != 0)
                            {
                                uc = LRM_CHAR;
                            }
                            else if ((markFlag & IBM.ICU.Text.Bidi.RLM_BEFORE) != 0)
                            {
                                uc = RLM_CHAR;
                            }
                            else
                            {
                                uc = ((Char)0);
                            }
                            if (uc != 0)
                            {
                                dest.Append(uc);
                            }
                            dest.Append(DoWriteReverse(text, bidiRun_0.start,
                                                       bidiRun_0.limit, options));

                            if (bidi.IsInverse() &&
                                (MASK_R_AL & IBM.ICU.Text.Bidi
                                 .DirPropFlag(dirProps[bidiRun_0.start])) == 0)
                            {
                                markFlag |= IBM.ICU.Text.Bidi.RLM_AFTER;
                            }
                            if ((markFlag & IBM.ICU.Text.Bidi.LRM_AFTER) != 0)
                            {
                                uc = LRM_CHAR;
                            }
                            else if ((markFlag & IBM.ICU.Text.Bidi.RLM_AFTER) != 0)
                            {
                                uc = RLM_CHAR;
                            }
                            else
                            {
                                uc = ((Char)0);
                            }
                            if (uc != 0)
                            {
                                dest.Append(uc);
                            }
                        }
                    }
                }
            }
            else
            {
                /* reverse output */
                if ((options & IBM.ICU.Text.Bidi.INSERT_LRM_FOR_NUMERIC) == 0)
                {
                    /* do not insert Bidi controls */
                    for (run = runCount; --run >= 0;)
                    {
                        BidiRun bidiRun_1 = bidi.GetVisualRun(run);
                        if (bidiRun_1.IsEvenRun())
                        {
                            dest.Append(DoWriteReverse(text, bidiRun_1.start,
                                                       bidiRun_1.limit, options & ~IBM.ICU.Text.Bidi.DO_MIRRORING));
                        }
                        else
                        {
                            dest.Append(DoWriteForward(text, bidiRun_1.start,
                                                       bidiRun_1.limit, options));
                        }
                    }
                }
                else
                {
                    /* insert Bidi controls for "inverse Bidi" */

                    sbyte[] dirProps_2 = bidi.dirProps;

                    for (run = runCount; --run >= 0;)
                    {
                        /* reverse output */
                        BidiRun bidiRun_3 = bidi.GetVisualRun(run);
                        if (bidiRun_3.IsEvenRun())
                        {
                            if (dirProps_2[bidiRun_3.limit - 1] != IBM.ICU.Text.Bidi.L)
                            {
                                dest.Append(LRM_CHAR);
                            }

                            dest.Append(DoWriteReverse(text, bidiRun_3.start,
                                                       bidiRun_3.limit, options & ~IBM.ICU.Text.Bidi.DO_MIRRORING));

                            if (dirProps_2[bidiRun_3.start] != IBM.ICU.Text.Bidi.L)
                            {
                                dest.Append(LRM_CHAR);
                            }
                        }
                        else
                        {
                            if ((MASK_R_AL & IBM.ICU.Text.Bidi
                                 .DirPropFlag(dirProps_2[bidiRun_3.start])) == 0)
                            {
                                dest.Append(RLM_CHAR);
                            }

                            dest.Append(DoWriteForward(text, bidiRun_3.start,
                                                       bidiRun_3.limit, options));

                            if ((MASK_R_AL & IBM.ICU.Text.Bidi
                                 .DirPropFlag(dirProps_2[bidiRun_3.limit - 1])) == 0)
                            {
                                dest.Append(RLM_CHAR);
                            }
                        }
                    }
                }
            }

            return(dest.ToString());
        }