1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*
  17. * $Id: XMLString.java,v 1.4 2004/02/17 04:21:14 minchau Exp $
  18. */
  19. package com.sun.org.apache.xml.internal.utils;
  20. import java.util.Locale;
  21. /**
  22. * This class is meant to be an interface to character strings, whether they
  23. * be java Strings or <code>com.sun.org.apache.xml.internal.utils.FastStringBuffer</code>s, or
  24. * other character data. By using XMLString, character copies can be reduced
  25. * in the XML pipeline.
  26. */
  27. public interface XMLString
  28. {
  29. /**
  30. * Directly call the
  31. * characters method on the passed ContentHandler for the
  32. * string-value. Multiple calls to the
  33. * ContentHandler's characters methods may well occur for a single call to
  34. * this method.
  35. *
  36. * @param ch A non-null reference to a ContentHandler.
  37. *
  38. * @throws org.xml.sax.SAXException
  39. */
  40. public abstract void dispatchCharactersEvents(org.xml.sax.ContentHandler ch)
  41. throws org.xml.sax.SAXException;
  42. /**
  43. * Directly call the
  44. * comment method on the passed LexicalHandler for the
  45. * string-value.
  46. *
  47. * @param lh A non-null reference to a LexicalHandler.
  48. *
  49. * @throws org.xml.sax.SAXException
  50. */
  51. public abstract void dispatchAsComment(org.xml.sax.ext.LexicalHandler lh)
  52. throws org.xml.sax.SAXException;
  53. /**
  54. * Conditionally trim all leading and trailing whitespace in the specified String.
  55. * All strings of white space are
  56. * replaced by a single space character (#x20), except spaces after punctuation which
  57. * receive double spaces if doublePunctuationSpaces is true.
  58. * This function may be useful to a formatter, but to get first class
  59. * results, the formatter should probably do it's own white space handling
  60. * based on the semantics of the formatting object.
  61. *
  62. * @param trimHead Trim leading whitespace?
  63. * @param trimTail Trim trailing whitespace?
  64. * @param doublePunctuationSpaces Use double spaces for punctuation?
  65. * @return The trimmed string.
  66. */
  67. public XMLString fixWhiteSpace(boolean trimHead,
  68. boolean trimTail,
  69. boolean doublePunctuationSpaces);
  70. /**
  71. * Returns the length of this string.
  72. *
  73. * @return the length of the sequence of characters represented by this
  74. * object.
  75. */
  76. public abstract int length();
  77. /**
  78. * Returns the character at the specified index. An index ranges
  79. * from <code>0</code> to <code>length() - 1</code>. The first character
  80. * of the sequence is at index <code>0</code>, the next at index
  81. * <code>1</code>, and so on, as for array indexing.
  82. *
  83. * @param index the index of the character.
  84. * @return the character at the specified index of this string.
  85. * The first character is at index <code>0</code>.
  86. * @exception IndexOutOfBoundsException if the <code>index</code>
  87. * argument is negative or not less than the length of this
  88. * string.
  89. */
  90. public abstract char charAt(int index);
  91. /**
  92. * Copies characters from this string into the destination character
  93. * array.
  94. *
  95. * @param srcBegin index of the first character in the string
  96. * to copy.
  97. * @param srcEnd index after the last character in the string
  98. * to copy.
  99. * @param dst the destination array.
  100. * @param dstBegin the start offset in the destination array.
  101. * @exception IndexOutOfBoundsException If any of the following
  102. * is true:
  103. * <ul><li><code>srcBegin</code> is negative.
  104. * <li><code>srcBegin</code> is greater than <code>srcEnd</code>
  105. * <li><code>srcEnd</code> is greater than the length of this
  106. * string
  107. * <li><code>dstBegin</code> is negative
  108. * <li><code>dstBegin+(srcEnd-srcBegin)</code> is larger than
  109. * <code>dst.length</code></ul>
  110. * @exception NullPointerException if <code>dst</code> is <code>null</code>
  111. */
  112. public abstract void getChars(int srcBegin, int srcEnd, char dst[],
  113. int dstBegin);
  114. /**
  115. * Compares this string to the specified object.
  116. * The result is <code>true</code> if and only if the argument is not
  117. * <code>null</code> and is a <code>String</code> object that represents
  118. * the same sequence of characters as this object.
  119. *
  120. * @param anObject the object to compare this <code>String</code>
  121. * against.
  122. * @return <code>true</code> if the <code>String </code>are equal;
  123. * <code>false</code> otherwise.
  124. * @see java.lang.String#compareTo(java.lang.String)
  125. * @see java.lang.String#equalsIgnoreCase(java.lang.String)
  126. */
  127. public abstract boolean equals(XMLString anObject);
  128. /**
  129. * Compares this string to the specified object.
  130. * The result is <code>true</code> if and only if the argument is not
  131. * <code>null</code> and is a <code>String</code> object that represents
  132. * the same sequence of characters as this object.
  133. *
  134. * @param anObject the object to compare this <code>String</code>
  135. * against.
  136. * @return <code>true</code> if the <code>String </code>are equal;
  137. * <code>false</code> otherwise.
  138. * @see java.lang.String#compareTo(java.lang.String)
  139. * @see java.lang.String#equalsIgnoreCase(java.lang.String)
  140. */
  141. public abstract boolean equals(Object anObject);
  142. /**
  143. * Compares this <code>String</code> to another <code>String</code>,
  144. * ignoring case considerations. Two strings are considered equal
  145. * ignoring case if they are of the same length, and corresponding
  146. * characters in the two strings are equal ignoring case.
  147. *
  148. * @param anotherString the <code>String</code> to compare this
  149. * <code>String</code> against.
  150. * @return <code>true</code> if the argument is not <code>null</code>
  151. * and the <code>String</code>s are equal,
  152. * ignoring case; <code>false</code> otherwise.
  153. * @see #equals(Object)
  154. * @see java.lang.Character#toLowerCase(char)
  155. * @see java.lang.Character#toUpperCase(char)
  156. */
  157. public abstract boolean equalsIgnoreCase(String anotherString);
  158. /**
  159. * Compares two strings lexicographically.
  160. *
  161. * @param anotherString the <code>String</code> to be compared.
  162. * @return the value <code>0</code> if the argument string is equal to
  163. * this string; a value less than <code>0</code> if this string
  164. * is lexicographically less than the string argument; and a
  165. * value greater than <code>0</code> if this string is
  166. * lexicographically greater than the string argument.
  167. * @exception java.lang.NullPointerException if <code>anotherString</code>
  168. * is <code>null</code>.
  169. */
  170. public abstract int compareTo(XMLString anotherString);
  171. /**
  172. * Compares two strings lexicographically, ignoring case considerations.
  173. * This method returns an integer whose sign is that of
  174. * <code>this.toUpperCase().toLowerCase().compareTo(
  175. * str.toUpperCase().toLowerCase())</code>.
  176. * <p>
  177. * Note that this method does <em>not</em> take locale into account,
  178. * and will result in an unsatisfactory ordering for certain locales.
  179. * The java.text package provides <em>collators</em> to allow
  180. * locale-sensitive ordering.
  181. *
  182. * @param str the <code>String</code> to be compared.
  183. * @return a negative integer, zero, or a positive integer as the
  184. * the specified String is greater than, equal to, or less
  185. * than this String, ignoring case considerations.
  186. * @see java.text.Collator#compare(String, String)
  187. * @since 1.2
  188. */
  189. public abstract int compareToIgnoreCase(XMLString str);
  190. /**
  191. * Tests if this string starts with the specified prefix beginning
  192. * a specified index.
  193. *
  194. * @param prefix the prefix.
  195. * @param toffset where to begin looking in the string.
  196. * @return <code>true</code> if the character sequence represented by the
  197. * argument is a prefix of the substring of this object starting
  198. * at index <code>toffset</code> <code>false</code> otherwise.
  199. * The result is <code>false</code> if <code>toffset</code> is
  200. * negative or greater than the length of this
  201. * <code>String</code> object; otherwise the result is the same
  202. * as the result of the expression
  203. * <pre>
  204. * this.subString(toffset).startsWith(prefix)
  205. * </pre>
  206. * @exception java.lang.NullPointerException if <code>prefix</code> is
  207. * <code>null</code>.
  208. */
  209. public abstract boolean startsWith(String prefix, int toffset);
  210. /**
  211. * Tests if this string starts with the specified prefix beginning
  212. * a specified index.
  213. *
  214. * @param prefix the prefix.
  215. * @param toffset where to begin looking in the string.
  216. * @return <code>true</code> if the character sequence represented by the
  217. * argument is a prefix of the substring of this object starting
  218. * at index <code>toffset</code> <code>false</code> otherwise.
  219. * The result is <code>false</code> if <code>toffset</code> is
  220. * negative or greater than the length of this
  221. * <code>String</code> object; otherwise the result is the same
  222. * as the result of the expression
  223. * <pre>
  224. * this.subString(toffset).startsWith(prefix)
  225. * </pre>
  226. * @exception java.lang.NullPointerException if <code>prefix</code> is
  227. * <code>null</code>.
  228. */
  229. public abstract boolean startsWith(XMLString prefix, int toffset);
  230. /**
  231. * Tests if this string starts with the specified prefix.
  232. *
  233. * @param prefix the prefix.
  234. * @return <code>true</code> if the character sequence represented by the
  235. * argument is a prefix of the character sequence represented by
  236. * this string; <code>false</code> otherwise.
  237. * Note also that <code>true</code> will be returned if the
  238. * argument is an empty string or is equal to this
  239. * <code>String</code> object as determined by the
  240. * {@link #equals(Object)} method.
  241. * @exception java.lang.NullPointerException if <code>prefix</code> is
  242. * <code>null</code>.
  243. * @since JDK1. 0
  244. */
  245. public abstract boolean startsWith(String prefix);
  246. /**
  247. * Tests if this string starts with the specified prefix.
  248. *
  249. * @param prefix the prefix.
  250. * @return <code>true</code> if the character sequence represented by the
  251. * argument is a prefix of the character sequence represented by
  252. * this string; <code>false</code> otherwise.
  253. * Note also that <code>true</code> will be returned if the
  254. * argument is an empty string or is equal to this
  255. * <code>String</code> object as determined by the
  256. * {@link #equals(Object)} method.
  257. * @exception java.lang.NullPointerException if <code>prefix</code> is
  258. * <code>null</code>.
  259. * @since JDK1. 0
  260. */
  261. public abstract boolean startsWith(XMLString prefix);
  262. /**
  263. * Tests if this string ends with the specified suffix.
  264. *
  265. * @param suffix the suffix.
  266. * @return <code>true</code> if the character sequence represented by the
  267. * argument is a suffix of the character sequence represented by
  268. * this object; <code>false</code> otherwise. Note that the
  269. * result will be <code>true</code> if the argument is the
  270. * empty string or is equal to this <code>String</code> object
  271. * as determined by the {@link #equals(Object)} method.
  272. * @exception java.lang.NullPointerException if <code>suffix</code> is
  273. * <code>null</code>.
  274. */
  275. public abstract boolean endsWith(String suffix);
  276. /**
  277. * Returns a hashcode for this string. The hashcode for a
  278. * <code>String</code> object is computed as
  279. * <blockquote><pre>
  280. * s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
  281. * </pre></blockquote>
  282. * using <code>int</code> arithmetic, where <code>s[i]</code> is the
  283. * <i>i</i>th character of the string, <code>n</code> is the length of
  284. * the string, and <code>^</code> indicates exponentiation.
  285. * (The hash value of the empty string is zero.)
  286. *
  287. * @return a hash code value for this object.
  288. */
  289. public abstract int hashCode();
  290. /**
  291. * Returns the index within this string of the first occurrence of the
  292. * specified character. If a character with value <code>ch</code> occurs
  293. * in the character sequence represented by this <code>String</code>
  294. * object, then the index of the first such occurrence is returned --
  295. * that is, the smallest value <i>k</i> such that:
  296. * <blockquote><pre>
  297. * this.charAt(<i>k</i>) == ch
  298. * </pre></blockquote>
  299. * is <code>true</code>. If no such character occurs in this string,
  300. * then <code>-1</code> is returned.
  301. *
  302. * @param ch a character.
  303. * @return the index of the first occurrence of the character in the
  304. * character sequence represented by this object, or
  305. * <code>-1</code> if the character does not occur.
  306. */
  307. public abstract int indexOf(int ch);
  308. /**
  309. * Returns the index within this string of the first occurrence of the
  310. * specified character, starting the search at the specified index.
  311. * <p>
  312. * If a character with value <code>ch</code> occurs in the character
  313. * sequence represented by this <code>String</code> object at an index
  314. * no smaller than <code>fromIndex</code>, then the index of the first
  315. * such occurrence is returned--that is, the smallest value <i>k</i>
  316. * such that:
  317. * <blockquote><pre>
  318. * (this.charAt(<i>k</i>) == ch) && (<i>k</i> >= fromIndex)
  319. * </pre></blockquote>
  320. * is true. If no such character occurs in this string at or after
  321. * position <code>fromIndex</code>, then <code>-1</code> is returned.
  322. * <p>
  323. * There is no restriction on the value of <code>fromIndex</code>. If it
  324. * is negative, it has the same effect as if it were zero: this entire
  325. * string may be searched. If it is greater than the length of this
  326. * string, it has the same effect as if it were equal to the length of
  327. * this string: <code>-1</code> is returned.
  328. *
  329. * @param ch a character.
  330. * @param fromIndex the index to start the search from.
  331. * @return the index of the first occurrence of the character in the
  332. * character sequence represented by this object that is greater
  333. * than or equal to <code>fromIndex</code>, or <code>-1</code>
  334. * if the character does not occur.
  335. */
  336. public abstract int indexOf(int ch, int fromIndex);
  337. /**
  338. * Returns the index within this string of the last occurrence of the
  339. * specified character. That is, the index returned is the largest
  340. * value <i>k</i> such that:
  341. * <blockquote><pre>
  342. * this.charAt(<i>k</i>) == ch
  343. * </pre></blockquote>
  344. * is true.
  345. * The String is searched backwards starting at the last character.
  346. *
  347. * @param ch a character.
  348. * @return the index of the last occurrence of the character in the
  349. * character sequence represented by this object, or
  350. * <code>-1</code> if the character does not occur.
  351. */
  352. public abstract int lastIndexOf(int ch);
  353. /**
  354. * Returns the index within this string of the last occurrence of the
  355. * specified character, searching backward starting at the specified
  356. * index. That is, the index returned is the largest value <i>k</i>
  357. * such that:
  358. * <blockquote><pre>
  359. * this.charAt(k) == ch) && (k <= fromIndex)
  360. * </pre></blockquote>
  361. * is true.
  362. *
  363. * @param ch a character.
  364. * @param fromIndex the index to start the search from. There is no
  365. * restriction on the value of <code>fromIndex</code>. If it is
  366. * greater than or equal to the length of this string, it has
  367. * the same effect as if it were equal to one less than the
  368. * length of this string: this entire string may be searched.
  369. * If it is negative, it has the same effect as if it were -1:
  370. * -1 is returned.
  371. * @return the index of the last occurrence of the character in the
  372. * character sequence represented by this object that is less
  373. * than or equal to <code>fromIndex</code>, or <code>-1</code>
  374. * if the character does not occur before that point.
  375. */
  376. public abstract int lastIndexOf(int ch, int fromIndex);
  377. /**
  378. * Returns the index within this string of the first occurrence of the
  379. * specified substring. The integer returned is the smallest value
  380. * <i>k</i> such that:
  381. * <blockquote><pre>
  382. * this.startsWith(str, <i>k</i>)
  383. * </pre></blockquote>
  384. * is <code>true</code>.
  385. *
  386. * @param str any string.
  387. * @return if the string argument occurs as a substring within this
  388. * object, then the index of the first character of the first
  389. * such substring is returned; if it does not occur as a
  390. * substring, <code>-1</code> is returned.
  391. * @exception java.lang.NullPointerException if <code>str</code> is
  392. * <code>null</code>.
  393. */
  394. public abstract int indexOf(String str);
  395. /**
  396. * Returns the index within this string of the first occurrence of the
  397. * specified substring. The integer returned is the smallest value
  398. * <i>k</i> such that:
  399. * <blockquote><pre>
  400. * this.startsWith(str, <i>k</i>)
  401. * </pre></blockquote>
  402. * is <code>true</code>.
  403. *
  404. * @param str any string.
  405. * @return if the string argument occurs as a substring within this
  406. * object, then the index of the first character of the first
  407. * such substring is returned; if it does not occur as a
  408. * substring, <code>-1</code> is returned.
  409. * @exception java.lang.NullPointerException if <code>str</code> is
  410. * <code>null</code>.
  411. */
  412. public abstract int indexOf(XMLString str);
  413. /**
  414. * Returns the index within this string of the first occurrence of the
  415. * specified substring, starting at the specified index. The integer
  416. * returned is the smallest value <i>k</i> such that:
  417. * <blockquote><pre>
  418. * this.startsWith(str, <i>k</i>) && (<i>k</i> >= fromIndex)
  419. * </pre></blockquote>
  420. * is <code>true</code>.
  421. * <p>
  422. * There is no restriction on the value of <code>fromIndex</code>. If
  423. * it is negative, it has the same effect as if it were zero: this entire
  424. * string may be searched. If it is greater than the length of this
  425. * string, it has the same effect as if it were equal to the length of
  426. * this string: <code>-1</code> is returned.
  427. *
  428. * @param str the substring to search for.
  429. * @param fromIndex the index to start the search from.
  430. * @return If the string argument occurs as a substring within this
  431. * object at a starting index no smaller than
  432. * <code>fromIndex</code>, then the index of the first character
  433. * of the first such substring is returned. If it does not occur
  434. * as a substring starting at <code>fromIndex</code> or beyond,
  435. * <code>-1</code> is returned.
  436. * @exception java.lang.NullPointerException if <code>str</code> is
  437. * <code>null</code>
  438. */
  439. public abstract int indexOf(String str, int fromIndex);
  440. /**
  441. * Returns the index within this string of the rightmost occurrence
  442. * of the specified substring. The rightmost empty string "" is
  443. * considered to occur at the index value <code>this.length()</code>.
  444. * The returned index is the largest value <i>k</i> such that
  445. * <blockquote><pre>
  446. * this.startsWith(str, k)
  447. * </pre></blockquote>
  448. * is true.
  449. *
  450. * @param str the substring to search for.
  451. * @return if the string argument occurs one or more times as a substring
  452. * within this object, then the index of the first character of
  453. * the last such substring is returned. If it does not occur as
  454. * a substring, <code>-1</code> is returned.
  455. * @exception java.lang.NullPointerException if <code>str</code> is
  456. * <code>null</code>.
  457. */
  458. public abstract int lastIndexOf(String str);
  459. /**
  460. * Returns the index within this string of the last occurrence of
  461. * the specified substring.
  462. *
  463. * @param str the substring to search for.
  464. * @param fromIndex the index to start the search from. There is no
  465. * restriction on the value of fromIndex. If it is greater than
  466. * the length of this string, it has the same effect as if it
  467. * were equal to the length of this string: this entire string
  468. * may be searched. If it is negative, it has the same effect
  469. * as if it were -1: -1 is returned.
  470. * @return If the string argument occurs one or more times as a substring
  471. * within this object at a starting index no greater than
  472. * <code>fromIndex</code>, then the index of the first character of
  473. * the last such substring is returned. If it does not occur as a
  474. * substring starting at <code>fromIndex</code> or earlier,
  475. * <code>-1</code> is returned.
  476. * @exception java.lang.NullPointerException if <code>str</code> is
  477. * <code>null</code>.
  478. */
  479. public abstract int lastIndexOf(String str, int fromIndex);
  480. /**
  481. * Returns a new string that is a substring of this string. The
  482. * substring begins with the character at the specified index and
  483. * extends to the end of this string. <p>
  484. * Examples:
  485. * <blockquote><pre>
  486. * "unhappy".substring(2) returns "happy"
  487. * "Harbison".substring(3) returns "bison"
  488. * "emptiness".substring(9) returns "" (an empty string)
  489. * </pre></blockquote>
  490. *
  491. * @param beginIndex the beginning index, inclusive.
  492. * @return the specified substring.
  493. * @exception IndexOutOfBoundsException if
  494. * <code>beginIndex</code> is negative or larger than the
  495. * length of this <code>String</code> object.
  496. */
  497. public abstract XMLString substring(int beginIndex);
  498. /**
  499. * Returns a new string that is a substring of this string. The
  500. * substring begins at the specified <code>beginIndex</code> and
  501. * extends to the character at index <code>endIndex - 1</code>.
  502. * Thus the length of the substring is <code>endIndex-beginIndex</code>.
  503. *
  504. * @param beginIndex the beginning index, inclusive.
  505. * @param endIndex the ending index, exclusive.
  506. * @return the specified substring.
  507. * @exception IndexOutOfBoundsException if the
  508. * <code>beginIndex</code> is negative, or
  509. * <code>endIndex</code> is larger than the length of
  510. * this <code>String</code> object, or
  511. * <code>beginIndex</code> is larger than
  512. * <code>endIndex</code>.
  513. */
  514. public abstract XMLString substring(int beginIndex, int endIndex);
  515. /**
  516. * Concatenates the specified string to the end of this string.
  517. *
  518. * @param str the <code>String</code> that is concatenated to the end
  519. * of this <code>String</code>.
  520. * @return a string that represents the concatenation of this object's
  521. * characters followed by the string argument's characters.
  522. * @exception java.lang.NullPointerException if <code>str</code> is
  523. * <code>null</code>.
  524. */
  525. public abstract XMLString concat(String str);
  526. /**
  527. * Converts all of the characters in this <code>String</code> to lower
  528. * case using the rules of the given <code>Locale</code>.
  529. *
  530. * @param locale use the case transformation rules for this locale
  531. * @return the String, converted to lowercase.
  532. * @see java.lang.Character#toLowerCase(char)
  533. * @see java.lang.String#toUpperCase(Locale)
  534. */
  535. public abstract XMLString toLowerCase(Locale locale);
  536. /**
  537. * Converts all of the characters in this <code>String</code> to lower
  538. * case using the rules of the default locale, which is returned
  539. * by <code>Locale.getDefault</code>.
  540. * <p>
  541. *
  542. * @return the string, converted to lowercase.
  543. * @see java.lang.Character#toLowerCase(char)
  544. * @see java.lang.String#toLowerCase(Locale)
  545. */
  546. public abstract XMLString toLowerCase();
  547. /**
  548. * Converts all of the characters in this <code>String</code> to upper
  549. * case using the rules of the given locale.
  550. * @param locale use the case transformation rules for this locale
  551. * @return the String, converted to uppercase.
  552. * @see java.lang.Character#toUpperCase(char)
  553. * @see java.lang.String#toLowerCase(Locale)
  554. */
  555. public abstract XMLString toUpperCase(Locale locale);
  556. /**
  557. * Converts all of the characters in this <code>String</code> to upper
  558. * case using the rules of the default locale, which is returned
  559. * by <code>Locale.getDefault</code>.
  560. *
  561. * <p>
  562. * If no character in this string has a different uppercase version,
  563. * based on calling the <code>toUpperCase</code> method defined by
  564. * <code>Character</code>, then the original string is returned.
  565. * <p>
  566. * Otherwise, this method creates a new <code>String</code> object
  567. * representing a character sequence identical in length to the
  568. * character sequence represented by this <code>String</code> object and
  569. * with every character equal to the result of applying the method
  570. * <code>Character.toUpperCase</code> to the corresponding character of
  571. * this <code>String</code> object. <p>
  572. * Examples:
  573. * <blockquote><pre>
  574. * "Fahrvergngen".toUpperCase() returns "FAHRVERGNGEN"
  575. * "Visit Ljubinje!".toUpperCase() returns "VISIT LJUBINJE!"
  576. * </pre></blockquote>
  577. *
  578. * @return the string, converted to uppercase.
  579. * @see java.lang.Character#toUpperCase(char)
  580. * @see java.lang.String#toUpperCase(Locale)
  581. */
  582. public abstract XMLString toUpperCase();
  583. /**
  584. * Removes white space from both ends of this string.
  585. * <p>
  586. * If this <code>String</code> object represents an empty character
  587. * sequence, or the first and last characters of character sequence
  588. * represented by this <code>String</code> object both have codes
  589. * greater than <code>'\u0020'</code> (the space character), then a
  590. * reference to this <code>String</code> object is returned.
  591. * <p>
  592. * Otherwise, if there is no character with a code greater than
  593. * <code>'\u0020'</code> in the string, then a new
  594. * <code>String</code> object representing an empty string is created
  595. * and returned.
  596. * <p>
  597. * Otherwise, let <i>k</i> be the index of the first character in the
  598. * string whose code is greater than <code>'\u0020'</code>, and let
  599. * <i>m</i> be the index of the last character in the string whose code
  600. * is greater than <code>'\u0020'</code>. A new <code>String</code>
  601. * object is created, representing the substring of this string that
  602. * begins with the character at index <i>k</i> and ends with the
  603. * character at index <i>m</i>-that is, the result of
  604. * <code>this.substring(<i>k</i>, <i>m</i>+1)</code>.
  605. * <p>
  606. * This method may be used to trim
  607. * {@link Character#isSpace(char) whitespace} from the beginning and end
  608. * of a string; in fact, it trims all ASCII control characters as well.
  609. *
  610. * @return this string, with white space removed from the front and end.
  611. */
  612. public abstract XMLString trim();
  613. /**
  614. * This object (which is already a string!) is itself returned.
  615. *
  616. * @return the string itself.
  617. */
  618. public abstract String toString();
  619. /**
  620. * Tell if this object contains a java String object.
  621. *
  622. * @return true if this XMLString can return a string without creating one.
  623. */
  624. public abstract boolean hasString();
  625. /**
  626. * Convert a string to a double -- Allowed input is in fixed
  627. * notation ddd.fff.
  628. *
  629. * @return A double value representation of the string, or return Double.NaN
  630. * if the string can not be converted.
  631. */
  632. public double toDouble();
  633. }