org.crosswire.common.icu
Class NumberShaper

java.lang.Object
  extended by org.crosswire.common.icu.NumberShaper
All Implemented Interfaces:
Serializable

public class NumberShaper
extends Object
implements Serializable

NumberShaper changes numbers from one number system to another. That is, the numbers 0-9 have different representations in some locales. This means that they have different code points. For example, Eastern Arabic numbers are from ۰ - ۹.

Internally, numbers will be represented with 0-9, but externally they should show as a user wishes. Further user input may, optionally, use the external form.

This shaper has special behavior for Arabic numbers that are in the form "12:34" as this is taken as chapter:verse. Normally, a ':' is treated as a numeric separator, this results in "12:34", but for verses it should be "34:12". That is, Arabic, numbers are left-to-right (even though the rest of the language is right-to-left) and the ':' as a numeric separator does not change that. So to get around this we mark the ':' as a right-to-left character.

Author:
DM Smith [dmsmith555 at yahoo dot com]
See Also:
NumericShaper, com.ibm.icu.text.ArabicShaping, for license details.
The copyright to this program is held by it's authors.
, Serialized Form

Field Summary
private  Locale locale
          The locale for this shaper.
private  char nineShape
          Nine for this shaper.
private static long serialVersionUID
          Serialization ID
 
Constructor Summary
NumberShaper()
          Create a shaper that is appropriate for the user's locale.
NumberShaper(Locale locale)
          Create a shaper that is appropriate for the given locale.
 
Method Summary
 boolean canShape()
          Determine whether shaping is possible.
 boolean canUnshape()
          Determine whether shaping back to 0-9 is possible.
private  char getNine()
          Establish nine for the language.
 String shape(String input)
          Replace 0-9 in the input with representations appropriate for the script.
private  char[] shaped(char[] src, boolean[] transformed)
           
private  char[] transform(char[] src, int zero, int nine, int offset, boolean[] transformed)
          Transform either to or from 0-9 and the script representation, returning the result and true when at least one character is transformed.
 String unshape(String input)
          Replace script representations of numbers with 0-9.
private  char[] unshaped(char[] src, boolean[] transformed)
          Perform shaping back to 0-9.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

locale

private Locale locale
The locale for this shaper.


nineShape

private char nineShape
Nine for this shaper.


serialVersionUID

private static final long serialVersionUID
Serialization ID

See Also:
Constant Field Values
Constructor Detail

NumberShaper

public NumberShaper()
Create a shaper that is appropriate for the user's locale.


NumberShaper

public NumberShaper(Locale locale)
Create a shaper that is appropriate for the given locale.

Parameters:
locale - the requested Locale
Method Detail

canShape

public boolean canShape()
Determine whether shaping is possible.

Returns:
whether shaping back to 0-9 is possible.

shape

public String shape(String input)
Replace 0-9 in the input with representations appropriate for the script.

Parameters:
input - the text to be transformed
Returns:
the transformed text

canUnshape

public boolean canUnshape()
Determine whether shaping back to 0-9 is possible.

Returns:
whether shaping back to 0-9 is possible.

unshape

public String unshape(String input)
Replace script representations of numbers with 0-9.

Parameters:
input - the text to be transformed
Returns:
the transformed text

unshaped

private char[] unshaped(char[] src,
                        boolean[] transformed)
Perform shaping back to 0-9.


shaped

private char[] shaped(char[] src,
                      boolean[] transformed)
Parameters:
src -
transformed -
Returns:
the shaped string

transform

private char[] transform(char[] src,
                         int zero,
                         int nine,
                         int offset,
                         boolean[] transformed)
Transform either to or from 0-9 and the script representation, returning the result and true when at least one character is transformed.

Parameters:
src - the text to transform
zero - zero in the source representation
nine - nine in the source representation
offset - the distance between zeros in the source and target representation
transformed - an input parameter of one boolean that can hold whether there was a transformation
Returns:
the shaped string

getNine

private char getNine()
Establish nine for the language. There are languages that don't have zeroes.

Returns:
the representation for 9 in the language

Copyright ¨ 2003-2007