com.simonstl.gorille
Class CharRules

java.lang.Object
  |
  +--com.simonstl.gorille.CharRules
Direct Known Subclasses:
AsciiRules, GeneratedRules, Xml10Rules, Xml11Rules

public class CharRules
extends java.lang.Object

This class stores a set of ranges of characters, allowing XML processors to test against different kinds of ranges.

Version 0.07 fixes the surrogate pairs code so that it returns false if the second code value in a surrogate pair isn't a low surrogate.

Version 0.06 fixes the character-checking so it rejects low surrogates that appear without a prior high surrogate. Thanks to Elliotte Rusty Harold for pointing this out.

Version 0.04 changes from char values to int values in order to support Unicode characters (surrogate pairs) outside of Plane 0. Thanks to Elliotte Rusty Harold for noticing, and John Cowan for suggesting a solution.

for each char in the String
        if in the range 0xD800 to 0xDBFF
                grab the next char as well
                set int[] element to
                (this-0xD800) * 0x400 + (next-0xDC00) + 10000
        else
                set int[] element to value of this char
Version 0.03 adds additional support for namespace-handling. Version 0.02 adds support for pubidChar.

Version:
0.05 10 January 2002
Author:
Simon St.Laurent

Field Summary
protected  CharRanges addlNameChar
           
protected  CharRanges baseChar
           
protected  CharRanges chars
           
protected  CharRanges combiningChar
           
protected  CharRanges digit
           
protected  CharRanges extender
           
protected  CharRanges ideographic
           
protected  boolean namespaceAware
           
protected  CharRanges nameStartChar
           
protected  CharRanges pubidChar
           
protected  CharRanges space
           
 
Constructor Summary
CharRules()
           
 
Method Summary
 boolean getNamespaceAware()
           
 boolean isAddlNameChar(int test)
          Checks characters after the beginning of names against the range of acceptable additional name characters, if there is one.
 boolean isBaseChar(int test)
          Checks characters to see if they are part of the BaseChar range.
 boolean isChar(int test)
          Checks characters against the range of acceptable Char characters.
 boolean isChars(char[] ch, int start, int length)
          Checks a character array from SAX to see if it conforms to the Chars rules.
 boolean isChars(java.lang.String test)
          Checks a String to see if it conforms to the Chars rules.
 boolean isCombiningChar(int test)
          Checks characters to see if they are part of the CombiningChar range.
 boolean isDigit(int test)
          Checks characters to see if they are part of the Digit range.
 boolean isExtender(int test)
          Checks characters to see if they are part of the Extender range.
 boolean isIdeographic(int test)
          Checks characters to see if they are part of the Ideographic range.
 boolean isLetter(int test)
          Checks characters to see if they are part of the Letter range - in XML 1.0, that's the combination of BaseChar and Ideographic.
 boolean isName(java.lang.String test)
          Checks a String to see if it conforms to the Name rules.
 boolean isNameChar(int test)
          Checks characters to see if they are part of the Name range - in XML 1.0, that's the combination of BaseChar, Ideographic, CombiningChar, and Extender.
 boolean isNames(java.lang.String test)
          Checks a String to see if it conforms to the NAMES rules.
 boolean isNameStartChar(int test)
          Checks characters at the beginning of names against the range of acceptable NameStartChar characters, if there is one, and falls back on XML 1.0's Letter rules if there isn't.
 boolean isNMTOKEN(java.lang.String test)
          Checks a String to see if it conforms to the NMTOKEN rules.
 boolean isNMTOKENS(java.lang.String test)
          Checks a String to see if it conforms to the NMTOKENS rules.
 boolean isPubid(java.lang.String test)
          Checks a String to see if it conforms to the Pubid rules.
 boolean isPubidChar(int test)
          Checks characters to see if they are part of the PubidChar range.
 boolean isQName(java.lang.String test)
          Checks a String to see if it conforms to the QName rules.
 boolean isSpace(int test)
          Checks characters to see if they are whitespace.
 void print()
           
 void setAddlNameChar(CharRanges _addlNameChar)
          Sets the range representing the list of additional characters which can be used in names after they start.
 void setBaseChar(CharRanges _baseChar)
          Sets the range representing the BaseChar production from XML 1.0.
 void setChar(CharRanges _chars)
          Sets the list of overall characters for content.
 void setCombiningChar(CharRanges _combiningChar)
          Sets the range representing the CombiningChar production from XML 1.0
 void setDigit(CharRanges _digit)
          Sets the range representing the Digit production from XML 1.0
 void setExtender(CharRanges _extender)
          Sets the range representing the Extender production from XML 1.0
 void setIdeographic(CharRanges _ideographic)
          Sets the range representing the Ideographic production from XML 1.0
 void setNamespaceAware(boolean _namespaceAware)
           
 void setNameStartChar(CharRanges _nameStartChar)
          Sets the range representing the list of characters for use at the beginning of names.
 void setPubidChar(CharRanges _pubidChar)
          Sets the range representing the PubidChar production from XML 1.0
 void setSpace(CharRanges _space)
          Sets the range representing the characters which represent whitespace.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

chars

protected CharRanges chars

nameStartChar

