[System.Net.Http] Add parsing of multi-value strings. Fixes #17132
[mono.git] / mcs / class / System.Net.Http / System.Net.Http.Headers / ViaHeaderValue.cs
index 4da14004e13189d47bd2bf89c2a927d35167c7d2..9381977ee17d1a351c95765636604230cee9240c 100644 (file)
@@ -26,6 +26,8 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System.Collections.Generic;
+
 namespace System.Net.Http.Headers
 {
        public class ViaHeaderValue : ICloneable
@@ -110,11 +112,25 @@ namespace System.Net.Http.Headers
                
                public static bool TryParse (string input, out ViaHeaderValue parsedValue)
                {
+                       var lexer = new Lexer (input);
+                       Token token;
+                       if (TryParseElement (lexer, out parsedValue, out token) && token == Token.Type.End)
+                               return true;
+
                        parsedValue = null;
+                       return false;
+               }
 
-                       var lexer = new Lexer (input);
+               internal static bool TryParse (string input, int minimalCount, out List<ViaHeaderValue> result)
+               {
+                       return CollectionParser.TryParse (input, minimalCount, TryParseElement, out result);
+               }
 
-                       var t = lexer.Scan ();
+               static bool TryParseElement (Lexer lexer, out ViaHeaderValue parsedValue, out Token t)  
+               {
+                       parsedValue = null;
+
+                       t = lexer.Scan ();
                        if (t != Token.Type.Token)
                                return false;
 
@@ -150,8 +166,9 @@ namespace System.Net.Http.Headers
                        value.ReceivedBy = lexer.GetStringValue (next, t);
 
                        string comment;
-                       if (!lexer.ScanCommentOptional (out comment))
-                               return false;
+                       if (lexer.ScanCommentOptional (out comment, out t)) {
+                               t = lexer.Scan ();
+                       }
 
                        value.Comment = comment;
                        parsedValue = value;