示例#1
0
        private void AddUriData(Match m, DataDictionary uri_data)
        {
            string[] groups = regex.GetGroupNames();
            foreach (string gn in groups)
            {
                Group g = m.Groups[gn];

                //
                // Unfortunately regex matching creates named groups with
                // the match index as their name, we want to filter all of
                // these guys out.
                //
                int dummy;
                if (Int32.TryParse(gn, out dummy))
                    continue;
                uri_data.Set(gn, g.Value);
            }
        }
示例#2
0
        internal static void ParseUrlEncodedData(string data, Encoding encoding, DataDictionary result)
        {
            if (data.Length == 0)
                return;

            string decoded = HtmlDecode (data);
            int decodedLength = decoded.Length;
            int namePos = 0;
            bool first = true;
            while (namePos <= decodedLength) {
                int valuePos = -1, valueEnd = -1;
                for (int q = namePos; q < decodedLength; q++) {
                    if (valuePos == -1 && decoded [q] == '=') {
                        valuePos = q + 1;
                    } else if (decoded [q] == '&') {
                        valueEnd = q;
                        break;
                    }
                }

                if (first) {
                    first = false;
                    if (decoded [namePos] == '?')
                        namePos++;
                }

                string name, value;
                if (valuePos == -1) {
                    name = null;
                    valuePos = namePos;
                } else {
                    name = UrlDecode (decoded.Substring (namePos, valuePos - namePos - 1), encoding);
                }
                if (valueEnd < 0) {
                    namePos = -1;
                    valueEnd = decoded.Length;
                } else {
                    namePos = valueEnd + 1;
                }
                value = UrlDecode (decoded.Substring (valuePos, valueEnd - valuePos), encoding);

                if (name == null) {
                   name = value;
                   value = String.Empty;
                }
                result.Set (name, value);
                if (namePos == -1)
                    break;
            }
        }
示例#3
0
        public static DataDictionary FromHeader(string header)
        {
            int eq_idx = -1;
            int key_idx = 0;
            var dict = new DataDictionary();

            for (int i = 0; i < header.Length; i++)
            {
                if (header[i] == ';')
                {
                    if (eq_idx == -1)
                        continue;
                    string key = header.Substring(key_idx, eq_idx - key_idx);
                    string value = header.Substring(eq_idx + 1, i - eq_idx - 1);

                    dict.Set(key.Trim(), value.Trim());

                    key_idx = i + 1;
                    eq_idx = -1;
                    continue;
                }

                if (header[i] == '=')
                    eq_idx = i;
            }

            if (eq_idx != -1)
            {
                string key = header.Substring(key_idx, eq_idx - key_idx);
                string value = header.Substring(eq_idx + 1);

                dict.Set(key.Trim(), value.Trim());
            }

            return dict;
        }
示例#4
0
        public bool IsMatch(string input, int start, DataDictionary data, out int end)
        {
            end = start;

            if (groups == null) {
                return false;
            }

            int input_pos = start;
            int pattern_pos = 0;

            string data_str;
            DataDictionary local_data = new DataDictionary ();
            foreach (Group g in groups) {
                // scan until start
                int g_start = start + g.Start;

                if (g_start > input.Length)
                    return false;

                int len = g_start - input_pos;
                for (int i = 0; i < len; i++) {
                    if (input [input_pos] != pattern [pattern_pos])
                        return false;

                    input_pos++;
                    pattern_pos++;

                    if (input_pos > input.Length)
                        return false;
                }

                if (g.End == pattern.Length - 1) {
                    // slurp until end
                    data_str = input.Substring (input_pos);
                    local_data.Set (g.Name, data_str);

                    data.Children.Add (local_data);
                    end = input.Length;
                    return true;
                }

                int input_start = input_pos;
                char end_marker = pattern [g.End + 1];
                while (input [input_pos] != end_marker) {
                    input_pos++;
                    if (input_pos >= input.Length)
                        return false;
                }

                data_str = input.Substring (input_start, input_pos - input_start);
                local_data.Set (g.Name, data_str);

                input_pos++;
                pattern_pos = g.End + 2;
            }

            while (pattern_pos < pattern.Length) {
                if (pattern [pattern_pos] != input [input_pos]) {
                    return false;
                }
                pattern_pos++;
                input_pos++;

                if (input_pos > input.Length) {
                    return false;
                }
            }

            data.Children.Add (local_data);
            end = input_pos;
            return true;
        }