Search in sources :

Example 26 with FastStringBuffer

use of org.apache.xml.utils.FastStringBuffer in project robovm by robovm.

the class XStringForFSB method compareToIgnoreCase.

/**
   * Compares two strings lexicographically, ignoring case considerations.
   * This method returns an integer whose sign is that of
   * <code>this.toUpperCase().toLowerCase().compareTo(
   * str.toUpperCase().toLowerCase())</code>.
   * <p>
   * Note that this method does <em>not</em> take locale into account,
   * and will result in an unsatisfactory ordering for certain locales.
   * The java.text package provides <em>collators</em> to allow
   * locale-sensitive ordering.
   *
   * @param   xstr   the <code>String</code> to be compared.
   *
   * @return  a negative integer, zero, or a positive integer as the
   *          the specified String is greater than, equal to, or less
   *          than this String, ignoring case considerations.
   * @see     java.text.Collator#compare(String, String)
   * @since   1.2
   */
public int compareToIgnoreCase(XMLString xstr) {
    int len1 = m_length;
    int len2 = xstr.length();
    int n = Math.min(len1, len2);
    FastStringBuffer fsb = fsb();
    int i = m_start;
    int j = 0;
    while (n-- != 0) {
        char c1 = Character.toLowerCase(fsb.charAt(i));
        char c2 = Character.toLowerCase(xstr.charAt(j));
        if (c1 != c2) {
            return c1 - c2;
        }
        i++;
        j++;
    }
    return len1 - len2;
}
Also used : FastStringBuffer(org.apache.xml.utils.FastStringBuffer)

Example 27 with FastStringBuffer

use of org.apache.xml.utils.FastStringBuffer in project robovm by robovm.

the class XStringForFSB method startsWith.

/**
   * Tests if this string starts with the specified prefix beginning
   * a specified index.
   *
   * @param   prefix    the prefix.
   * @param   toffset   where to begin looking in the string.
   * @return  <code>true</code> if the character sequence represented by the
   *          argument is a prefix of the substring of this object starting
   *          at index <code>toffset</code>; <code>false</code> otherwise.
   *          The result is <code>false</code> if <code>toffset</code> is
   *          negative or greater than the length of this
   *          <code>String</code> object; otherwise the result is the same
   *          as the result of the expression
   *          <pre>
   *          this.subString(toffset).startsWith(prefix)
   *          </pre>
   * @exception java.lang.NullPointerException if <code>prefix</code> is
   *          <code>null</code>.
   */
public boolean startsWith(XMLString prefix, int toffset) {
    FastStringBuffer fsb = fsb();
    int to = m_start + toffset;
    int tlim = m_start + m_length;
    int po = 0;
    int pc = prefix.length();
    // Note: toffset might be near -1>>>1.
    if ((toffset < 0) || (toffset > m_length - pc)) {
        return false;
    }
    while (--pc >= 0) {
        if (fsb.charAt(to) != prefix.charAt(po)) {
            return false;
        }
        to++;
        po++;
    }
    return true;
}
Also used : FastStringBuffer(org.apache.xml.utils.FastStringBuffer)

Example 28 with FastStringBuffer

use of org.apache.xml.utils.FastStringBuffer in project robovm by robovm.

the class XStringForFSB method fixWhiteSpace.

/**
   * Conditionally trim all leading and trailing whitespace in the specified String.
   * All strings of white space are
   * replaced by a single space character (#x20), except spaces after punctuation which
   * receive double spaces if doublePunctuationSpaces is true.
   * This function may be useful to a formatter, but to get first class
   * results, the formatter should probably do it's own white space handling
   * based on the semantics of the formatting object.
   *
   * @param   trimHead    Trim leading whitespace?
   * @param   trimTail    Trim trailing whitespace?
   * @param   doublePunctuationSpaces    Use double spaces for punctuation?
   * @return              The trimmed string.
   */
