(HtmlParser): rename ItemParsedListener to Listener
while here: - add a new callback method: bool should_remove(Item &)
This commit is contained in:
parent
f02dd1093a
commit
f35e2122ed
|
@ -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)
|
|||
}
|
||||
|
||||
|
||||
void HTMLParser::CallListener(size_t index)
|
||||
{
|
||||
if( listener )
|
||||
{
|
||||
listener->item_parsed(pstack[index]);
|
||||
|
||||
|
||||
bool HTMLParser::RemoveIfNeeded(size_t index)
|
||||
if( listener->should_remove(pstack[index]) )
|
||||
{
|
||||
if( item_parsed_listener )
|
||||
{
|
||||
if( !item_parsed_listener->item_parsed(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();
|
||||
|
|
|
@ -160,14 +160,15 @@ public:
|
|||
};
|
||||
|
||||
|
||||
class ItemParsedListener
|
||||
class Listener
|
||||
{
|
||||
public:
|
||||
|
||||
ItemParsedListener() {}
|
||||
Listener() {}
|
||||
|
||||
virtual bool item_parsed(const Item & item) { return true; }
|
||||
virtual ~ItemParsedListener() {}
|
||||
virtual void item_parsed(const Item & item) { }
|
||||
virtual bool should_remove(const Item & item) { return false; }
|
||||
virtual ~Listener() {}
|
||||
|
||||
};
|
||||
|
||||
|
@ -182,7 +183,7 @@ public:
|
|||
HTMLParser & operator=(const HTMLParser & f);
|
||||
virtual ~HTMLParser();
|
||||
|
||||
void set_item_parsed_listener(ItemParsedListener * listener);
|
||||
void set_item_parsed_listener(Listener * listener);
|
||||
|
||||
|
||||
void parse_html(const wchar_t * in, Space & space, bool compact_mode = false);
|
||||
|
@ -304,7 +305,7 @@ protected:
|
|||
// html <nofilter> tag name
|
||||
std::wstring no_filter_tag;
|
||||
|
||||
ItemParsedListener * item_parsed_listener;
|
||||
Listener * listener;
|
||||
|
||||
/*
|
||||
true if the lastc was escaped (with a backslash)
|
||||
|
@ -445,7 +446,7 @@ protected:
|
|||
void RemoveLastSpace(size_t index);
|
||||
void AddTextSpaceToSpaceTree(const Space & space);
|
||||
|
||||
bool RemoveIfNeeded(size_t index);
|
||||
void CallListener(size_t index);
|
||||
|
||||
bool check_escape_sequentions();
|
||||
void read_xml_entity();
|
||||
|
|
Loading…
Reference in New Issue