/** * Compares two strings lexicographically. * * @param xstr the <code>String</code> to be compared. * @return the value <code>0</code> if the argument string is equal to this string; a value less * than <code>0</code> if this string is lexicographically less than the string argument; and * a value greater than <code>0</code> if this string is lexicographically greater than the * string argument. * @exception java.lang.NullPointerException if <code>anotherString</code> is <code>null</code>. */ public int compareTo(XMLString xstr) { int len1 = this.length(); int len2 = xstr.length(); int n = Math.min(len1, len2); int i = 0; int j = 0; while (n-- != 0) { char c1 = this.charAt(i); char c2 = xstr.charAt(j); if (c1 != c2) { return c1 - c2; } i++; j++; } return len1 - len2; }
/** * 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) { int to = toffset; int tlim = this.length(); int po = 0; int pc = prefix.length(); // Note: toffset might be near -1>>>1. if ((toffset < 0) || (toffset > tlim - pc)) { return false; } while (--pc >= 0) { if (this.charAt(to) != prefix.charAt(po)) { return false; } to++; po++; } return true; }
/** * Convert a string to a double -- Allowed input is in fixed notation ddd.fff. * * @return A double value representation of the string, or return Double.NaN if the string can not * be converted. */ public double toDouble() { /* XMLCharacterRecognizer.isWhiteSpace(char c) methods treats the following * characters as white space characters. * ht - horizontal tab, nl - newline , cr - carriage return and sp - space * trim() methods by default also takes care of these white space characters * So trim() method is used to remove leading and trailing white spaces. */ XMLString s = trim(); double result = Double.NaN; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c != '-' && c != '.' && (c < 0X30 || c > 0x39)) { // The character is not a '-' or a '.' or a digit // then return NaN because something is wrong. return result; } } try { result = Double.parseDouble(s.toString()); } catch (NumberFormatException e) { } return result; }