Example #1
0
        public static Dictionary <String, String> getAttributes(String tag)
        {
            tag = tag + " ";

            Dictionary <String, String> dic = new Dictionary <String, String>();

            TagAttrState st = new TagAttrState();

            for (int i = 0; i < tag.Length; i++)
            {
                st.OneStr += tag[i];

                if (tag[i] == '=')
                {
                    st.EqualFound = true;
                    continue;
                }

                if (st.EqualFound && st.ValueBegin == false)
                {
                    if (tag[i] == '"')
                    {
                        st.ValueBegin   = true;
                        st.IsQuoteBegin = true;
                        continue;
                    }

                    if (tag[i] != ' ')
                    {
                        st.ValueBegin   = true;
                        st.IsQuoteBegin = false;
                        continue;
                    }
                }

                if (st.IsQuoteBegin && tag[i] == '"')
                {
                    st.IsQuoteEnd = true;
                    continue;
                }

                if (i == tag.Length - 1)
                {
                    st.OneEnd = true;
                }
                else
                {
                    if (tag[i] == ' ' && st.EqualFound && st.ValueBegin)
                    {
                        if (st.IsQuoteBegin == false)
                        {
                            st.OneEnd = true;
                        }
                        else
                        {
                            if (st.IsQuoteEnd)
                            {
                                st.OneEnd = true;
                            }
                        }
                    }
                }


                if (st.OneEnd)
                {
                    String[] kvPair = st.GetPair();
                    if (kvPair != null)
                    {
                        dic[kvPair[0]] = kvPair[1];
                    }

                    st = new TagAttrState();
                }
            }
            return(dic);
        }
Example #2
0
        public static Dictionary<String, String> getAttributes( String tag )
        {
            tag = tag + " ";

            Dictionary<String, String> dic = new Dictionary<String, String>();

            TagAttrState st = new TagAttrState();

            for (int i = 0; i < tag.Length; i++) {
                st.OneStr += tag[i];

                if (tag[i] == '=') {
                    st.EqualFound = true;
                    continue;
                }

                if (st.EqualFound && st.ValueBegin == false) {

                    if (tag[i] == '"') {
                        st.ValueBegin = true;
                        st.IsQuoteBegin = true;
                        continue;
                    }

                    if (tag[i] != ' ') {
                        st.ValueBegin = true;
                        st.IsQuoteBegin = false;
                        continue;
                    }
                }

                if (st.IsQuoteBegin && tag[i] == '"') {
                    st.IsQuoteEnd = true;
                    continue;
                }

                if (i == tag.Length - 1) {
                    st.OneEnd = true;
                }
                else {

                    if (tag[i] == ' ' && st.EqualFound && st.ValueBegin) {

                        if (st.IsQuoteBegin == false) {
                            st.OneEnd = true;
                        }
                        else {
                            if (st.IsQuoteEnd) st.OneEnd = true;
                        }

                    }

                }

                if (st.OneEnd) {

                    String[] kvPair = st.GetPair();
                    if (kvPair != null) {
                        dic[kvPair[0]] = kvPair[1];
                    }

                    st = new TagAttrState();
                }

            }
            return dic;
        }