1 /* 2 * Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 /* 26 ******************************************************************************* 27 * (C) Copyright IBM Corp. and others, 1996-2009 - All Rights Reserved * 28 * * 29 * The original version of this source code and documentation is copyrighted * 30 * and owned by IBM, These materials are provided under terms of a License * 31 * Agreement between IBM and Sun. This technology is protected by multiple * 32 * US and International patents. This notice and attribution to IBM may not * 33 * to removed. * 34 ******************************************************************************* 35 */ 36 /* Written by Simon Montagu, Matitiahu Allouche 37 * (ported from C code written by Markus W. Scherer) 38 */ 39 40 package jdk.internal.icu.text; 41 42 /** 43 * A BidiRun represents a sequence of characters at the same embedding level. 44 * The Bidi algorithm decomposes a piece of text into sequences of characters 45 * at the same embedding level, each such sequence is called a "run". 46 * 47 * <p>A BidiRun represents such a run by storing its essential properties, 48 * but does not duplicate the characters which form the run. 49 * 50 * <p>The "limit" of the run is the position just after the 51 * last character, i.e., one more than that position. 52 * 53 * <p>This class has no public constructor, and its members cannot be 54 * modified by users. 55 * 56 * @see com.ibm.icu.text.Bidi 57 */ 58 class BidiRun { 59 60 int start; /* first logical position of the run */ 61 int limit; /* last visual position of the run +1 */ 62 int insertRemove; /* if >0, flags for inserting LRM/RLM before/after run, 63 if <0, count of bidi controls within run */ 64 byte level; 65 66 /* 67 * Default constructor 68 * 69 * Note that members start and limit of a run instance have different 70 * meanings depending whether the run is part of the runs array of a Bidi 71 * object, or if it is a reference returned by getVisualRun() or 72 * getLogicalRun(). 73 * For a member of the runs array of a Bidi object, 74 * - start is the first logical position of the run in the source text. 75 * - limit is one after the last visual position of the run. 76 * For a reference returned by getLogicalRun() or getVisualRun(), 77 * - start is the first logical position of the run in the source text. 78 * - limit is one after the last logical position of the run. 79 */ BidiRun()80 BidiRun() 81 { 82 this(0, 0, (byte)0); 83 } 84 85 /* 86 * Constructor 87 */ BidiRun(int start, int limit, byte embeddingLevel)88 BidiRun(int start, int limit, byte embeddingLevel) 89 { 90 this.start = start; 91 this.limit = limit; 92 this.level = embeddingLevel; 93 } 94 95 /* 96 * Copy the content of a BidiRun instance 97 */ copyFrom(BidiRun run)98 void copyFrom(BidiRun run) 99 { 100 this.start = run.start; 101 this.limit = run.limit; 102 this.level = run.level; 103 this.insertRemove = run.insertRemove; 104 } 105 106 /** 107 * Get level of run 108 */ getEmbeddingLevel()109 byte getEmbeddingLevel() 110 { 111 return level; 112 } 113 114 /** 115 * Check if run level is even 116 * @return true if the embedding level of this run is even, i.e. it is a 117 * left-to-right run. 118 */ isEvenRun()119 boolean isEvenRun() 120 { 121 return (level & 1) == 0; 122 } 123 124 } 125