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