6
|
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: XString.java,v 1.2.4.1 2005/09/14 20:47:20 jeffsuttor Exp $
|
|
22 |
*/
|
|
23 |
package com.sun.org.apache.xpath.internal.objects;
|
|
24 |
|
|
25 |
import java.util.Locale;
|
|
26 |
|
|
27 |
import com.sun.org.apache.xml.internal.dtm.DTM;
|
|
28 |
import com.sun.org.apache.xml.internal.utils.XMLCharacterRecognizer;
|
|
29 |
import com.sun.org.apache.xml.internal.utils.XMLString;
|
|
30 |
import com.sun.org.apache.xml.internal.utils.XMLStringFactory;
|
|
31 |
import com.sun.org.apache.xpath.internal.ExpressionOwner;
|
|
32 |
import com.sun.org.apache.xpath.internal.XPathContext;
|
|
33 |
import com.sun.org.apache.xpath.internal.XPathVisitor;
|
|
34 |
|
|
35 |
/**
|
|
36 |
* This class represents an XPath string object, and is capable of
|
|
37 |
* converting the string to other types, such as a number.
|
|
38 |
* @xsl.usage general
|
|
39 |
*/
|
|
40 |
public class XString extends XObject implements XMLString
|
|
41 |
{
|
|
42 |
static final long serialVersionUID = 2020470518395094525L;
|
|
43 |
|
|
44 |
/** Empty string XString object */
|
|
45 |
public static final XString EMPTYSTRING = new XString("");
|
|
46 |
|
|
47 |
/**
|
|
48 |
* Construct a XString object. This constructor exists for derived classes.
|
|
49 |
*
|
|
50 |
* @param val String object this will wrap.
|
|
51 |
*/
|
|
52 |
protected XString(Object val)
|
|
53 |
{
|
|
54 |
super(val);
|
|
55 |
}
|
|
56 |
|
|
57 |
/**
|
|
58 |
* Construct a XNodeSet object.
|
|
59 |
*
|
|
60 |
* @param val String object this will wrap.
|
|
61 |
*/
|
|
62 |
public XString(String val)
|
|
63 |
{
|
|
64 |
super(val);
|
|
65 |
}
|
|
66 |
|
|
67 |
/**
|
|
68 |
* Tell that this is a CLASS_STRING.
|
|
69 |
*
|
|
70 |
* @return type CLASS_STRING
|
|
71 |
*/
|
|
72 |
public int getType()
|
|
73 |
{
|
|
74 |
return CLASS_STRING;
|
|
75 |
}
|
|
76 |
|
|
77 |
/**
|
|
78 |
* Given a request type, return the equivalent string.
|
|
79 |
* For diagnostic purposes.
|
|
80 |
*
|
|
81 |
* @return type string "#STRING"
|
|
82 |
*/
|
|
83 |
public String getTypeString()
|
|
84 |
{
|
|
85 |
return "#STRING";
|
|
86 |
}
|
|
87 |
|
|
88 |
/**
|
|
89 |
* Tell if this object contains a java String object.
|
|
90 |
*
|
|
91 |
* @return true if this XMLString can return a string without creating one.
|
|
92 |
*/
|
|
93 |
public boolean hasString()
|
|
94 |
{
|
|
95 |
return true;
|
|
96 |
}
|
|
97 |
|
|
98 |
/**
|
|
99 |
* Cast result object to a number.
|
|
100 |
*
|
|
101 |
* @return 0.0 if this string is null, numeric value of this string
|
|
102 |
* or NaN
|
|
103 |
*/
|
|
104 |
public double num()
|
|
105 |
{
|
|
106 |
return toDouble();
|
|
107 |
}
|
|
108 |
|
|
109 |
/**
|
|
110 |
* Convert a string to a double -- Allowed input is in fixed
|
|
111 |
* notation ddd.fff.
|
|
112 |
*
|
|
113 |
* @return A double value representation of the string, or return Double.NaN
|
|
114 |
* if the string can not be converted.
|
|
115 |
*/
|
|
116 |
public double toDouble()
|
|
117 |
{
|
|
118 |
/* XMLCharacterRecognizer.isWhiteSpace(char c) methods treats the following
|
|
119 |
* characters as white space characters.
|
|
120 |
* ht - horizontal tab, nl - newline , cr - carriage return and sp - space
|
|
121 |
* trim() methods by default also takes care of these white space characters
|
|
122 |
* So trim() method is used to remove leading and trailing white spaces.
|
|
123 |
*/
|
|
124 |
XMLString s = trim();
|
|
125 |
double result = Double.NaN;
|
|
126 |
for (int i = 0; i < s.length(); i++)
|
|
127 |
{
|
|
128 |
char c = s.charAt(i);
|
|
129 |
if (c != '-' && c != '.' && ( c < 0X30 || c > 0x39)) {
|
|
130 |
// The character is not a '-' or a '.' or a digit
|
|
131 |
// then return NaN because something is wrong.
|
|
132 |
return result;
|
|
133 |
}
|
|
134 |
}
|
|
135 |
try
|
|
136 |
{
|
|
137 |
result = Double.parseDouble(s.toString());
|
|
138 |
} catch (NumberFormatException e){}
|
|
139 |
|
|
140 |
return result;
|
|
141 |
}
|
|
142 |
|
|
143 |
/**
|
|
144 |
* Cast result object to a boolean.
|
|
145 |
*
|
|
146 |
* @return True if the length of this string object is greater
|
|
147 |
* than 0.
|
|
148 |
*/
|
|
149 |
public boolean bool()
|
|
150 |
{
|
|
151 |
return str().length() > 0;
|
|
152 |
}
|
|
153 |
|
|
154 |
/**
|
|
155 |
* Cast result object to a string.
|
|
156 |
*
|
|
157 |
* @return The string this wraps or the empty string if null
|
|
158 |
*/
|
|
159 |
public XMLString xstr()
|
|
160 |
{
|
|
161 |
return this;
|
|
162 |
}
|
|
163 |
|
|
164 |
/**
|
|
165 |
* Cast result object to a string.
|
|
166 |
*
|
|
167 |
* @return The string this wraps or the empty string if null
|
|
168 |
*/
|
|
169 |
public String str()
|
|
170 |
{
|
|
171 |
return (null != m_obj) ? ((String) m_obj) : "";
|
|
172 |
}
|
|
173 |
|
|
174 |
/**
|
|
175 |
* Cast result object to a result tree fragment.
|
|
176 |
*
|
|
177 |
* @param support Xpath context to use for the conversion
|
|
178 |
*
|
|
179 |
* @return A document fragment with this string as a child node
|
|
180 |
*/
|
|
181 |
public int rtf(XPathContext support)
|
|
182 |
{
|
|
183 |
|
|
184 |
DTM frag = support.createDocumentFragment();
|
|
185 |
|
|
186 |
frag.appendTextChild(str());
|
|
187 |
|
|
188 |
return frag.getDocument();
|
|
189 |
}
|
|
190 |
|
|
191 |
/**
|
|
192 |
* Directly call the
|
|
193 |
* characters method on the passed ContentHandler for the
|
|
194 |
* string-value. Multiple calls to the
|
|
195 |
* ContentHandler's characters methods may well occur for a single call to
|
|
196 |
* this method.
|
|
197 |
*
|
|
198 |
* @param ch A non-null reference to a ContentHandler.
|
|
199 |
*
|
|
200 |
* @throws org.xml.sax.SAXException
|
|
201 |
*/
|
|
202 |
public void dispatchCharactersEvents(org.xml.sax.ContentHandler ch)
|
|
203 |
throws org.xml.sax.SAXException
|
|
204 |
{
|
|
205 |
|
|
206 |
String str = str();
|
|
207 |
|
|
208 |
ch.characters(str.toCharArray(), 0, str.length());
|
|
209 |
}
|
|
210 |
|
|
211 |
/**
|
|
212 |
* Directly call the
|
|
213 |
* comment method on the passed LexicalHandler for the
|
|
214 |
* string-value.
|
|
215 |
*
|
|
216 |
* @param lh A non-null reference to a LexicalHandler.
|
|
217 |
*
|
|
218 |
* @throws org.xml.sax.SAXException
|
|
219 |
*/
|
|
220 |
public void dispatchAsComment(org.xml.sax.ext.LexicalHandler lh)
|
|
221 |
throws org.xml.sax.SAXException
|
|
222 |
{
|
|
223 |
|
|
224 |
String str = str();
|
|
225 |
|
|
226 |
lh.comment(str.toCharArray(), 0, str.length());
|
|
227 |
}
|
|
228 |
|
|
229 |
/**
|
|
230 |
* Returns the length of this string.
|
|
231 |
*
|
|
232 |
* @return the length of the sequence of characters represented by this
|
|
233 |
* object.
|
|
234 |
*/
|
|
235 |
public int length()
|
|
236 |
{
|
|
237 |
return str().length();
|
|
238 |
}
|
|
239 |
|
|
240 |
/**
|
|
241 |
* Returns the character at the specified index. An index ranges
|
|
242 |
* from <code>0</code> to <code>length() - 1</code>. The first character
|
|
243 |
* of the sequence is at index <code>0</code>, the next at index
|
|
244 |
* <code>1</code>, and so on, as for array indexing.
|
|
245 |
*
|
|
246 |
* @param index the index of the character.
|
|
247 |
* @return the character at the specified index of this string.
|
|
248 |
* The first character is at index <code>0</code>.
|
|
249 |
* @exception IndexOutOfBoundsException if the <code>index</code>
|
|
250 |
* argument is negative or not less than the length of this
|
|
251 |
* string.
|
|
252 |
*/
|
|
253 |
public char charAt(int index)
|
|
254 |
{
|
|
255 |
return str().charAt(index);
|
|
256 |
}
|
|
257 |
|
|
258 |
/**
|
|
259 |
* Copies characters from this string into the destination character
|
|
260 |
* array.
|
|
261 |
*
|
|
262 |
* @param srcBegin index of the first character in the string
|
|
263 |
* to copy.
|
|
264 |
* @param srcEnd index after the last character in the string
|
|
265 |
* to copy.
|
|
266 |
* @param dst the destination array.
|
|
267 |
* @param dstBegin the start offset in the destination array.
|
|
268 |
* @exception IndexOutOfBoundsException If any of the following
|
|
269 |
* is true:
|
|
270 |
* <ul><li><code>srcBegin</code> is negative.
|
|
271 |
* <li><code>srcBegin</code> is greater than <code>srcEnd</code>
|
|
272 |
* <li><code>srcEnd</code> is greater than the length of this
|
|
273 |
* string
|
|
274 |
* <li><code>dstBegin</code> is negative
|
|
275 |
* <li><code>dstBegin+(srcEnd-srcBegin)</code> is larger than
|
|
276 |
* <code>dst.length</code></ul>
|
|
277 |
* @exception NullPointerException if <code>dst</code> is <code>null</code>
|
|
278 |
*/
|
|
279 |
public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin)
|
|
280 |
{
|
|
281 |
str().getChars(srcBegin, srcEnd, dst, dstBegin);
|
|
282 |
}
|
|
283 |
|
|
284 |
/**
|
|
285 |
* Tell if two objects are functionally equal.
|
|
286 |
*
|
|
287 |
* @param obj2 Object to compare this to
|
|
288 |
*
|
|
289 |
* @return true if the two objects are equal
|
|
290 |
*
|
|
291 |
* @throws javax.xml.transform.TransformerException
|
|
292 |
*/
|
|
293 |
public boolean equals(XObject obj2)
|
|
294 |
{
|
|
295 |
|
|
296 |
// In order to handle the 'all' semantics of
|
|
297 |
// nodeset comparisons, we always call the
|
|
298 |
// nodeset function.
|
|
299 |
int t = obj2.getType();
|
|
300 |
try
|
|
301 |
{
|
|
302 |
if (XObject.CLASS_NODESET == t)
|
|
303 |
return obj2.equals(this);
|
|
304 |
// If at least one object to be compared is a boolean, then each object
|
|
305 |
// to be compared is converted to a boolean as if by applying the
|
|
306 |
// boolean function.
|
|
307 |
else if(XObject.CLASS_BOOLEAN == t)
|
|
308 |
return obj2.bool() == bool();
|
|
309 |
// Otherwise, if at least one object to be compared is a number, then each object
|
|
310 |
// to be compared is converted to a number as if by applying the number function.
|
|
311 |
else if(XObject.CLASS_NUMBER == t)
|
|
312 |
return obj2.num() == num();
|
|
313 |
}
|
|
314 |
catch(javax.xml.transform.TransformerException te)
|
|
315 |
{
|
|
316 |
throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(te);
|
|
317 |
}
|
|
318 |
|
|
319 |
// Otherwise, both objects to be compared are converted to strings as
|
|
320 |
// if by applying the string function.
|
|
321 |
return xstr().equals(obj2.xstr());
|
|
322 |
}
|
|
323 |
|
|
324 |
/**
|
|
325 |
* Compares this string to the specified object.
|
|
326 |
* The result is <code>true</code> if and only if the argument is not
|
|
327 |
* <code>null</code> and is a <code>String</code> object that represents
|
|
328 |
* the same sequence of characters as this object.
|
|
329 |
*
|
|
330 |
* @param obj2 the object to compare this <code>String</code>
|
|
331 |
* against.
|
|
332 |
* @return <code>true</code> if the <code>String </code>are equal;
|
|
333 |
* <code>false</code> otherwise.
|
|
334 |
* @see java.lang.String#compareTo(java.lang.String)
|
|
335 |
* @see java.lang.String#equalsIgnoreCase(java.lang.String)
|
|
336 |
*/
|
|
337 |
public boolean equals(XMLString obj2)
|
|
338 |
{
|
|
339 |
|
|
340 |
if (!obj2.hasString())
|
|
341 |
return obj2.equals(this);
|
|
342 |
else
|
|
343 |
return str().equals(obj2.toString());
|
|
344 |
}
|
|
345 |
|
|
346 |
/**
|
|
347 |
* Compares this string to the specified object.
|
|
348 |
* The result is <code>true</code> if and only if the argument is not
|
|
349 |
* <code>null</code> and is a <code>String</code> object that represents
|
|
350 |
* the same sequence of characters as this object.
|
|
351 |
*
|
|
352 |
* @param obj2 the object to compare this <code>String</code>
|
|
353 |
* against.
|
|
354 |
* @return <code>true</code> if the <code>String </code>are equal;
|
|
355 |
* <code>false</code> otherwise.
|
|
356 |
* @see java.lang.String#compareTo(java.lang.String)
|
|
357 |
* @see java.lang.String#equalsIgnoreCase(java.lang.String)
|
|
358 |
*/
|
|
359 |
public boolean equals(Object obj2)
|
|
360 |
{
|
|
361 |
|
|
362 |
if (null == obj2)
|
|
363 |
return false;
|
|
364 |
|
|
365 |
// In order to handle the 'all' semantics of
|
|
366 |
// nodeset comparisons, we always call the
|
|
367 |
// nodeset function.
|
|
368 |
else if (obj2 instanceof XNodeSet)
|
|
369 |
return obj2.equals(this);
|
|
370 |
else if(obj2 instanceof XNumber)
|
|
371 |
return obj2.equals(this);
|
|
372 |
else
|
|
373 |
return str().equals(obj2.toString());
|
|
374 |
}
|
|
375 |
|
|
376 |
/**
|
|
377 |
* Compares this <code>String</code> to another <code>String</code>,
|
|
378 |
* ignoring case considerations. Two strings are considered equal
|
|
379 |
* ignoring case if they are of the same length, and corresponding
|
|
380 |
* characters in the two strings are equal ignoring case.
|
|
381 |
*
|
|
382 |
* @param anotherString the <code>String</code> to compare this
|
|
383 |
* <code>String</code> against.
|
|
384 |
* @return <code>true</code> if the argument is not <code>null</code>
|
|
385 |
* and the <code>String</code>s are equal,
|
|
386 |
* ignoring case; <code>false</code> otherwise.
|
|
387 |
* @see #equals(Object)
|
|
388 |
* @see java.lang.Character#toLowerCase(char)
|
|
389 |
* @see java.lang.Character#toUpperCase(char)
|
|
390 |
*/
|
|
391 |
public boolean equalsIgnoreCase(String anotherString)
|
|
392 |
{
|
|
393 |
return str().equalsIgnoreCase(anotherString);
|
|
394 |
}
|
|
395 |
|
|
396 |
/**
|
|
397 |
* Compares two strings lexicographically.
|
|
398 |
*
|
|
399 |
* @param xstr the <code>String</code> to be compared.
|
|
400 |
*
|
|
401 |
* @return the value <code>0</code> if the argument string is equal to
|
|
402 |
* this string; a value less than <code>0</code> if this string
|
|
403 |
* is lexicographically less than the string argument; and a
|
|
404 |
* value greater than <code>0</code> if this string is
|
|
405 |
* lexicographically greater than the string argument.
|
|
406 |
* @exception java.lang.NullPointerException if <code>anotherString</code>
|
|
407 |
* is <code>null</code>.
|
|
408 |
*/
|
|
409 |
public int compareTo(XMLString xstr)
|
|
410 |
{
|
|
411 |
|
|
412 |
int len1 = this.length();
|
|
413 |
int len2 = xstr.length();
|
|
414 |
int n = Math.min(len1, len2);
|
|
415 |
int i = 0;
|
|
416 |
int j = 0;
|
|
417 |
|
|
418 |
while (n-- != 0)
|
|
419 |
{
|
|
420 |
char c1 = this.charAt(i);
|
|
421 |
char c2 = xstr.charAt(j);
|
|
422 |
|
|
423 |
if (c1 != c2)
|
|
424 |
{
|
|
425 |
return c1 - c2;
|
|
426 |
}
|
|
427 |
|
|
428 |
i++;
|
|
429 |
j++;
|
|
430 |
}
|
|
431 |
|
|
432 |
return len1 - len2;
|
|
433 |
}
|
|
434 |
|
|
435 |
/**
|
|
436 |
* Compares two strings lexicographically, ignoring case considerations.
|
|
437 |
* This method returns an integer whose sign is that of
|
|
438 |
* <code>this.toUpperCase().toLowerCase().compareTo(
|
|
439 |
* str.toUpperCase().toLowerCase())</code>.
|
|
440 |
* <p>
|
|
441 |
* Note that this method does <em>not</em> take locale into account,
|
|
442 |
* and will result in an unsatisfactory ordering for certain locales.
|
|
443 |
* The java.text package provides <em>collators</em> to allow
|
|
444 |
* locale-sensitive ordering.
|
|
445 |
*
|
|
446 |
* @param str the <code>String</code> to be compared.
|
|
447 |
* @return a negative integer, zero, or a positive integer as the
|
|
448 |
* the specified String is greater than, equal to, or less
|
|
449 |
* than this String, ignoring case considerations.
|
|
450 |
* @see java.text.Collator#compare(String, String)
|
|
451 |
* @since 1.2
|
|
452 |
*/
|
|
453 |
public int compareToIgnoreCase(XMLString str)
|
|
454 |
{
|
|
455 |
// %REVIEW% Like it says, @since 1.2. Doesn't exist in earlier
|
|
456 |
// versions of Java, hence we can't yet shell out to it. We can implement
|
|
457 |
// it as character-by-character compare, but doing so efficiently
|
|
458 |
// is likely to be (ahem) interesting.
|
|
459 |
//
|
|
460 |
// However, since nobody is actually _using_ this method yet:
|
|
461 |
// return str().compareToIgnoreCase(str.toString());
|
|
462 |
|
|
463 |
throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(
|
|
464 |
new java.lang.NoSuchMethodException(
|
|
465 |
"Java 1.2 method, not yet implemented"));
|
|
466 |
}
|
|
467 |
|
|
468 |
/**
|
|
469 |
* Tests if this string starts with the specified prefix beginning
|
|
470 |
* a specified index.
|
|
471 |
*
|
|
472 |
* @param prefix the prefix.
|
|
473 |
* @param toffset where to begin looking in the string.
|
|
474 |
* @return <code>true</code> if the character sequence represented by the
|
|
475 |
* argument is a prefix of the substring of this object starting
|
|
476 |
* at index <code>toffset</code>; <code>false</code> otherwise.
|
|
477 |
* The result is <code>false</code> if <code>toffset</code> is
|
|
478 |
* negative or greater than the length of this
|
|
479 |
* <code>String</code> object; otherwise the result is the same
|
|
480 |
* as the result of the expression
|
|
481 |
* <pre>
|
|
482 |
* this.subString(toffset).startsWith(prefix)
|
|
483 |
* </pre>
|
|
484 |
* @exception java.lang.NullPointerException if <code>prefix</code> is
|
|
485 |
* <code>null</code>.
|
|
486 |
*/
|
|
487 |
public boolean startsWith(String prefix, int toffset)
|
|
488 |
{
|
|
489 |
return str().startsWith(prefix, toffset);
|
|
490 |
}
|
|
491 |
|
|
492 |
/**
|
|
493 |
* Tests if this string starts with the specified prefix.
|
|
494 |
*
|
|
495 |
* @param prefix the prefix.
|
|
496 |
* @return <code>true</code> if the character sequence represented by the
|
|
497 |
* argument is a prefix of the character sequence represented by
|
|
498 |
* this string; <code>false</code> otherwise.
|
|
499 |
* Note also that <code>true</code> will be returned if the
|
|
500 |
* argument is an empty string or is equal to this
|
|
501 |
* <code>String</code> object as determined by the
|
|
502 |
* {@link #equals(Object)} method.
|
|
503 |
* @exception java.lang.NullPointerException if <code>prefix</code> is
|
|
504 |
* <code>null</code>.
|
|
505 |
*/
|
|
506 |
public boolean startsWith(String prefix)
|
|
507 |
{
|
|
508 |
return startsWith(prefix, 0);
|
|
509 |
}
|
|
510 |
|
|
511 |
/**
|
|
512 |
* Tests if this string starts with the specified prefix beginning
|
|
513 |
* a specified index.
|
|
514 |
*
|
|
515 |
* @param prefix the prefix.
|
|
516 |
* @param toffset where to begin looking in the string.
|
|
517 |
* @return <code>true</code> if the character sequence represented by the
|
|
518 |
* argument is a prefix of the substring of this object starting
|
|
519 |
* at index <code>toffset</code>; <code>false</code> otherwise.
|
|
520 |
* The result is <code>false</code> if <code>toffset</code> is
|
|
521 |
* negative or greater than the length of this
|
|
522 |
* <code>String</code> object; otherwise the result is the same
|
|
523 |
* as the result of the expression
|
|
524 |
* <pre>
|
|
525 |
* this.subString(toffset).startsWith(prefix)
|
|
526 |
* </pre>
|
|
527 |
* @exception java.lang.NullPointerException if <code>prefix</code> is
|
|
528 |
* <code>null</code>.
|
|
529 |
*/
|
|
530 |
public boolean startsWith(XMLString prefix, int toffset)
|
|
531 |
{
|
|
532 |
|
|
533 |
int to = toffset;
|
|
534 |
int tlim = this.length();
|
|
535 |
int po = 0;
|
|
536 |
int pc = prefix.length();
|
|
537 |
|
|
538 |
// Note: toffset might be near -1>>>1.
|
|
539 |
if ((toffset < 0) || (toffset > tlim - pc))
|
|
540 |
{
|
|
541 |
return false;
|
|
542 |
}
|
|
543 |
|
|
544 |
while (--pc >= 0)
|
|
545 |
{
|
|
546 |
if (this.charAt(to) != prefix.charAt(po))
|
|
547 |
{
|
|
548 |
return false;
|
|
549 |
}
|
|
550 |
|
|
551 |
to++;
|
|
552 |
po++;
|
|
553 |
}
|
|
554 |
|
|
555 |
return true;
|
|
556 |
}
|
|
557 |
|
|
558 |
/**
|
|
559 |
* Tests if this string starts with the specified prefix.
|
|
560 |
*
|
|
561 |
* @param prefix the prefix.
|
|
562 |
* @return <code>true</code> if the character sequence represented by the
|
|
563 |
* argument is a prefix of the character sequence represented by
|
|
564 |
* this string; <code>false</code> otherwise.
|
|
565 |
* Note also that <code>true</code> will be returned if the
|
|
566 |
* argument is an empty string or is equal to this
|
|
567 |
* <code>String</code> object as determined by the
|
|
568 |
* {@link #equals(Object)} method.
|
|
569 |
* @exception java.lang.NullPointerException if <code>prefix</code> is
|
|
570 |
* <code>null</code>.
|
|
571 |
*/
|
|
572 |
public boolean startsWith(XMLString prefix)
|
|
573 |
{
|
|
574 |
return startsWith(prefix, 0);
|
|
575 |
}
|
|
576 |
|
|
577 |
/**
|
|
578 |
* Tests if this string ends with the specified suffix.
|
|
579 |
*
|
|
580 |
* @param suffix the suffix.
|
|
581 |
* @return <code>true</code> if the character sequence represented by the
|
|
582 |
* argument is a suffix of the character sequence represented by
|
|
583 |
* this object; <code>false</code> otherwise. Note that the
|
|
584 |
* result will be <code>true</code> if the argument is the
|
|
585 |
* empty string or is equal to this <code>String</code> object
|
|
586 |
* as determined by the {@link #equals(Object)} method.
|
|
587 |
* @exception java.lang.NullPointerException if <code>suffix</code> is
|
|
588 |
* <code>null</code>.
|
|
589 |
*/
|
|
590 |
public boolean endsWith(String suffix)
|
|
591 |
{
|
|
592 |
return str().endsWith(suffix);
|
|
593 |
}
|
|
594 |
|
|
595 |
/**
|
|
596 |
* Returns a hashcode for this string. The hashcode for a
|
|
597 |
* <code>String</code> object is computed as
|
|
598 |
* <blockquote><pre>
|
|
599 |
* s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
|
|
600 |
* </pre></blockquote>
|
|
601 |
* using <code>int</code> arithmetic, where <code>s[i]</code> is the
|
|
602 |
* <i>i</i>th character of the string, <code>n</code> is the length of
|
|
603 |
* the string, and <code>^</code> indicates exponentiation.
|
|
604 |
* (The hash value of the empty string is zero.)
|
|
605 |
*
|
|
606 |
* @return a hash code value for this object.
|
|
607 |
*/
|
|
608 |
public int hashCode()
|
|
609 |
{
|
|
610 |
return str().hashCode();
|
|
611 |
}
|
|
612 |
|
|
613 |
/**
|
|
614 |
* Returns the index within this string of the first occurrence of the
|
|
615 |
* specified character. If a character with value <code>ch</code> occurs
|
|
616 |
* in the character sequence represented by this <code>String</code>
|
|
617 |
* object, then the index of the first such occurrence is returned --
|
|
618 |
* that is, the smallest value <i>k</i> such that:
|
|
619 |
* <blockquote><pre>
|
|
620 |
* this.charAt(<i>k</i>) == ch
|
|
621 |
* </pre></blockquote>
|
|
622 |
* is <code>true</code>. If no such character occurs in this string,
|
|
623 |
* then <code>-1</code> is returned.
|
|
624 |
*
|
|
625 |
* @param ch a character.
|
|
626 |
* @return the index of the first occurrence of the character in the
|
|
627 |
* character sequence represented by this object, or
|
|
628 |
* <code>-1</code> if the character does not occur.
|
|
629 |
*/
|
|
630 |
public int indexOf(int ch)
|
|
631 |
{
|
|
632 |
return str().indexOf(ch);
|
|
633 |
}
|
|
634 |
|
|
635 |
/**
|
|
636 |
* Returns the index within this string of the first occurrence of the
|
|
637 |
* specified character, starting the search at the specified index.
|
|
638 |
* <p>
|
|
639 |
* If a character with value <code>ch</code> occurs in the character
|
|
640 |
* sequence represented by this <code>String</code> object at an index
|
|
641 |
* no smaller than <code>fromIndex</code>, then the index of the first
|
|
642 |
* such occurrence is returned--that is, the smallest value <i>k</i>
|
|
643 |
* such that:
|
|
644 |
* <blockquote><pre>
|
|
645 |
* (this.charAt(<i>k</i>) == ch) && (<i>k</i> >= fromIndex)
|
|
646 |
* </pre></blockquote>
|
|
647 |
* is true. If no such character occurs in this string at or after
|
|
648 |
* position <code>fromIndex</code>, then <code>-1</code> is returned.
|
|
649 |
* <p>
|
|
650 |
* There is no restriction on the value of <code>fromIndex</code>. If it
|
|
651 |
* is negative, it has the same effect as if it were zero: this entire
|
|
652 |
* string may be searched. If it is greater than the length of this
|
|
653 |
* string, it has the same effect as if it were equal to the length of
|
|
654 |
* this string: <code>-1</code> is returned.
|
|
655 |
*
|
|
656 |
* @param ch a character.
|
|
657 |
* @param fromIndex the index to start the search from.
|
|
658 |
* @return the index of the first occurrence of the character in the
|
|
659 |
* character sequence represented by this object that is greater
|
|
660 |
* than or equal to <code>fromIndex</code>, or <code>-1</code>
|
|
661 |
* if the character does not occur.
|
|
662 |
*/
|
|
663 |
public int indexOf(int ch, int fromIndex)
|
|
664 |
{
|
|
665 |
return str().indexOf(ch, fromIndex);
|
|
666 |
}
|
|
667 |
|
|
668 |
/**
|
|
669 |
* Returns the index within this string of the last occurrence of the
|
|
670 |
* specified character. That is, the index returned is the largest
|
|
671 |
* value <i>k</i> such that:
|
|
672 |
* <blockquote><pre>
|
|
673 |
* this.charAt(<i>k</i>) == ch
|
|
674 |
* </pre></blockquote>
|
|
675 |
* is true.
|
|
676 |
* The String is searched backwards starting at the last character.
|
|
677 |
*
|
|
678 |
* @param ch a character.
|
|
679 |
* @return the index of the last occurrence of the character in the
|
|
680 |
* character sequence represented by this object, or
|
|
681 |
* <code>-1</code> if the character does not occur.
|
|
682 |
*/
|
|
683 |
public int lastIndexOf(int ch)
|
|
684 |
{
|
|
685 |
return str().lastIndexOf(ch);
|
|
686 |
}
|
|
687 |
|
|
688 |
/**
|
|
689 |
* Returns the index within this string of the last occurrence of the
|
|
690 |
* specified character, searching backward starting at the specified
|
|
691 |
* index. That is, the index returned is the largest value <i>k</i>
|
|
692 |
* such that:
|
|
693 |
* <blockquote><pre>
|
|
694 |
* this.charAt(k) == ch) && (k <= fromIndex)
|
|
695 |
* </pre></blockquote>
|
|
696 |
* is true.
|
|
697 |
*
|
|
698 |
* @param ch a character.
|
|
699 |
* @param fromIndex the index to start the search from. There is no
|
|
700 |
* restriction on the value of <code>fromIndex</code>. If it is
|
|
701 |
* greater than or equal to the length of this string, it has
|
|
702 |
* the same effect as if it were equal to one less than the
|
|
703 |
* length of this string: this entire string may be searched.
|
|
704 |
* If it is negative, it has the same effect as if it were -1:
|
|
705 |
* -1 is returned.
|
|
706 |
* @return the index of the last occurrence of the character in the
|
|
707 |
* character sequence represented by this object that is less
|
|
708 |
* than or equal to <code>fromIndex</code>, or <code>-1</code>
|
|
709 |
* if the character does not occur before that point.
|
|
710 |
*/
|
|
711 |
public int lastIndexOf(int ch, int fromIndex)
|
|
712 |
{
|
|
713 |
return str().lastIndexOf(ch, fromIndex);
|
|
714 |
}
|
|
715 |
|
|
716 |
/**
|
|
717 |
* Returns the index within this string of the first occurrence of the
|
|
718 |
* specified substring. The integer returned is the smallest value
|
|
719 |
* <i>k</i> such that:
|
|
720 |
* <blockquote><pre>
|
|
721 |
* this.startsWith(str, <i>k</i>)
|
|
722 |
* </pre></blockquote>
|
|
723 |
* is <code>true</code>.
|
|
724 |
*
|
|
725 |
* @param str any string.
|
|
726 |
* @return if the string argument occurs as a substring within this
|
|
727 |
* object, then the index of the first character of the first
|
|
728 |
* such substring is returned; if it does not occur as a
|
|
729 |
* substring, <code>-1</code> is returned.
|
|
730 |
* @exception java.lang.NullPointerException if <code>str</code> is
|
|
731 |
* <code>null</code>.
|
|
732 |
*/
|
|
733 |
public int indexOf(String str)
|
|
734 |
{
|
|
735 |
return str().indexOf(str);
|
|
736 |
}
|
|
737 |
|
|
738 |
/**
|
|
739 |
* Returns the index within this string of the first occurrence of the
|
|
740 |
* specified substring. The integer returned is the smallest value
|
|
741 |
* <i>k</i> such that:
|
|
742 |
* <blockquote><pre>
|
|
743 |
* this.startsWith(str, <i>k</i>)
|
|
744 |
* </pre></blockquote>
|
|
745 |
* is <code>true</code>.
|
|
746 |
*
|
|
747 |
* @param str any string.
|
|
748 |
* @return if the string argument occurs as a substring within this
|
|
749 |
* object, then the index of the first character of the first
|
|
750 |
* such substring is returned; if it does not occur as a
|
|
751 |
* substring, <code>-1</code> is returned.
|
|
752 |
* @exception java.lang.NullPointerException if <code>str</code> is
|
|
753 |
* <code>null</code>.
|
|
754 |
*/
|
|
755 |
public int indexOf(XMLString str)
|
|
756 |
{
|
|
757 |
return str().indexOf(str.toString());
|
|
758 |
}
|
|
759 |
|
|
760 |
/**
|
|
761 |
* Returns the index within this string of the first occurrence of the
|
|
762 |
* specified substring, starting at the specified index. The integer
|
|
763 |
* returned is the smallest value <i>k</i> such that:
|
|
764 |
* <blockquote><pre>
|
|
765 |
* this.startsWith(str, <i>k</i>) && (<i>k</i> >= fromIndex)
|
|
766 |
* </pre></blockquote>
|
|
767 |
* is <code>true</code>.
|
|
768 |
* <p>
|
|
769 |
* There is no restriction on the value of <code>fromIndex</code>. If
|
|
770 |
* it is negative, it has the same effect as if it were zero: this entire
|
|
771 |
* string may be searched. If it is greater than the length of this
|
|
772 |
* string, it has the same effect as if it were equal to the length of
|
|
773 |
* this string: <code>-1</code> is returned.
|
|
774 |
*
|
|
775 |
* @param str the substring to search for.
|
|
776 |
* @param fromIndex the index to start the search from.
|
|
777 |
* @return If the string argument occurs as a substring within this
|
|
778 |
* object at a starting index no smaller than
|
|
779 |
* <code>fromIndex</code>, then the index of the first character
|
|
780 |
* of the first such substring is returned. If it does not occur
|
|
781 |
* as a substring starting at <code>fromIndex</code> or beyond,
|
|
782 |
* <code>-1</code> is returned.
|
|
783 |
* @exception java.lang.NullPointerException if <code>str</code> is
|
|
784 |
* <code>null</code>
|
|
785 |
*/
|
|
786 |
public int indexOf(String str, int fromIndex)
|
|
787 |
{
|
|
788 |
return str().indexOf(str, fromIndex);
|
|
789 |
}
|
|
790 |
|
|
791 |
/**
|
|
792 |
* Returns the index within this string of the rightmost occurrence
|
|
793 |
* of the specified substring. The rightmost empty string "" is
|
|
794 |
* considered to occur at the index value <code>this.length()</code>.
|
|
795 |
* The returned index is the largest value <i>k</i> such that
|
|
796 |
* <blockquote><pre>
|
|
797 |
* this.startsWith(str, k)
|
|
798 |
* </pre></blockquote>
|
|
799 |
* is true.
|
|
800 |
*
|
|
801 |
* @param str the substring to search for.
|
|
802 |
* @return if the string argument occurs one or more times as a substring
|
|
803 |
* within this object, then the index of the first character of
|
|
804 |
* the last such substring is returned. If it does not occur as
|
|
805 |
* a substring, <code>-1</code> is returned.
|
|
806 |
* @exception java.lang.NullPointerException if <code>str</code> is
|
|
807 |
* <code>null</code>.
|
|
808 |
*/
|
|
809 |
public int lastIndexOf(String str)
|
|
810 |
{
|
|
811 |
return str().lastIndexOf(str);
|
|
812 |
}
|
|
813 |
|
|
814 |
/**
|
|
815 |
* Returns the index within this string of the last occurrence of
|
|
816 |
* the specified substring.
|
|
817 |
*
|
|
818 |
* @param str the substring to search for.
|
|
819 |
* @param fromIndex the index to start the search from. There is no
|
|
820 |
* restriction on the value of fromIndex. If it is greater than
|
|
821 |
* the length of this string, it has the same effect as if it
|
|
822 |
* were equal to the length of this string: this entire string
|
|
823 |
* may be searched. If it is negative, it has the same effect
|
|
824 |
* as if it were -1: -1 is returned.
|
|
825 |
* @return If the string argument occurs one or more times as a substring
|
|
826 |
* within this object at a starting index no greater than
|
|
827 |
* <code>fromIndex</code>, then the index of the first character of
|
|
828 |
* the last such substring is returned. If it does not occur as a
|
|
829 |
* substring starting at <code>fromIndex</code> or earlier,
|
|
830 |
* <code>-1</code> is returned.
|
|
831 |
* @exception java.lang.NullPointerException if <code>str</code> is
|
|
832 |
* <code>null</code>.
|
|
833 |
*/
|
|
834 |
public int lastIndexOf(String str, int fromIndex)
|
|
835 |
{
|
|
836 |
return str().lastIndexOf(str, fromIndex);
|
|
837 |
}
|
|
838 |
|
|
839 |
/**
|
|
840 |
* Returns a new string that is a substring of this string. The
|
|
841 |
* substring begins with the character at the specified index and
|
|
842 |
* extends to the end of this string. <p>
|
|
843 |
* Examples:
|
|
844 |
* <blockquote><pre>
|
|
845 |
* "unhappy".substring(2) returns "happy"
|
|
846 |
* "Harbison".substring(3) returns "bison"
|
|
847 |
* "emptiness".substring(9) returns "" (an empty string)
|
|
848 |
* </pre></blockquote>
|
|
849 |
*
|
|
850 |
* @param beginIndex the beginning index, inclusive.
|
|
851 |
* @return the specified substring.
|
|
852 |
* @exception IndexOutOfBoundsException if
|
|
853 |
* <code>beginIndex</code> is negative or larger than the
|
|
854 |
* length of this <code>String</code> object.
|
|
855 |
*/
|
|
856 |
public XMLString substring(int beginIndex)
|
|
857 |
{
|
|
858 |
return new XString(str().substring(beginIndex));
|
|
859 |
}
|
|
860 |
|
|
861 |
/**
|
|
862 |
* Returns a new string that is a substring of this string. The
|
|
863 |
* substring begins at the specified <code>beginIndex</code> and
|
|
864 |
* extends to the character at index <code>endIndex - 1</code>.
|
|
865 |
* Thus the length of the substring is <code>endIndex-beginIndex</code>.
|
|
866 |
*
|
|
867 |
* @param beginIndex the beginning index, inclusive.
|
|
868 |
* @param endIndex the ending index, exclusive.
|
|
869 |
* @return the specified substring.
|
|
870 |
* @exception IndexOutOfBoundsException if the
|
|
871 |
* <code>beginIndex</code> is negative, or
|
|
872 |
* <code>endIndex</code> is larger than the length of
|
|
873 |
* this <code>String</code> object, or
|
|
874 |
* <code>beginIndex</code> is larger than
|
|
875 |
* <code>endIndex</code>.
|
|
876 |
*/
|
|
877 |
public XMLString substring(int beginIndex, int endIndex)
|
|
878 |
{
|
|
879 |
return new XString(str().substring(beginIndex, endIndex));
|
|
880 |
}
|
|
881 |
|
|
882 |
/**
|
|
883 |
* Concatenates the specified string to the end of this string.
|
|
884 |
*
|
|
885 |
* @param str the <code>String</code> that is concatenated to the end
|
|
886 |
* of this <code>String</code>.
|
|
887 |
* @return a string that represents the concatenation of this object's
|
|
888 |
* characters followed by the string argument's characters.
|
|
889 |
* @exception java.lang.NullPointerException if <code>str</code> is
|
|
890 |
* <code>null</code>.
|
|
891 |
*/
|
|
892 |
public XMLString concat(String str)
|
|
893 |
{
|
|
894 |
|
|
895 |
// %REVIEW% Make an FSB here?
|
|
896 |
return new XString(str().concat(str));
|
|
897 |
}
|
|
898 |
|
|
899 |
/**
|
|
900 |
* Converts all of the characters in this <code>String</code> to lower
|
|
901 |
* case using the rules of the given <code>Locale</code>.
|
|
902 |
*
|
|
903 |
* @param locale use the case transformation rules for this locale
|
|
904 |
* @return the String, converted to lowercase.
|
|
905 |
* @see java.lang.Character#toLowerCase(char)
|
|
906 |
* @see java.lang.String#toUpperCase(Locale)
|
|
907 |
*/
|
|
908 |
public XMLString toLowerCase(Locale locale)
|
|
909 |
{
|
|
910 |
return new XString(str().toLowerCase(locale));
|
|
911 |
}
|
|
912 |
|
|
913 |
/**
|
|
914 |
* Converts all of the characters in this <code>String</code> to lower
|
|
915 |
* case using the rules of the default locale, which is returned
|
|
916 |
* by <code>Locale.getDefault</code>.
|
|
917 |
* <p>
|
|
918 |
*
|
|
919 |
* @return the string, converted to lowercase.
|
|
920 |
* @see java.lang.Character#toLowerCase(char)
|
|
921 |
* @see java.lang.String#toLowerCase(Locale)
|
|
922 |
*/
|
|
923 |
public XMLString toLowerCase()
|
|
924 |
{
|
|
925 |
return new XString(str().toLowerCase());
|
|
926 |
}
|
|
927 |
|
|
928 |
/**
|
|
929 |
* Converts all of the characters in this <code>String</code> to upper
|
|
930 |
* case using the rules of the given locale.
|
|
931 |
* @param locale use the case transformation rules for this locale
|
|
932 |
* @return the String, converted to uppercase.
|
|
933 |
* @see java.lang.Character#toUpperCase(char)
|
|
934 |
* @see java.lang.String#toLowerCase(Locale)
|
|
935 |
*/
|
|
936 |
public XMLString toUpperCase(Locale locale)
|
|
937 |
{
|
|
938 |
return new XString(str().toUpperCase(locale));
|
|
939 |
}
|
|
940 |
|
|
941 |
/**
|
|
942 |
* Converts all of the characters in this <code>String</code> to upper
|
|
943 |
* case using the rules of the default locale, which is returned
|
|
944 |
* by <code>Locale.getDefault</code>.
|
|
945 |
*
|
|
946 |
* <p>
|
|
947 |
* If no character in this string has a different uppercase version,
|
|
948 |
* based on calling the <code>toUpperCase</code> method defined by
|
|
949 |
* <code>Character</code>, then the original string is returned.
|
|
950 |
* <p>
|
|
951 |
* Otherwise, this method creates a new <code>String</code> object
|
|
952 |
* representing a character sequence identical in length to the
|
|
953 |
* character sequence represented by this <code>String</code> object and
|
|
954 |
* with every character equal to the result of applying the method
|
|
955 |
* <code>Character.toUpperCase</code> to the corresponding character of
|
|
956 |
* this <code>String</code> object. <p>
|
|
957 |
* Examples:
|
|
958 |
* <blockquote><pre>
|
|
959 |
* "Fahrvergnügen".toUpperCase() returns "FAHRVERGNÜGEN"
|
|
960 |
* "Visit Ljubinje!".toUpperCase() returns "VISIT LJUBINJE!"
|
|
961 |
* </pre></blockquote>
|
|
962 |
*
|
|
963 |
* @return the string, converted to uppercase.
|
|
964 |
* @see java.lang.Character#toUpperCase(char)
|
|
965 |
* @see java.lang.String#toUpperCase(Locale)
|
|
966 |
*/
|
|
967 |
public XMLString toUpperCase()
|
|
968 |
{
|
|
969 |
return new XString(str().toUpperCase());
|
|
970 |
}
|
|
971 |
|
|
972 |
/**
|
|
973 |
* Removes white space from both ends of this string.
|
|
974 |
*
|
|
975 |
* @return this string, with white space removed from the front and end.
|
|
976 |
*/
|
|
977 |
public XMLString trim()
|
|
978 |
{
|
|
979 |
return new XString(str().trim());
|
|
980 |
}
|
|
981 |
|
|
982 |
/**
|
|
983 |
* Returns whether the specified <var>ch</var> conforms to the XML 1.0 definition
|
|
984 |
* of whitespace. Refer to <A href="http://www.w3.org/TR/1998/REC-xml-19980210#NT-S">
|
|
985 |
* the definition of <CODE>S</CODE></A> for details.
|
|
986 |
* @param ch Character to check as XML whitespace.
|
|
987 |
* @return =true if <var>ch</var> is XML whitespace; otherwise =false.
|
|
988 |
*/
|
|
989 |
private static boolean isSpace(char ch)
|
|
990 |
{
|
|
991 |
return XMLCharacterRecognizer.isWhiteSpace(ch); // Take the easy way out for now.
|
|
992 |
}
|
|
993 |
|
|
994 |
/**
|
|
995 |
* Conditionally trim all leading and trailing whitespace in the specified String.
|
|
996 |
* All strings of white space are
|
|
997 |
* replaced by a single space character (#x20), except spaces after punctuation which
|
|
998 |
* receive double spaces if doublePunctuationSpaces is true.
|
|
999 |
* This function may be useful to a formatter, but to get first class
|
|
1000 |
* results, the formatter should probably do it's own white space handling
|
|
1001 |
* based on the semantics of the formatting object.
|
|
1002 |
*
|
|
1003 |
* @param trimHead Trim leading whitespace?
|
|
1004 |
* @param trimTail Trim trailing whitespace?
|
|
1005 |
* @param doublePunctuationSpaces Use double spaces for punctuation?
|
|
1006 |
* @return The trimmed string.
|
|
1007 |
*/
|
|
1008 |
public XMLString fixWhiteSpace(boolean trimHead, boolean trimTail,
|
|
1009 |
boolean doublePunctuationSpaces)
|
|
1010 |
{
|
|
1011 |
|
|
1012 |
// %OPT% !!!!!!!
|
|
1013 |
int len = this.length();
|
|
1014 |
char[] buf = new char[len];
|
|
1015 |
|
|
1016 |
this.getChars(0, len, buf, 0);
|
|
1017 |
|
|
1018 |
boolean edit = false;
|
|
1019 |
int s;
|
|
1020 |
|
|
1021 |
for (s = 0; s < len; s++)
|
|
1022 |
{
|
|
1023 |
if (isSpace(buf[s]))
|
|
1024 |
{
|
|
1025 |
break;
|
|
1026 |
}
|
|
1027 |
}
|
|
1028 |
|
|
1029 |
/* replace S to ' '. and ' '+ -> single ' '. */
|
|
1030 |
int d = s;
|
|
1031 |
boolean pres = false;
|
|
1032 |
|
|
1033 |
for (; s < len; s++)
|
|
1034 |
{
|
|
1035 |
char c = buf[s];
|
|
1036 |
|
|
1037 |
if (isSpace(c))
|
|
1038 |
{
|
|
1039 |
if (!pres)
|
|
1040 |
{
|
|
1041 |
if (' ' != c)
|
|
1042 |
{
|
|
1043 |
edit = true;
|
|
1044 |
}
|
|
1045 |
|
|
1046 |
buf[d++] = ' ';
|
|
1047 |
|
|
1048 |
if (doublePunctuationSpaces && (s != 0))
|
|
1049 |
{
|
|
1050 |
char prevChar = buf[s - 1];
|
|
1051 |
|
|
1052 |
if (!((prevChar == '.') || (prevChar == '!')
|
|
1053 |
|| (prevChar == '?')))
|
|
1054 |
{
|
|
1055 |
pres = true;
|
|
1056 |
}
|
|
1057 |
}
|
|
1058 |
else
|
|
1059 |
{
|
|
1060 |
pres = true;
|
|
1061 |
}
|
|
1062 |
}
|
|
1063 |
else
|
|
1064 |
{
|
|
1065 |
edit = true;
|
|
1066 |
pres = true;
|
|
1067 |
}
|
|
1068 |
}
|
|
1069 |
else
|
|
1070 |
{
|
|
1071 |
buf[d++] = c;
|
|
1072 |
pres = false;
|
|
1073 |
}
|
|
1074 |
}
|
|
1075 |
|
|
1076 |
if (trimTail && 1 <= d && ' ' == buf[d - 1])
|
|
1077 |
{
|
|
1078 |
edit = true;
|
|
1079 |
|
|
1080 |
d--;
|
|
1081 |
}
|
|
1082 |
|
|
1083 |
int start = 0;
|
|
1084 |
|
|
1085 |
if (trimHead && 0 < d && ' ' == buf[0])
|
|
1086 |
{
|
|
1087 |
edit = true;
|
|
1088 |
|
|
1089 |
start++;
|
|
1090 |
}
|
|
1091 |
|
|
1092 |
XMLStringFactory xsf = XMLStringFactoryImpl.getFactory();
|
|
1093 |
|
|
1094 |
return edit ? xsf.newstr(new String(buf, start, d - start)) : this;
|
|
1095 |
}
|
|
1096 |
|
|
1097 |
/**
|
|
1098 |
* @see com.sun.org.apache.xpath.internal.XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
|
|
1099 |
*/
|
|
1100 |
public void callVisitors(ExpressionOwner owner, XPathVisitor visitor)
|
|
1101 |
{
|
|
1102 |
visitor.visitStringLiteral(owner, this);
|
|
1103 |
}
|
|
1104 |
|
|
1105 |
}
|