⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tree.xs

📁 该软件可以方便的把HTML网页解析成一棵Tree
💻 XS
📖 第 1 页 / 共 2 页
字号:
managed_node::name()## DESCRIPTION##	Gets the name of an Element_Node.## RETURN VALUE##	Returns the name of an Element_Node.################################################################################CODE:	if ( NODE_DECL( Element_Node, e, THIS ) )		RETVAL = e->name;	else		croak( "HTML::Tree::name(): object isn't an Element_Node" );OUTPUT:	RETVAL################################################################################# SYNOPSIS#managed_node*managed_node::new(sv,param_hash_ref = 0)## DESCRIPTION##	Create an HTML::Tree from one of an array-of-hashes Perl data structure,#	a file, or a string.  Because the XS compiler will do it's C++ object#	creation magic only if the function is named "new", we have to lump#	three functions into one here and distinguish them by using CASE and#	ALIAS.  Ugh.## PARAMETERS##	sv		Either a file name or a string.##	param_hash_ref	A reference to a hash of parameters.## RETURN VALUE##	Returns a blessed reference to an HTML::Tree.################################################################################CASE: ix == 1	ALIAS:		from_array = 1	INPUT:		SV* sv	CODE:		Content_Node *const parent = new Content_Node;		array2tree( sv, parent );		RETVAL = new managed_node( parent, true );	OUTPUT:		RETVALCASE: ix == 2	ALIAS:		from_file = 2	INPUT:		SV* sv		SV* param_hash_ref	CODE:		bool include_comments = false;		if ( !SvPOK( sv ) )			croak(	"Usage: "				"HTML::Tree->from_file(file_name[,hash_ref])"			);		if ( param_hash_ref ) {			if ( !is_hash_ref( param_hash_ref ) )				croak( "2nd argument must be a hash ref" );			HV *const hv = (HV*)SvRV( param_hash_ref );			SV **sv_ptr;			if ( sv_ptr = hv_fetch( hv, "Include_Comments", 16, 0 ))				include_comments = SvTRUE( *sv_ptr );		}		mmap_file const file( SvPV( sv, PL_na ) );		RETVAL = file ? new managed_node( html_parse(			file.begin(), file.end(), include_comments		), true ) : 0;	OUTPUT:		RETVALCASE: ix == 3	ALIAS:		from_string = 3	INPUT:		SV* sv		SV* param_hash_ref	CODE:		bool include_comments = false;		if ( !SvPOK( sv ) )			croak(	"Usage: "				"HTML::Tree->from_string(string[,hash_ref])"			);		if ( param_hash_ref ) {			if ( !is_hash_ref( param_hash_ref ) )				croak( "2nd argument must be a hash ref" );			HV *const hv = (HV*)SvRV( param_hash_ref );			SV **sv_ptr;			if ( sv_ptr = hv_fetch( hv, "Include_Comments", 16, 0 ))				include_comments = SvTRUE( *sv_ptr );		}		STRLEN len;		char const *const c_string = SvPV( sv, len );		RETVAL = new managed_node( html_parse(			c_string, c_string + len, include_comments		), true );	OUTPUT:		RETVAL################################################################################# SYNOPSIS#char const*managed_node::text(new_text = 0)	char const* new_text## DESCRIPTION##	Gets or sets the text of a Text_Node.## PARAMETERS##	new_text	The new text to set to.## RETURN VALUE##	Returns the text of a text node (after setting it).################################################################################CODE:	if ( NODE_DECL( Text_Node, t, THIS ) ) {		if ( new_text )			t->text = new_text;		RETVAL = t->text.c_str();	} else		croak( "HTML::Tree::text(): object isn't a Text_Node" );OUTPUT:	RETVAL################################################################################# SYNOPSIS#voidmanaged_node::visit(ref1,ref2 = 0)	SV* ref1	SV* ref2## DESCRIPTION##	Traverse an HTML::Tree calling a visitor for each node.## PARAMETERS##	With 1 argument, ref1 is a reference to a Perl function to serve as the#	visitor; with two arguments, ref1 is a reference to a hash and ref2 is#	a reference to a Perl function to serve as the visitor.################################################################################CODE:	if ( !ref2 && !is_func_ref( ref1 ) )		croak( "Usage: $html->visit(func_ref)" );	 if ( ref2 && ( !is_hash_ref( ref1 ) || !is_func_ref( ref2 ) ) )		croak( "Usage: $html->visit(hash_ref,func_ref)" );	if ( ref2 ) {		perl_visitor v( ref2, ref1 );		(*THIS)->visit( v );	} else {		perl_visitor v( ref1 );		(*THIS)->visit( v );	}################################################################################# SYNOPSIS#boolmanaged_node::write(file_name,param_hash_ref = 0)	char const* file_name	SV* param_hash_ref## DESCRIPTION##	Write the HTML text representation of the HTML tree starting at this#	node to a file.## PARAMETERS##	file_name	The name of the file to write to.##	param_hash_ref	A reference to a hash of parameters.  The only#			parameter currently supported is Pretty_Print.## RETURN VALUE##	Returns true if the file could be opened and written to; false#	otherwise.################################################################################CODE:	ofstream file( file_name );	if ( !file )		RETVAL = false;	else {		int pretty_print = -1;		if ( param_hash_ref ) {			if ( !is_hash_ref( param_hash_ref ) )				croak(	"Usage: "					"$node->write(file_name[,hash_ref])"				);			HV *const hv = (HV*)SvRV( param_hash_ref );			if ( SV **svp = hv_fetch( hv, "Pretty_Print", 12, 0 ) )				pretty_print = SvIV( *svp );		}		file << (*THIS)->write( pretty_print );		file.close();		RETVAL = true;	}OUTPUT:	RETVAL################################################################################MODULE = HTML::Tree		PACKAGE = atts4perl##	This module implements the package for the tied hash for element node#	attributes.  The package is private in that the user never sees it.#	The code is fairly straight-forward.################################################################################voidatts4perl::CLEAR()CODE:	THIS->container_.clear();voidatts4perl::DELETE(key)	char const* keyCODE:	THIS->container_.erase( key );voidatts4perl::DESTROY()intatts4perl::EXISTS(key)	char const* keyCODE:	RETVAL = THIS->container_.find( key ) != THIS->container_.end();OUTPUT:	RETVALchar const*atts4perl::FETCH(key)	char const* keyCODE:	atts4perl::const_iterator const i = THIS->container_.find( key );	RETVAL = i != THIS->container_.end() ? i->second.c_str() : 0;OUTPUT:	RETVALchar const*atts4perl::FIRSTKEY()CODE:	RETVAL = THIS->container_.empty() ? 0 :		( THIS->iter_ = THIS->container_.begin() )->first.c_str();OUTPUT:	RETVALchar const*atts4perl::NEXTKEY(key)	char const* keyCODE:	RETVAL = ++THIS->iter_ != THIS->container_.end() ?		THIS->iter_->first.c_str() : 0;OUTPUT:	RETVALvoidatts4perl::STORE(key,value)	char const* key	char const* valueCODE:	THIS->container_[ key ] = value;################################################################################MODULE = HTML::Tree		PACKAGE = Content_Node##	This module implements the package for the tied array for parent node#	children.  The package is private in that the user never sees it.################################################################################voidContent_Node::DELETE(index)	int indexCODE:	if ( index < THIS->size() ) {		Content_Node::iterator it = THIS->begin();		while ( index-- > 0 )			++it;		delete *it;	}boolContent_Node::EXISTS(index)	int indexCODE:	RETVAL = index >= 0 && index < THIS->size();OUTPUT:	RETVALvoidContent_Node::EXTEND(count)	int countCODE:	croak( "can not arbitrarily extend array; sorry" );managed_node*Content_Node::FETCH(index)	int indexCODE:	static char PERL_CONST CLASS[] = "HTML::Tree";	if ( index < THIS->size() ) {		Content_Node::iterator it = THIS->begin();		while ( index-- > 0 )			++it;		RETVAL = new managed_node( *it );	} else		RETVAL = 0;OUTPUT:	RETVALintContent_Node::FETCHSIZE()CODE:	RETVAL = THIS->size();OUTPUT:	RETVALmanaged_node*Content_Node::POP()CODE:	static char PERL_CONST CLASS[] = "HTML::Tree";	if ( !THIS->empty() )		RETVAL = new managed_node( THIS->pop_back(), true );	else		RETVAL = 0;OUTPUT:	RETVALvoidContent_Node::PUSH(sv)	SV* svCODE:	sv2tree( sv, THIS );managed_node*Content_Node::SHIFT()CODE:	static char PERL_CONST CLASS[] = "HTML::Tree";	RETVAL = !THIS->empty() ?		new managed_node( THIS->pop_front(), true ) : 0;OUTPUT:	RETVALvoidContent_Node::STORE(index,sv)	int index	SV* svCODE:	if ( index < THIS->size() ) {		Content_Node *const parent = new Content_Node;		sv2tree( sv, parent );		Content_Node::iterator it = THIS->begin();		while ( index-- > 0 )			++it;		THIS->insert( it, parent );		delete *it;	} else		croak( "index out of bounds" );voidContent_Node::UNSHIFT(sv)	SV* svCODE:	Content_Node *const parent = new Content_Node;	sv2tree( sv, parent );	THIS->push_front( parent );################################################################################MODULE = HTML::Tree		PACKAGE = string4perl##	This module implements the package for the tied scalar for strings.#	The package is private in that the user never sees it.  The code is#	fairly straight-forward.################################################################################voidstring4perl::DESTROY()char const*string4perl::FETCH()CODE:	RETVAL = THIS->s_.c_str();OUTPUT:	RETVALvoidstring4perl::STORE(value)	char const* valueCODE:	THIS->s_ = value;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -