2 *******************************************************************************
\r
3 * Copyright (C) 2001-2009, International Business Machines
\r
4 * Corporation and others. All Rights Reserved.
\r
5 *******************************************************************************
\r
7 /* Written by Simon Montagu, Matitiahu Allouche
\r
8 * (ported from C code written by Markus W. Scherer)
\r
11 package com.ibm.icu.text;
\r
14 * A BidiRun represents a sequence of characters at the same embedding level.
\r
15 * The Bidi algorithm decomposes a piece of text into sequences of characters
\r
16 * at the same embedding level, each such sequence is called a <quote>run</quote>.
\r
18 * <p>A BidiRun represents such a run by storing its essential properties,
\r
19 * but does not duplicate the characters which form the run.
\r
21 * <p>The "limit" of the run is the position just after the
\r
22 * last character, i.e., one more than that position.
\r
24 * <p>This class has no public constructor, and its members cannot be
\r
25 * modified by users.
\r
27 * @see com.ibm.icu.text.Bidi
\r
30 public class BidiRun {
\r
32 int start; /* first logical position of the run */
\r
33 int limit; /* last visual position of the run +1 */
\r
34 int insertRemove; /* if >0, flags for inserting LRM/RLM before/after run,
\r
35 if <0, count of bidi controls within run */
\r
39 * Default constructor
\r
41 * Note that members start and limit of a run instance have different
\r
42 * meanings depending whether the run is part of the runs array of a Bidi
\r
43 * object, or if it is a reference returned by getVisualRun() or
\r
45 * For a member of the runs array of a Bidi object,
\r
46 * - start is the first logical position of the run in the source text.
\r
47 * - limit is one after the last visual position of the run.
\r
48 * For a reference returned by getLogicalRun() or getVisualRun(),
\r
49 * - start is the first logical position of the run in the source text.
\r
50 * - limit is one after the last logical position of the run.
\r
54 this(0, 0, (byte)0);
\r
60 BidiRun(int start, int limit, byte embeddingLevel)
\r
64 this.level = embeddingLevel;
\r
68 * Copy the content of a BidiRun instance
\r
70 void copyFrom(BidiRun run)
\r
72 this.start = run.start;
\r
73 this.limit = run.limit;
\r
74 this.level = run.level;
\r
75 this.insertRemove = run.insertRemove;
\r
79 * Get the first logical position of the run in the source text
\r
82 public int getStart()
\r
88 * Get position of one character after the end of the run in the source text
\r
91 public int getLimit()
\r
100 public int getLength()
\r
102 return limit - start;
\r
109 public byte getEmbeddingLevel()
\r
115 * Check if run level is odd
\r
116 * @return true if the embedding level of this run is odd, i.e. it is a
\r
117 * right-to-left run.
\r
120 public boolean isOddRun()
\r
122 return (level & 1) == 1;
\r
126 * Check if run level is even
\r
127 * @return true if the embedding level of this run is even, i.e. it is a
\r
128 * left-to-right run.
\r
131 public boolean isEvenRun()
\r
133 return (level & 1) == 0;
\r
137 * Get direction of run
\r
140 public byte getDirection()
\r
142 return (byte)(level & 1);
\r
146 * String to display run
\r
149 public String toString()
\r
151 return new String("BidiRun " + start + " - " + limit + " @ " + level);
\r