private void ParseStyles(HtmlTag tag, string style)
{
string name, value;
int start=0, i=0;
while (i < style.Length)
{
name = value = String.Empty;
// skip whitespace
while (i < style.Length &&
Char.IsWhiteSpace(style, i))
{
start = ++i;
}
// style name
while (i < style.Length &&
style[i] != StylePropChar)
{
i++;
}
// copy style name
if (start < style.Length)
{
name = style.Substring(start, i-start);
}
// inc first
start = ++i;
// skip whitespace
while (i < style.Length &&
Char.IsWhiteSpace(style, i))
{
// inc first
start = ++i;
}
// style value
while (i < style.Length &&
style[i] != StyleDelimChar)
{
// TODO: handle HTML entities (e.g. """)
i++;
}
if (!String.IsNullOrEmpty(name) &&
start < style.Length)
{
// copy style value
value = style.Substring(start, i-start);
// apply style to tag
tag.Styles[name.ToLowerInvariant()] = value;
}
// inc first
start = ++i;
}
}