1 // 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html#License 3 /* 4 ******************************************************************************* 5 * Copyright (C) 2001-2016, International Business Machines 6 * Corporation and others. All Rights Reserved. 7 ******************************************************************************* 8 */ 9 /* Written by Simon Montagu, Matitiahu Allouche 10 * (ported from C code written by Markus W. Scherer) 11 */ 12 13 package com.ibm.icu.text; 14 15 /** 16 * A BidiRun represents a sequence of characters at the same embedding level. 17 * The Bidi algorithm decomposes a piece of text into sequences of characters 18 * at the same embedding level, each such sequence is called a "run". 19 * 20 * <p>A BidiRun represents such a run by storing its essential properties, 21 * but does not duplicate the characters which form the run. 22 * 23 * <p>The "limit" of the run is the position just after the 24 * last character, i.e., one more than that position. 25 * 26 * <p>This class has no public constructor, and its members cannot be 27 * modified by users. 28 * 29 * @see com.ibm.icu.text.Bidi 30 * @stable ICU 3.8 31 */ 32 public class BidiRun { 33 34 int start; /* first logical position of the run */ 35 int limit; /* last visual position of the run +1 */ 36 int insertRemove; /* if >0, flags for inserting LRM/RLM before/after run, 37 if <0, count of bidi controls within run */ 38 byte level; 39 40 /* 41 * Default constructor 42 * 43 * Note that members start and limit of a run instance have different 44 * meanings depending whether the run is part of the runs array of a Bidi 45 * object, or if it is a reference returned by getVisualRun() or 46 * getLogicalRun(). 47 * For a member of the runs array of a Bidi object, 48 * - start is the first logical position of the run in the source text. 49 * - limit is one after the last visual position of the run. 50 * For a reference returned by getLogicalRun() or getVisualRun(), 51 * - start is the first logical position of the run in the source text. 52 * - limit is one after the last logical position of the run. 53 */ 54 BidiRun() 55 { 56 this(0, 0, (byte)0); 57 } 58 59 /* 60 * Constructor 61 */ 62 BidiRun(int start, int limit, byte embeddingLevel) 63 { 64 this.start = start; 65 this.limit = limit; 66 this.level = embeddingLevel; 67 } 68 69 /* 70 * Copy the content of a BidiRun instance 71 */ 72 void copyFrom(BidiRun run) 73 { 74 this.start = run.start; 75 this.limit = run.limit; 76 this.level = run.level; 77 this.insertRemove = run.insertRemove; 78 } 79 80 /** 81 * Get the first logical position of the run in the source text 82 * @stable ICU 3.8 83 */ 84 public int getStart() 85 { 86 return start; 87 } 88 89 /** 90 * Get position of one character after the end of the run in the source text 91 * @stable ICU 3.8 92 */ 93 public int getLimit() 94 { 95 return limit; 96 } 97 98 /** 99 * Get length of run 100 * @stable ICU 3.8 101 */ 102 public int getLength() 103 { 104 return limit - start; 105 } 106 107 /** 108 * Get level of run 109 * @stable ICU 3.8 110 */ 111 public byte getEmbeddingLevel() 112 { 113 return level; 114 } 115 116 /** 117 * Check if run level is odd 118 * @return true if the embedding level of this run is odd, i.e. it is a 119 * right-to-left run. 120 * @stable ICU 3.8 121 */ 122 public boolean isOddRun() 123 { 124 return (level & 1) == 1; 125 } 126 127 /** 128 * Check if run level is even 129 * @return true if the embedding level of this run is even, i.e. it is a 130 * left-to-right run. 131 * @stable ICU 3.8 132 */ 133 public boolean isEvenRun() 134 { 135 return (level & 1) == 0; 136 } 137 138 /** 139 * Get direction of run 140 * @stable ICU 3.8 141 */ 142 public byte getDirection() 143 { 144 return (byte)(level & 1); 145 } 146 147 /** 148 * String to display run 149 * @stable ICU 3.8 150 */ 151 @Override 152 public String toString() 153 { 154 return "BidiRun " + start + " - " + limit + " @ " + level; 155 } 156 } 157