FileDocCategorySizeDatePackage
XMLString.javaAPI DocApache Xerces 3.0.16138Fri Sep 14 20:33:56 BST 2007org.apache.xerces.xni

XMLString

public class XMLString extends Object
This class is used as a structure to pass text contained in the underlying character buffer of the scanner. The offset and length fields allow the buffer to be re-used without creating new character arrays.

Note: Methods that are passed an XMLString structure should consider the contents read-only and not make any modifications to the contents of the buffer. The method receiving this structure should also not modify the offset and length if this structure (or the values of this structure) are passed to another method.

Note: Methods that are passed an XMLString structure are required to copy the information out of the buffer if it is to be saved for use beyond the scope of the method. The contents of the structure are volatile and the contents of the character buffer cannot be assured once the method that is passed this structure returns. Therefore, methods passed this structure should not save any reference to the structure or the character array contained in the structure.

author
Eric Ye, IBM
author
Andy Clark, IBM
version
$Id: XMLString.java 447247 2006-09-18 05:23:52Z mrglavas $

Fields Summary
public char[]
ch
The character array.
public int
offset
The offset into the character array.
public int
length
The length of characters from the offset.
Constructors Summary
public XMLString()
Default constructor.

    
public XMLString(char[] ch, int offset, int length)
Constructs an XMLString structure preset with the specified values.

param
ch The character array.
param
offset The offset into the character array.
param
length The length of characters from the offset.

        setValues(ch, offset, length);
    
public XMLString(XMLString string)
Constructs an XMLString structure with copies of the values in the given structure.

Note: This does not copy the character array; only the reference to the array is copied.

param
string The XMLString to copy.

        setValues(string);
    
Methods Summary
public voidclear()
Resets all of the values to their defaults.

        this.ch = null;
        this.offset = 0;
        this.length = -1;
    
public booleanequals(char[] ch, int offset, int length)
Returns true if the contents of this XMLString structure and the specified array are equal.

param
ch The character array.
param
offset The offset into the character array.
param
length The length of characters from the offset.

        if (ch == null) {
            return false;
        }
        if (this.length != length) {
            return false;
        }

        for (int i=0; i<length; i++) {
            if (this.ch[this.offset+i] != ch[offset+i] ) {
                return false;
            }
        }
        return true;
    
public booleanequals(java.lang.String s)
Returns true if the contents of this XMLString structure and the specified string are equal.

param
s The string to compare.

        if (s == null) {
            return false;
        }
        if ( length != s.length() ) {
            return false;
        }

        // is this faster than call s.toCharArray first and compare the 
        // two arrays directly, which will possibly involve creating a
        // new char array object.
        for (int i=0; i<length; i++) {
            if (ch[offset+i] != s.charAt(i)) {
                return false;
            }
        }

        return true;
    
public voidsetValues(char[] ch, int offset, int length)
Initializes the contents of the XMLString structure with the specified values.

param
ch The character array.
param
offset The offset into the character array.
param
length The length of characters from the offset.

        this.ch = ch;
        this.offset = offset;
        this.length = length;
    
public voidsetValues(org.apache.xerces.xni.XMLString s)
Initializes the contents of the XMLString structure with copies of the given string structure.

Note: This does not copy the character array; only the reference to the array is copied.

param
s

        setValues(s.ch, s.offset, s.length);
    
public java.lang.StringtoString()
Returns a string representation of this object.

        return length > 0 ? new String(ch, offset, length) : "";