APIdia Launch Partner
Top Description Fields Constructors Methods
sun.font

public final Class ScriptRun

extends Object
Class Inheritance

ScriptRun is used to find runs of characters in the same script, as defined in the Script class. It implements a simple iterator over an array of characters. The iterator will assign COMMON and INHERITED characters to the same script as the preceding characters. If the COMMON and INHERITED characters are first, they will be assigned to the same script as the following characters. The iterator will try to match paired punctuation. If it sees an opening punctuation character, it will remember the script that was assigned to that character, and assign the same script to the matching closing punctuation. No attempt is made to combine related scripts into a single run. In particular, Hiragana, Katakana, and Han characters will appear in separate runs. Here is an example of how to iterate over script runs:
void printScriptRuns(char[] text)
{
    ScriptRun scriptRun = new ScriptRun(text, 0, text.length);

    while (scriptRun.next()) {
        int start  = scriptRun.getScriptStart();
        int limit  = scriptRun.getScriptLimit();
        int script = scriptRun.getScriptCode();

        System.out.println("Script \"" + Script.getName(script) + "\" from " +
                           start + " to " + limit + ".");
    }
 }

Field Summary

Modifier and TypeField and Description
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
private static final int
private static final int
private static int[]
private int
private int
private int
private int
private int[]
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
private char[]
private int
private int

Constructor Summary

AccessConstructor and Description
public
public
ScriptRun(char[]
the array of characters over which to iterate.
chars
,
int
the index of the first character over which to iterate
start
,
int
the number of characters over which to iterate
count
)

Construct a ScriptRun object which iterates over a subrange of the given characters.

Method Summary

Modifier and TypeMethod and Description
private static int

Returns:

the index of the character in the table, or -1 if it's not there.
getPairIndex
(int
the character for which to search.
ch
)

Search the pairedChars array for the given character.

public int

Returns:

the script code for the script of the current script run.
getScriptCode
()

Get the script code for the script of the current script run.

public int

Returns:

the index of the first character after the current script run.
getScriptLimit
()

Get the index of the first character after the current script run.

public int

Returns:

the index of the first character in the current script run.
getScriptStart
()

Get the starting index of the current script run.

private static byte

Returns:

the bit number (counting from the low order bit) of the highest bit.
highBit
(int
the word in which to find the highest bit that's set.
n
)

Find the highest bit that's set in a word.

public void
init(char[] chars, int start, int count)

public boolean

Returns:

false if there isn't another run, true if there is.
next
()

Find the next script run.

private int
private void
pushback(int ch)

private static boolean

Returns:

true if the two scripts are the same.
sameScript
(int
one of the script codes.
scriptOne
,
int
the other script code.
scriptTwo
)

Compare two script codes to see if they are in the same script.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DONEback to summary
pack-priv static final int DONE
LEAD_LIMITback to summary
pack-priv static final int LEAD_LIMIT
LEAD_STARTback to summary
pack-priv static final int LEAD_START
LEAD_SURROGATE_SHIFTback to summary
pack-priv static final int LEAD_SURROGATE_SHIFT
pairedCharExtraback to summary
private static final int pairedCharExtra
pairedCharPowerback to summary
private static final int pairedCharPower
pairedCharsback to summary
private static int[] pairedChars
parenSPback to summary
private int parenSP
scriptCodeback to summary
private int scriptCode
scriptLimitback to summary
private int scriptLimit
scriptStartback to summary
private int scriptStart
stackback to summary
private int[] stack
SURROGATE_OFFSETback to summary
pack-priv static final int SURROGATE_OFFSET
SURROGATE_STARTback to summary
pack-priv static final int SURROGATE_START
TAIL_LIMITback to summary
pack-priv static final int TAIL_LIMIT
TAIL_STARTback to summary
pack-priv static final int TAIL_START
textback to summary
private char[] text
textLimitback to summary
private int textLimit
textStartback to summary
private int textStart

Constructor Detail

ScriptRunback to summary
public ScriptRun()
ScriptRunback to summary
public ScriptRun(char[] chars, int start, int count)

Construct a ScriptRun object which iterates over a subrange of the given characters.

Parameters
chars:char[]

the array of characters over which to iterate.

start:int

the index of the first character over which to iterate

count:int

the number of characters over which to iterate

Method Detail

getPairIndexback to summary
private static int getPairIndex(int ch)

Search the pairedChars array for the given character.

Parameters
ch:int

the character for which to search.

Returns:int

the index of the character in the table, or -1 if it's not there.

getScriptCodeback to summary
public int getScriptCode()

Get the script code for the script of the current script run.

Returns:int

the script code for the script of the current script run.

See Also
Script
getScriptLimitback to summary
public int getScriptLimit()

Get the index of the first character after the current script run.

Returns:int

the index of the first character after the current script run.

getScriptStartback to summary
public int getScriptStart()

Get the starting index of the current script run.

Returns:int

the index of the first character in the current script run.

highBitback to summary
private static byte highBit(int n)

Find the highest bit that's set in a word. Uses a binary search through the bits.

Parameters
n:int

the word in which to find the highest bit that's set.

Returns:byte

the bit number (counting from the low order bit) of the highest bit.

initback to summary
public void init(char[] chars, int start, int count)
nextback to summary
public boolean next()

Find the next script run. Returns false if there isn't another run, returns true if there is.

Returns:boolean

false if there isn't another run, true if there is.

nextCodePointback to summary
private int nextCodePoint()
pushbackback to summary
private void pushback(int ch)
sameScriptback to summary
private static boolean sameScript(int scriptOne, int scriptTwo)

Compare two script codes to see if they are in the same script. If one script is a strong script, and the other is INHERITED or COMMON, it will compare equal.

Parameters
scriptOne:int

one of the script codes.

scriptTwo:int

the other script code.

Returns:boolean

true if the two scripts are the same.

See Also
Script