using System;
using System.Diagnostics;
using System.Web;
namespace Sandbox.Html
{
///
/// Represents an HTML attribute.
///
[DebuggerDisplay( "Name: {Name}, Value: {Value}" )]
internal class Attribute
{
internal string _name;
internal int _namelength;
internal int _namestartindex;
internal string _value;
internal int _valuelength;
internal int _valuestartindex;
private string _text;
internal Attribute( Document ownerdocument )
{
_text = ownerdocument.Text;
}
///
/// Gets the qualified name of the attribute.
///
public string Name => _name ?? (_name = _text.Substring( _namestartindex, _namelength ).ToLowerInvariant());
///
/// Gets or sets the value of the attribute.
///
public string Value => _value ??= GetValue();
private string GetValue()
{
if ( _valuestartindex <= 0 ) return string.Empty;
if ( _valuelength <= 0 ) return string.Empty;
return HttpUtility.HtmlDecode( _text.Substring( _valuestartindex, _valuelength ) );
}
}
}