Beispiel #1
0
        /// <summary>
        /// Parse a query from a given string.
        /// </summary>
        /// <param name="query">The query string to parse from.</param>
        /// <param name="urlEncoded">A value indicating whether the string is URL encoded or not.</param>
        public UriQuery(string query, bool urlEncoded)
        {
            for (int i = 0; i < query.Length; i++)
            {
                int start      = i;
                int equalIndex = -1;
                while (i < query.Length)
                {
                    if (query[i] == '=')
                    {
                        if (equalIndex < 0)
                        {
                            equalIndex = i;
                        }
                    }
                    else if (query[i] == '&')
                    {
                        break;
                    }
                    i++;
                }

                string name;
                string value;

                if (equalIndex < 0)
                {
                    name  = query.Substring(start, i - start);
                    value = string.Empty;
                }
                else
                {
                    name  = query.Substring(start, equalIndex - start);
                    value = query.Substring(equalIndex + 1, (i - equalIndex) - 1);
                }

                if (urlEncoded)
                {
                    this.Add(UrlEncoding.Decode(name), UrlEncoding.Decode(value));
                }
                else
                {
                    this.Add(name, value);
                }

                if (i == query.Length - 1 && query[i] == '&')
                {
                    this.Add(null, string.Empty);
                }
            }
        }
Beispiel #2
0
        static string[] GetUriPathNodes(string absolutePath)
        {
            ArrayList nodes = new ArrayList();
            string    path  = absolutePath.Replace('\\', '/');

            if (path.Length <= 1)
            {
                return new string[] { UrlEncoding.Decode(path) }
            }
            ;
            //	return new string[] {path};

            int start = 0;

            for (int i = 0; i < path.Length; i++)
            {
                if (path[i] == '/')
                {
                    while (i < path.Length && path[i] == '/')
                    {
                        i++;
                    }
                    nodes.Add(UrlEncoding.Decode(path.Substring(start, i - start)));
                    //nodes.Add(path.Substring(start, i-start));
                    start = i;
                }
            }

            if (start != path.Length)
            {
                nodes.Add(UrlEncoding.Decode(path.Substring(start, path.Length - start)));
            }
            //nodes.Add(path.Substring(start, path.Length-start));

            return(nodes.ToArray(typeof(string)) as string[]);
        }