Esempio n. 1
0
        /// <summary>
        /// Returns a list of
        /// <see cref="Apache.Http.NameValuePair">NameValuePairs</see>
        /// as parsed from the given string using the given character
        /// encoding.
        /// </summary>
        /// <param name="s">text to parse.</param>
        /// <param name="charset">Encoding to use when decoding the parameters.</param>
        /// <param name="parameterSeparator">
        /// The characters used to separate parameters, by convention,
        /// <code>'&'</code>
        /// and
        /// <code>';'</code>
        /// .
        /// </param>
        /// <returns>
        /// a list of
        /// <see cref="Apache.Http.NameValuePair">Apache.Http.NameValuePair</see>
        /// as built from the URI's query portion.
        /// </returns>
        /// <since>4.3</since>
        public static IList <NameValuePair> Parse(string s, Encoding charset, params char[]
                                                  parameterSeparator)
        {
            if (s == null)
            {
                return(Sharpen.Collections.EmptyList());
            }
            BasicHeaderValueParser parser = BasicHeaderValueParser.Instance;
            CharArrayBuffer        buffer = new CharArrayBuffer(s.Length);

            buffer.Append(s);
            ParserCursor          cursor = new ParserCursor(0, buffer.Length());
            IList <NameValuePair> list   = new AList <NameValuePair>();

            while (!cursor.AtEnd())
            {
                NameValuePair nvp = parser.ParseNameValuePair(buffer, cursor, parameterSeparator);
                if (nvp.GetName().Length > 0)
                {
                    list.AddItem(new BasicNameValuePair(DecodeFormFields(nvp.GetName(), charset), DecodeFormFields
                                                            (nvp.GetValue(), charset)));
                }
            }
            return(list);
        }
Esempio n. 2
0
        /// <exception cref="Apache.Http.ParseException"></exception>
        public virtual HeaderElement ParseHeader(CharArrayBuffer buffer, ParserCursor cursor
                                                 )
        {
            Args.NotNull(buffer, "Char array buffer");
            Args.NotNull(cursor, "Parser cursor");
            NameValuePair         nvp     = ParseNameValuePair(buffer, cursor);
            IList <NameValuePair> @params = new AList <NameValuePair>();

            while (!cursor.AtEnd())
            {
                NameValuePair param = ParseNameValuePair(buffer, cursor);
                @params.AddItem(param);
            }
            return(new BasicHeaderElement(nvp.GetName(), nvp.GetValue(), Sharpen.Collections.ToArray
                                              (@params, new NameValuePair[@params.Count])));
        }