protected CharRanges nameStartChar

addlNameChar

protected CharRanges addlNameChar

space

protected CharRanges space

baseChar

protected CharRanges baseChar

ideographic

protected CharRanges ideographic

combiningChar

protected CharRanges combiningChar

digit

protected CharRanges digit

extender

protected CharRanges extender

pubidChar

protected CharRanges pubidChar

namespaceAware

protected boolean namespaceAware
Constructor Detail

CharRules

public CharRules()
Method Detail

setNamespaceAware

public void setNamespaceAware(boolean _namespaceAware)

getNamespaceAware

public boolean getNamespaceAware()

setChar

public void setChar(CharRanges _chars)
Sets the list of overall characters for content. (The Char production in XML 1.0 and 1.1.)


setNameStartChar

public void setNameStartChar(CharRanges _nameStartChar)
Sets the range representing the list of characters for use at the beginning of names. (The NameStartChar production in XML 1.1.)


setAddlNameChar

public void setAddlNameChar(CharRanges _addlNameChar)
Sets the range representing the list of additional characters which can be used in names after they start. (The NameChar production in XML 1.1, minus the NameStartChar.)


setSpace

public void setSpace(CharRanges _space)
Sets the range representing the characters which represent whitespace. (The S production in XML 1.0 and 1.1.)


setBaseChar

public void setBaseChar(CharRanges _baseChar)
Sets the range representing the BaseChar production from XML 1.0.


setIdeographic

public void setIdeographic(CharRanges _ideographic)
Sets the range representing the Ideographic production from XML 1.0


setCombiningChar

public void setCombiningChar(CharRanges _combiningChar)
Sets the range representing the CombiningChar production from XML 1.0


setDigit

public void setDigit(CharRanges _digit)
Sets the range representing the Digit production from XML 1.0


setExtender

public void setExtender(CharRanges _extender)
Sets the range representing the Extender production from XML 1.0


setPubidChar

public void setPubidChar(CharRanges _pubidChar)
Sets the range representing the PubidChar production from XML 1.0


isChar

public boolean isChar(int test)
Checks characters against the range of acceptable Char characters.


isNameStartChar

public boolean isNameStartChar(int test)
Checks characters at the beginning of names against the range of acceptable NameStartChar characters, if there is one, and falls back on XML 1.0's Letter rules if there isn't.


isAddlNameChar

public boolean isAddlNameChar(int test)
Checks characters after the beginning of names against the range of acceptable additional name characters, if there is one.


isSpace

public boolean isSpace(int test)
Checks characters to see if they are whitespace.


isBaseChar

public boolean isBaseChar(int test)
Checks characters to see if they are part of the BaseChar range.


isIdeographic

public boolean isIdeographic(int test)
Checks characters to see if they are part of the Ideographic range.


isCombiningChar

public boolean isCombiningChar(int test)
Checks characters to see if they are part of the CombiningChar range.


isDigit

public boolean isDigit(int test)
Checks characters to see if they are part of the Digit range.


isExtender

public boolean isExtender(int test)
Checks characters to see if they are part of the Extender range.


isPubidChar

public boolean isPubidChar(int test)
Checks characters to see if they are part of the PubidChar range.


isLetter

public boolean isLetter(int test)
Checks characters to see if they are part of the Letter range - in XML 1.0, that's the combination of BaseChar and Ideographic.


isNameChar

public boolean isNameChar(int test)
Checks characters to see if they are part of the Name range - in XML 1.0, that's the combination of BaseChar, Ideographic, CombiningChar, and Extender. In XML 1.1, that's NameStartChar and the additional name characters.


isChars

public boolean isChars(java.lang.String test)
Checks a String to see if it conforms to the Chars rules. Works using either XML 1.0 or 1.1, depending on the rules file used to set the ranges.


isChars

public boolean isChars(char[] ch,
                       int start,
                       int length)
Checks a character array from SAX to see if it conforms to the Chars rules. Works using either XML 1.0 or 1.1, depending on the rules file used to set the ranges.


isName

public boolean isName(java.lang.String test)
Checks a String to see if it conforms to the Name rules. Works using either XML 1.0 or 1.1, depending on the rules file used to set the ranges.


isQName

public boolean isQName(java.lang.String test)
Checks a String to see if it conforms to the QName rules. Works using either XML 1.0 or 1.1, depending on the rules file used to set the ranges.


isNMTOKEN

public boolean isNMTOKEN(java.lang.String test)
Checks a String to see if it conforms to the NMTOKEN rules. Works using either XML 1.0 or 1.1, depending on the rules file used to set the ranges.


isNMTOKENS

public boolean isNMTOKENS(java.lang.String test)
Checks a String to see if it conforms to the NMTOKENS rules. Works using either XML 1.0 or 1.1, depending on the rules file used to set the ranges.


isNames

public boolean isNames(java.lang.String test)
Checks a String to see if it conforms to the NAMES rules. Works using either XML 1.0 or 1.1, depending on the rules file used to set the ranges.


isPubid

public boolean isPubid(java.lang.String test)
Checks a String to see if it conforms to the Pubid rules. XML 1.1 didn't make any changes to the Pubid rules.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

print

public void print()