classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] Patch: FYI: PR classpath/23183


From: Tom Tromey
Subject: [cp-patches] Patch: FYI: PR classpath/23183
Date: 24 Aug 2005 19:59:56 -0600

I'm checking this in.

This fixes PR classpath/23183, a small bug in SimpleDateFormat format
parsing.  We weren't correctly handling quotes.  I added a regression
test for this to Mauve.

Tom

Index: ChangeLog
from  Tom Tromey  <address@hidden>

        * java/text/SimpleDateFormat.java (compileFormat): Correctly
        handle quoted single quotes.  PR classspath/23183.

Index: java/text/SimpleDateFormat.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/text/SimpleDateFormat.java,v
retrieving revision 1.50
diff -u -r1.50 SimpleDateFormat.java
--- java/text/SimpleDateFormat.java 23 Aug 2005 17:10:16 -0000 1.50
+++ java/text/SimpleDateFormat.java 25 Aug 2005 02:03:15 -0000
@@ -314,16 +314,33 @@
              {
                // Quoted text section; skip to next single quote
                pos = pattern.indexOf('\'', i + 1);
-               if (pos == -1)
+               // First look for '' -- meaning a single quote.
+               if (pos == i + 1)
+                 tokens.add("'");
+               else
                  {
-                   throw new IllegalArgumentException("Quotes starting at 
character "
-                                                      + i + " not closed.");
+                   // 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());
                  }
-               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));
                i = pos;
              }
            else




reply via email to

[Prev in Thread] Current Thread [Next in Thread]