public XMLString fixWhiteSpace(boolean trimHead, boolean trimTail, boolean doublePunctuationSpaces) {
    int end = m_length + m_start;
    char[] buf = new char[m_length];
    FastStringBuffer fsb = fsb();
    boolean edit = false;
    /* replace S to ' '. and ' '+ -> single ' '. */
    int d = 0;
    boolean pres = false;
    for (int s = m_start; s < end; s++) {
        char c = fsb.charAt(s);
        if (isSpace(c)) {
            if (!pres) {
                if (' ' != c) {
                    edit = true;
                }
                buf[d++] = ' ';
                if (doublePunctuationSpaces && (d != 0)) {
                    char prevChar = buf[d - 1];
                    if (!((prevChar == '.') || (prevChar == '!') || (prevChar == '?'))) {
                        pres = true;
                    }
                } else {
                    pres = true;
                }
            } else {
                edit = true;
                pres = true;
            }
        } else {
            buf[d++] = c;
            pres = false;
        }
    }
    if (trimTail && 1 <= d && ' ' == buf[d - 1]) {
        edit = true;
        d--;
    }
    int start = 0;
    if (trimHead && 0 < d && ' ' == buf[0]) {
        edit = true;
        start++;
    }
    XMLStringFactory xsf = XMLStringFactoryImpl.getFactory();
    return edit ? xsf.newstr(buf, start, d - start) : this;
}
Also used : XMLStringFactory(org.apache.xml.utils.XMLStringFactory) FastStringBuffer(org.apache.xml.utils.FastStringBuffer)

Example 29 with FastStringBuffer

use of org.apache.xml.utils.FastStringBuffer in project robovm by robovm.

the class XStringForFSB method equals.

/**
   * Tell if two objects are functionally equal.
   *
   * @param anotherString Object to compare this to
   *
   * @return true if the two objects are equal
   *
   * @throws javax.xml.transform.TransformerException
   */
public boolean equals(String anotherString) {
    int n = m_length;
    if (n == anotherString.length()) {
        FastStringBuffer fsb = fsb();
        int i = m_start;
        int j = 0;
        while (n-- != 0) {
            if (fsb.charAt(i) != anotherString.charAt(j)) {
                return false;
            }
            i++;
            j++;
        }
        return true;
    }
    return false;
}
Also used : FastStringBuffer(org.apache.xml.utils.FastStringBuffer)

Example 30 with FastStringBuffer

use of org.apache.xml.utils.FastStringBuffer in project robovm by robovm.

the class XStringForFSB method getChars.

/**
   * Copies characters from this string into the destination character
   * array.
   *
   * @param      srcBegin   index of the first character in the string
   *                        to copy.
   * @param      srcEnd     index after the last character in the string
   *                        to copy.
   * @param      dst        the destination array.
   * @param      dstBegin   the start offset in the destination array.
   * @exception IndexOutOfBoundsException If any of the following
   *            is true:
   *            <ul><li><code>srcBegin</code> is negative.
   *            <li><code>srcBegin</code> is greater than <code>srcEnd</code>
   *            <li><code>srcEnd</code> is greater than the length of this
   *                string
   *            <li><code>dstBegin</code> is negative
   *            <li><code>dstBegin+(srcEnd-srcBegin)</code> is larger than
   *                <code>dst.length</code></ul>
   * @exception NullPointerException if <code>dst</code> is <code>null</code>
   */
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) {
    // %OPT% Need to call this on FSB when it is implemented.
    // %UNTESTED% (I don't think anyone calls this yet?)
    int n = srcEnd - srcBegin;
    if (n > m_length)
        n = m_length;
    if (n > (dst.length - dstBegin))
        n = (dst.length - dstBegin);
    int end = srcBegin + m_start + n;
    int d = dstBegin;
    FastStringBuffer fsb = fsb();
    for (int i = srcBegin + m_start; i < end; i++) {
        dst[d++] = fsb.charAt(i);
    }
}
Also used : FastStringBuffer(org.apache.xml.utils.FastStringBuffer)

Aggregations

FastStringBuffer (org.apache.xml.utils.FastStringBuffer)35 Node (org.w3c.dom.Node)9 XMLString (org.apache.xml.utils.XMLString)8 QName (org.apache.xml.utils.QName)4 DecimalFormat (java.text.DecimalFormat)2 Locale (java.util.Locale)2 Vector (java.util.Vector)2 XMLStringFactory (org.apache.xml.utils.XMLStringFactory)2 CharArrayWrapper (org.apache.xml.utils.res.CharArrayWrapper)2 XResourceBundle (org.apache.xml.utils.res.XResourceBundle)2