← 返回首页
package org.unicode.bidi; /* * (C) Copyright IBM Corp. 1999, All Rights Reserved * (C) Copyright Google Inc. 2013, All Rights Reserved * (C) Copyright ASMUS, Inc. 2013, All Rights Reserved * * Distributed under the Terms of Use in http://www.unicode.org/copyright.html. */ import java.io.PrintWriter; /** * A class that maps ASCII characters to bidi direction types, used for testing purposes. * This class should not be used as a model for access to or storage of this information. * * @author Doug Felt */ public abstract class BidiReferenceTestCharmap { /** Charmap instance that maps portions of ASCII to strong format codes. */ public static final BidiReferenceTestCharmap TEST_ENGLISH = new TestEnglish(); /** Charmap instance that maps portions of ASCII to AL, AN. */ public static final BidiReferenceTestCharmap TEST_MIXED = new TestMixed(); /** Charmap instance that maps portions of ASCII to R. */ public static final BidiReferenceTestCharmap TEST_HEBREW = new TestHebrew(); /** Charmap instance that maps portions of ASCII to AL, AN, R. */ public static final BidiReferenceTestCharmap TEST_ARABIC = new TestArabic(); /** Charmap instance that maps portions of ASCII to R, and brackets to ON for PBA. */ public static final BidiReferenceTestCharmap TEST_PBA = new TestPBA(); private static final byte L = BidiReference.L; private static final byte LRE = BidiReference.LRE; private static final byte LRO = BidiReference.LRO; private static final byte R = BidiReference.R; private static final byte AL = BidiReference.AL; private static final byte RLE = BidiReference.RLE; private static final byte RLO = BidiReference.RLO; private static final byte PDF = BidiReference.PDF; private static final byte EN = BidiReference.EN; private static final byte ES = BidiReference.ES; private static final byte ET = BidiReference.ET; private static final byte AN = BidiReference.AN; private static final byte CS = BidiReference.CS; private static final byte NSM = BidiReference.NSM; private static final byte BN = BidiReference.BN; private static final byte B = BidiReference.B; private static final byte S = BidiReference.S; private static final byte WS = BidiReference.WS; private static final byte ON = BidiReference.ON; private static final byte RLI = BidiReference.RLI; private static final byte LRI = BidiReference.LRI; private static final byte FSI = BidiReference.FSI; private static final byte PDI = BidiReference.PDI; private static final byte TYPE_MIN = BidiReference.TYPE_MIN; private static final byte TYPE_MAX = BidiReference.TYPE_MAX; private static final String[] typenames = BidiReference.typenames; /** * Return the name of this mapping. */ public abstract String getName(); /** * Return the bidi direction codes corresponding to the ASCII characters in the string. * @param str the string * @return an array of bidi direction codes */ public final byte[] getCodes(String str) { return getCodes(str.toCharArray()); } /** * Return the bidi direction codes corresponding to the ASCII characters in the array. * @param chars the array of ASCII characters * @return an array of bidi direction codes */ public final byte[] getCodes(char[] chars) { return getCodes(chars, 0, chars.length); } /** * Return the bidi direction codes corresponding to the ASCII characters in the subrange * of the array. * @param chars the array of ASCII characters * @param charstart the start of the subrange to use * @param count the number of characters in the subrange to use * @return an array of bidi direction codes */ public final byte[] getCodes(char[] chars, int charstart, int count) { final byte[] result = new byte[count]; convert(chars, charstart, result, 0, count); return result; } /** * Display the mapping from ASCII to bidi direction codes using the provided PrintWriter. */ public abstract void dumpInfo(PrintWriter w); /** * Convert a subrange of characters to direction codes and place into the code array. * * @param chars the characters to convert * @param charStart the start position in the chars array * @param codes the destination array for the direction codes * @param codeStart the start position in the codes array * @param count the number of characters to convert to direction codes */ public abstract void convert(char[] chars, int charStart, byte[] codes, int codeStart, int count); /** * Diagnostic utility to list array of bidi direction codes * * @param w - where to output * @param codes - array of bidi direction codes */ public abstract void dumpCodes(PrintWriter w, byte [] codes); /** * Constructor for subclass use. */ protected BidiReferenceTestCharmap() { // don't know why the compiler default constructor isn't acceptable } // // Default implementation classes // /** * Default implementation that maps ASCII to all bidi types. * * This is the base class for TestArabic, TestHebrew, and TestMixed mappings. */ public static class DefaultCharmap extends BidiReferenceTestCharmap { protected String name; protected byte[] map; /** * Initialize to default mapping, and define name. */ public DefaultCharmap(String name) { this.name = name; map = baseMap.clone(); // steal some printable characters for format controls, etc // finalize basic mapping setMap(RLO, "}"); setMap(LRO, "{"); setMap(PDF, "^"); setMap(RLE, "]"); setMap(LRE, "["); setMap(RLI, ">"); setMap(LRI, "