public override State PushChar(char c, IParseContext context, ref string rollback) { XAttribute att = context.Nodes.Peek() as XAttribute; if (c == '<') { //parent handles message if (att != null) { context.Nodes.Pop(); } rollback = string.Empty; return(Parent); } //state has just been entered if (context.CurrentStateLength == 1) { if (context.PreviousState is XmlNameState) { Debug.Assert(att.IsNamed); context.StateTag = GETTINGEQ; } else if (context.PreviousState is XmlAttributeValueState) { //Got value, so end attribute context.Nodes.Pop(); att.End(context.LocationMinus(1)); IAttributedXObject element = (IAttributedXObject)context.Nodes.Peek(); element.Attributes.AddAttribute(att); rollback = string.Empty; return(Parent); } else { //starting a new attribute Debug.Assert(att == null); Debug.Assert(context.StateTag == NAMING); att = new XAttribute(context.LocationMinus(1)); context.Nodes.Push(att); rollback = string.Empty; return(XmlNameState); } } if (c == '>') { context.LogWarning("Attribute ended unexpectedly with '>' character."); if (att != null) { context.Nodes.Pop(); } rollback = string.Empty; return(Parent); } if (context.StateTag == GETTINGEQ) { if (char.IsWhiteSpace(c)) { return(null); } else if (c == '=') { context.StateTag = GETTINGVAL; return(null); } } else if (context.StateTag == GETTINGVAL) { if (char.IsWhiteSpace(c)) { return(null); } else if (c == '"') { return(DoubleQuotedAttributeValueState); } else if (c == '\'') { return(SingleQuotedAttributeValueState); } else if (char.IsLetterOrDigit(c)) { rollback = string.Empty; return(UnquotedAttributeValueState); } } if (char.IsLetterOrDigit(c) || char.IsPunctuation(c) || char.IsWhiteSpace(c)) { if (context.StateTag == GETTINGEQ) { context.LogError("Expecting = in attribute, got " + c + "."); } else if (context.StateTag == GETTINGVAL) { context.LogError("Expecting attribute value, got " + c + "."); } else { context.LogError("Unexpected character '" + c + "' in attribute."); } if (att != null) { context.Nodes.Pop(); } rollback = string.Empty; return(Parent); } rollback = string.Empty; return(Parent); }
public override State PushChar(char c, IParseContext context, ref string rollback) { XAttribute att = context.Nodes.Peek() as XAttribute; //state has just been entered if (context.CurrentStateLength == 1) { if (context.PreviousState is XmlNameState) { //error parsing name if (!att.IsNamed) { context.Nodes.Pop(); rollback = string.Empty; return(Parent); } context.StateTag = GETTINGEQ; } else if (context.PreviousState is XmlAttributeValueState) { //Got value, so end attribute context.Nodes.Pop(); att.End(context.LocationMinus(1)); IAttributedXObject element = (IAttributedXObject)context.Nodes.Peek(); element.Attributes.AddAttribute(att); rollback = string.Empty; return(Parent); } else { //starting a new attribute Debug.Assert(att == null); Debug.Assert(context.StateTag == NAMING); att = new XAttribute(context.LocationMinus(1)); context.Nodes.Push(att); rollback = string.Empty; return(XmlNameState); } } if (context.StateTag == GETTINGEQ) { if (char.IsWhiteSpace(c)) { return(null); } if (c == '=') { context.StateTag = GETTINGVAL; return(null); } context.LogError("Expecting = in attribute, got '" + c + "'."); } else if (context.StateTag == GETTINGVAL) { if (char.IsWhiteSpace(c)) { return(null); } rollback = string.Empty; return(AttributeValueState); } else if (c != '<') { //parent handles message for '<' context.LogError("Unexpected character '" + c + "' in attribute."); } if (att != null) { context.Nodes.Pop(); } rollback = string.Empty; return(Parent); }