Revert "Remove StringBuilder allocation/usage from DateTimeFormat"
authorstephentoub <stoub@microsoft.com>
Thu, 28 Jan 2016 04:13:01 +0000 (20:13 -0800)
committerstephentoub <stoub@microsoft.com>
Thu, 28 Jan 2016 04:13:01 +0000 (20:13 -0800)
This reverts commit 3a8f9cb3c9412f896fd4be808564fe26afc54fc4.

src/mscorlib/src/System/Globalization/DateTimeFormat.cs
src/mscorlib/src/System/Globalization/TimeSpanFormat.cs

index 833e06d8b2d3c38f8d4ff9218920fb105444a82d..adc6d52d1501e106427d3d538e31123419ce0a18 100644 (file)
@@ -288,10 +288,9 @@ namespace System {
     
         //
         // The pos should point to a quote character. This method will
-        // get the length, including beginning and ending quote, of the
-        // quoted string.
+        // get the string encloed by the quote character.
         //
-        internal static int ParseQuoteString(String format, int pos)
+        internal static int ParseQuoteString(String format, int pos, StringBuilder result)
         {
             //
             // NOTE : pos will be the index of the quote character in the 'format' string.
@@ -316,13 +315,15 @@ namespace System {
                     //  minute: 45"
                     // because the second double quote is escaped.
                     if (pos < formatLen) {
-                        pos++;
+                        result.Append(format[pos++]);
                     } else {
                             //
                             // This means that '\' is at the end of the formatting string.
                             //
                             throw new FormatException(Environment.GetResourceString("Format_InvalidString"));
                     }                    
+                } else {
+                    result.Append(ch);
                 }
             }
             
@@ -334,7 +335,7 @@ namespace System {
                             CultureInfo.CurrentCulture,
                             Environment.GetResourceString("Format_BadQuote"), quoteChar));
             }
-
+            
             //
             // Return the character count including the begin/end quote characters and enclosed string.
             //
@@ -629,8 +630,9 @@ namespace System {
                         break;
                     case '\'':
                     case '\"':
-                        tokenLen = ParseQuoteString(format, i);
-                        result.Append(format, i + 1, tokenLen - 2);
+                        StringBuilder enquotedString = new StringBuilder();
+                        tokenLen = ParseQuoteString(format, i, enquotedString); 
+                        result.Append(enquotedString);
                         break;
                     case '%':
                         // Optional format character.
index 1022dd91763bb7c527a71dd580f3f62b1561807e..4a9ccfda14cd8ddbcac67c5977e621c238ca0d3e 100644 (file)
@@ -232,8 +232,9 @@ namespace System.Globalization {
                         break;
                     case '\'':
                     case '\"':
-                        tokenLen = DateTimeFormat.ParseQuoteString(format, i); 
-                        result.Append(format, i + 1, tokenLen - 2);
+                        StringBuilder enquotedString = new StringBuilder();
+                        tokenLen = DateTimeFormat.ParseQuoteString(format, i, enquotedString); 
+                        result.Append(enquotedString);
                         break;
                     case '%':
                         // Optional format character.