(HtmlParser): rename ItemParsedListener to Listener
while here: - add a new callback method: bool should_remove(Item &)
This commit is contained in:
@@ -104,9 +104,9 @@ void HTMLParser::parse_html(const wchar_t * in, Space & space, bool compact_mode
|
||||
}
|
||||
|
||||
|
||||
void HTMLParser::set_item_parsed_listener(ItemParsedListener * listener)
|
||||
void HTMLParser::set_item_parsed_listener(Listener * listener)
|
||||
{
|
||||
item_parsed_listener = listener;
|
||||
this->listener = listener;
|
||||
}
|
||||
|
||||
|
||||
@@ -393,7 +393,7 @@ void HTMLParser::SetSomeDefaults()
|
||||
skip_commentaries = false;
|
||||
skip_entities = false;
|
||||
analyze_entities = false;
|
||||
item_parsed_listener = nullptr;
|
||||
listener = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -2121,11 +2121,7 @@ void HTMLParser::CheckClosingTags()
|
||||
|
||||
for(int z=(int)stack_len-2 ; z >= i ; --z)
|
||||
{
|
||||
if( RemoveIfNeeded(z) )
|
||||
{
|
||||
RemoveLastSpace(z);
|
||||
}
|
||||
|
||||
CallListener(z); // space from the item can be set as null here (when a should_remove() callback returned true)
|
||||
CheckWhiteCharsExceptions(pstack[z]);
|
||||
|
||||
if( !skip_tags && IsTagSafe(LastItem().name) && !IsNameEqual(no_filter_tag, LastItem().name) )
|
||||
@@ -2343,23 +2339,20 @@ void HTMLParser::AddTextSpaceToSpaceTree(const Space & space)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool HTMLParser::RemoveIfNeeded(size_t index)
|
||||
void HTMLParser::CallListener(size_t index)
|
||||
{
|
||||
if( item_parsed_listener )
|
||||
if( listener )
|
||||
{
|
||||
if( !item_parsed_listener->item_parsed(pstack[index]) )
|
||||
listener->item_parsed(pstack[index]);
|
||||
|
||||
if( listener->should_remove(pstack[index]) )
|
||||
{
|
||||
return true;
|
||||
RemoveLastSpace(index);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void HTMLParser::ReadLoop()
|
||||
{
|
||||
while( status == ok && ReadItem() )
|
||||
@@ -2392,8 +2385,7 @@ void HTMLParser::ReadLoop()
|
||||
{
|
||||
if( stack_len > 0 )
|
||||
{
|
||||
if( RemoveIfNeeded(stack_len - 1) )
|
||||
RemoveLastSpace(stack_len - 1);
|
||||
CallListener(stack_len - 1);
|
||||
}
|
||||
|
||||
PopStack();
|
||||
|
Reference in New Issue
Block a user