]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_4_2-src/main/classes/core/src/com/ibm/icu/text/BidiRun.java
go
[Dictionary.git] / jars / icu4j-4_4_2-src / main / classes / core / src / com / ibm / icu / text / BidiRun.java
1 /*\r
2 *******************************************************************************\r
3 *   Copyright (C) 2001-2009, International Business Machines\r
4 *   Corporation and others.  All Rights Reserved.\r
5 *******************************************************************************\r
6 */\r
7 /* Written by Simon Montagu, Matitiahu Allouche\r
8  * (ported from C code written by Markus W. Scherer)\r
9  */\r
10 \r
11 package com.ibm.icu.text;\r
12 \r
13 /**\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
17  *\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
20  *\r
21  * <p>The &quot;limit&quot; of the run is the position just after the\r
22  * last character, i.e., one more than that position.\r
23  *\r
24  * <p>This class has no public constructor, and its members cannot be\r
25  * modified by users.\r
26  *\r
27  * @see com.ibm.icu.text.Bidi\r
28  * @stable ICU 3.8\r
29  */\r
30 public class BidiRun {\r
31 \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
36     byte level;\r
37 \r
38     /*\r
39      * Default constructor\r
40      *\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
44      * getLogicalRun().\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
51      */\r
52     BidiRun()\r
53     {\r
54         this(0, 0, (byte)0);\r
55     }\r
56 \r
57     /*\r
58      * Constructor\r
59      */\r
60     BidiRun(int start, int limit, byte embeddingLevel)\r
61     {\r
62         this.start = start;\r
63         this.limit = limit;\r
64         this.level = embeddingLevel;\r
65     }\r
66 \r
67     /*\r
68      * Copy the content of a BidiRun instance\r
69      */\r
70     void copyFrom(BidiRun run)\r
71     {\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
76     }\r
77 \r
78     /**\r
79      * Get the first logical position of the run in the source text\r
80      * @stable ICU 3.8\r
81      */\r
82     public int getStart()\r
83     {\r
84         return start;\r
85     }\r
86 \r
87     /**\r
88      * Get position of one character after the end of the run in the source text\r
89      * @stable ICU 3.8\r
90      */\r
91     public int getLimit()\r
92     {\r
93         return limit;\r
94     }\r
95 \r
96     /**\r
97      * Get length of run\r
98      * @stable ICU 3.8\r
99      */\r
100     public int getLength()\r
101     {\r
102         return limit - start;\r
103     }\r
104 \r
105     /**\r
106      * Get level of run\r
107      * @stable ICU 3.8\r
108      */\r
109     public byte getEmbeddingLevel()\r
110     {\r
111         return level;\r
112     }\r
113 \r
114     /**\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
118      * @stable ICU 3.8\r
119      */\r
120     public boolean isOddRun()\r
121     {\r
122         return (level & 1) == 1;\r
123     }\r
124 \r
125     /**\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
129      * @stable ICU 3.8\r
130      */\r
131     public boolean isEvenRun()\r
132     {\r
133         return (level & 1) == 0;\r
134     }\r
135 \r
136     /**\r
137      * Get direction of run\r
138      * @stable ICU 3.8\r
139      */\r
140     public byte getDirection()\r
141     {\r
142         return (byte)(level & 1);\r
143     }\r
144 \r
145     /**\r
146      * String to display run\r
147      * @stable ICU 3.8\r
148      */\r
149     public String toString()\r
150     {\r
151         return new String("BidiRun " + start + " - " + limit + " @ " + level);\r
152     }\r
153 }\r