Beispiel #1
0
            private IEnumerable<XAttribute> ReadAttributes(int skip = 0)
            {
                var textBlock = _currentText.ToString().Substring(skip);
                
                var attrReader = new AttributeReader();

                foreach (var c in textBlock)
                {
                    switch (c)
                    {
                        case '=':
                            if (attrReader.State == ReadState.ReadName)
                            {
                                attrReader.BeginReadText();
                            }
                            else
                            {
                                attrReader.Text.Append(c);
                            }
                            break;
                        case '\'':
                            if (attrReader.State == ReadState.ReadText)
                            {
                                attrReader.State = ReadState.AposOpen;
                            }
                            else
                            {
                                if (attrReader.State == ReadState.AposOpen)
                                {
                                    attrReader.State = ReadState.None;

                                    if (attrReader.SplitIndex > 0)
                                    {
                                        yield return attrReader.ReadAttribute();
                                    }
                                }
                                else
                                {
                                    attrReader.Text.Append(c);
                                }
                            }
                            break;
                        case '"':

                            if (attrReader.State == ReadState.ReadText)
                            {
                                attrReader.State = ReadState.QuoteOpen;
                            }
                            else
                            {
                                if (attrReader.State == ReadState.QuoteOpen)
                                {
                                    attrReader.State = ReadState.None;

                                    if (attrReader.SplitIndex > 0)
                                    {
                                        yield return attrReader.ReadAttribute();
                                    }
                                }
                                else
                                {
                                    attrReader.Text.Append(c);
                                }
                            }

                            break;
                        case ' ':
                            if (attrReader.State == ReadState.QuoteOpen || attrReader.State == ReadState.AposOpen)
                            {
                                attrReader.Text.Append(c);
                            }
                            else
                            {
                                if (attrReader.SplitIndex > 0)
                                {
                                    yield return attrReader.ReadAttribute();
                                }
                            }
                            break;
                        case '>':
                            if (attrReader.State == ReadState.QuoteOpen || attrReader.State == ReadState.AposOpen)
                            {
                                attrReader.Text.Append(c);
                            }
                            else
                            {
                                if (attrReader.State == ReadState.ReadText)
                                {
                                    attrReader.State = ReadState.None;

                                    if (attrReader.SplitIndex > 0)
                                    {
                                        yield return attrReader.ReadAttribute();
                                    }
                                }
                            }
                            break;
                        default:
                            if (attrReader.State == ReadState.None) attrReader.State = ReadState.ReadName;
                            attrReader.Text.Append(c);
                            break;
                    }
                }

                yield break;
            }