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) 2000-2009, International Business Machines Corporation and * 6 * 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 * Overrides default Bidi class values with custom ones. 17 * 18 * <p>The override mechanism requires to define a subclass of 19 * <code>BidiClassifier</code> which overrides the <code>classifier</code> 20 * method to assign customized Bidi classes.</p> 21 * 22 * <p>This may be useful for assigning Bidi classes to PUA characters, or 23 * for special application needs. For instance, an application may want to 24 * handle all spaces like L or R characters (according to the base direction) 25 * when creating the visual ordering of logical lines which are part of a report 26 * organized in columns: there should not be interaction between adjacent 27 * cells.</p> 28 * 29 * <p>To start using this customized 30 * classifier with a Bidi object, it must be specified by calling the 31 * <code>Bidi.setCustomClassifier</code> method; after that, the method 32 * <code>classify</code> of the custom <code>BidiClassifier</code> will be 33 * called by the UBA implementation any time the class of a character is 34 * to be determined.</p> 35 * 36 * @see Bidi#setCustomClassifier 37 * @stable ICU 3.8 38 */ 39 40 public /*abstract*/ class BidiClassifier { 41 42 /** 43 * This object can be used for any purpose by the caller to pass 44 * information to the BidiClassifier methods, and by the BidiClassifier 45 * methods themselves.<br> 46 * For instance, this object can be used to save a reference to 47 * a previous custom BidiClassifier while setting a new one, so as to 48 * allow chaining between them. 49 * @stable ICU 3.8 50 */ 51 protected Object context; 52 53 /** 54 * @param context Context for this classifier instance. 55 * May be null. 56 * @stable ICU 3.8 57 */ 58 public BidiClassifier(Object context) { 59 this.context = context; 60 } 61 62 /** 63 * Sets classifier context, which can be used either by a caller or 64 * callee for various purposes. 65 * 66 * @param context Context for this classifier instance. 67 * May be null. 68 * @stable ICU 3.8 69 */ 70 public void setContext(Object context) { 71 this.context = context; 72 } 73 74 /** 75 * Returns the current classifier context. 76 * @stable ICU 3.8 77 */ 78 public Object getContext() { 79 return this.context; 80 } 81 82 /** 83 * Gets customized Bidi class for the code point <code>c</code>. 84 * <p> 85 * Default implementation, to be overridden. 86 * 87 * @param c Code point to be classified. 88 * @return An integer representing directional property / Bidi class for the 89 * given code point <code>c</code>, or Bidi.CLASS_DEFAULT=UCharacter.getIntPropertyMaxValue(UProperty.BIDI_CLASS)+1 90 * to signify that there is no need to override the standard Bidi class for 91 * the given code point. 92 * @see Bidi#CLASS_DEFAULT 93 * @stable ICU 3.8 94 */ 95 public int classify(int c) { 96 return Bidi.CLASS_DEFAULT; 97 } 98 } 99