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 script 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.

See also: com.ibm.icu.text.ArabicShaping

Author:
DM Smith
See Also:
NumericShaper, The GNU Lesser General Public License for details., Serialized Form

Field Summary
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.
 
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 script.
 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

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.

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.

Parameters:
src - the text to transform
transformed - an input parameter of one boolean that can hold whether there was a transformation
Returns:
the unshaped text

shaped

private char[] shaped(char[] src,
                      boolean[] transformed)
Parameters:
src - the text to transform
transformed - an input parameter of one boolean that can hold whether there was a transformation
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 script. There are scripts that don't have zeroes.

Returns:
the representation for 9 in the script

Copyright ¨ 2003-2015