diff options
Diffstat (limited to 'libjava/classpath/java/text/SimpleDateFormat.java')
-rw-r--r-- | libjava/classpath/java/text/SimpleDateFormat.java | 117 |
1 files changed, 73 insertions, 44 deletions
diff --git a/libjava/classpath/java/text/SimpleDateFormat.java b/libjava/classpath/java/text/SimpleDateFormat.java index 789cb83d86d..c0c4cf68cea 100644 --- a/libjava/classpath/java/text/SimpleDateFormat.java +++ b/libjava/classpath/java/text/SimpleDateFormat.java @@ -180,8 +180,8 @@ public class SimpleDateFormat extends DateFormat * years to be interpreted as representing * the years between 2004 and 2104. * - * @see get2DigitYearStart() - * @see set2DigitYearStart(java.util.Date) + * @see #get2DigitYearStart() + * @see #set2DigitYearStart(java.util.Date) * @see Date * @serial The start date of the century for parsing two digit years. * May not be null. @@ -192,8 +192,8 @@ public class SimpleDateFormat extends DateFormat * The year at which interpretation of two * digit years starts. * - * @see get2DigitYearStart() - * @see set2DigitYearStart(java.util.Date) + * @see #get2DigitYearStart() + * @see #set2DigitYearStart(java.util.Date) * @serial Ignored. */ private transient int defaultCentury; @@ -204,10 +204,10 @@ public class SimpleDateFormat extends DateFormat * stored in standardChars. Localized patterns * are translated to this form. * - * @see applyPattern(String) - * @see applyLocalizedPattern(String) - * @see toPattern() - * @see toLocalizedPattern() + * @see #applyPattern(String) + * @see #applyLocalizedPattern(String) + * @see #toPattern() + * @see #toLocalizedPattern() * @serial The non-localized pattern string. May not be null. */ private String pattern; @@ -294,44 +294,73 @@ public class SimpleDateFormat extends DateFormat int field; CompiledField current = null; - for (int i=0; i<pattern.length(); i++) { - thisChar = pattern.charAt(i); - field = standardChars.indexOf(thisChar); - if (field == -1) { - current = null; - if ((thisChar >= 'A' && thisChar <= 'Z') - || (thisChar >= 'a' && thisChar <= 'z')) { - // Not a valid letter - throw new IllegalArgumentException("Invalid letter " + thisChar + - "encountered at character " + i - + "."); - } else if (thisChar == '\'') { - // Quoted text section; skip to next single quote - pos = pattern.indexOf('\'',i+1); - if (pos == -1) { - throw new IllegalArgumentException("Quotes starting at character " - + i + " not closed."); + for (int i = 0; i < pattern.length(); i++) + { + thisChar = pattern.charAt(i); + field = standardChars.indexOf(thisChar); + if (field == -1) + { + current = null; + if ((thisChar >= 'A' && thisChar <= 'Z') + || (thisChar >= 'a' && thisChar <= 'z')) + { + // Not a valid letter + throw new IllegalArgumentException("Invalid letter " + + thisChar + + "encountered at character " + + i + "."); + } + else if (thisChar == '\'') + { + // Quoted text section; skip to next single quote + pos = pattern.indexOf('\'', i + 1); + // First look for '' -- meaning a single quote. + if (pos == i + 1) + tokens.add("'"); + else + { + // Look for the terminating quote. However, if we + // see a '', that represents a literal quote and + // we must iterate. + StringBuffer buf = new StringBuffer(); + int oldPos = i + 1; + do + { + if (pos == -1) + throw new IllegalArgumentException("Quotes starting at character " + + i + + " not closed."); + buf.append(pattern.substring(oldPos, pos)); + if (pos + 1 >= pattern.length() + || pattern.charAt(pos + 1) != '\'') + break; + buf.append('\''); + oldPos = pos + 2; + pos = pattern.indexOf('\'', pos + 2); + } + while (true); + tokens.add(buf.toString()); + } + i = pos; + } + else + { + // A special character + tokens.add(new Character(thisChar)); + } } - if ((pos+1 < pattern.length()) && (pattern.charAt(pos+1) == '\'')) { - tokens.add(pattern.substring(i+1,pos+1)); - } else { - tokens.add(pattern.substring(i+1,pos)); + else + { + // A valid field + if ((current != null) && (field == current.field)) + current.size++; + else + { + current = new CompiledField(field, 1, thisChar); + tokens.add(current); + } } - i = pos; - } else { - // A special character - tokens.add(new Character(thisChar)); - } - } else { - // A valid field - if ((current != null) && (field == current.field)) { - current.size++; - } else { - current = new CompiledField(field,1,thisChar); - tokens.add(current); - } } - } } /** @@ -611,7 +640,7 @@ public class SimpleDateFormat extends DateFormat * <li>Is using the same century for two digit years.</li> * </ul> * - * @param obj The object to compare for equality against. + * @param o The object to compare for equality against. * * @return <code>true</code> if the specified object is equal to this object, * <code>false</code> otherwise. |