Skip to content

Commit

Permalink
improve debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
kosloot committed Oct 29, 2024
1 parent 7787bea commit 5cb1ea4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/libfolia/folia_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ namespace folia {
KWargs getArgs( const std::string& );
std::string toString( const KWargs& );

void addAttributes( const xmlNode *, const KWargs& );
void addAttributes( const xmlNode *, const KWargs&, bool=false );
KWargs getAttributes( const xmlNode * );

std::string parseDate( const std::string& );
Expand Down
2 changes: 1 addition & 1 deletion src/folia_document.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3235,7 +3235,7 @@ namespace folia {
if ( debug == SERIALIZE ){
cerr << "to_xmlDoc: add attributes to root: " << attribs << endl;
}
addAttributes( root, attribs );
addAttributes( root, attribs, debug == SERIALIZE );
xmlNode *md = xmlAddChild( root, TiCC::XmlNewNode( foliaNs(), "metadata" ) );
add_annotations( md );
add_provenance( md );
Expand Down
17 changes: 16 additions & 1 deletion src/folia_utils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -416,37 +416,52 @@ namespace folia {
return atts;
}

void addAttributes( const xmlNode *_node, const KWargs& atts ){
void addAttributes( const xmlNode *_node,
const KWargs& atts,
bool debug ){
/// add all attributes from 'atts' as attribute nodes to 'node`
/*!
\param _node The xmlNode to add to
\param atts The list of attribute/value pairs
\param debug do we want to debug? (default false)
some special care is taken for attributes 'xml:id', 'id' and 'lang'
*/
xmlNode *node = const_cast<xmlNode*>(_node); // strange libxml2 interface
KWargs attribs = atts;
auto it = attribs.find("xml:id");
if ( it != attribs.end() ){ // xml:id is special
if ( debug ){
cerr << "set xml:id " << it->second << endl;
}
xmlSetProp( node,
XML_XML_ID,
to_xmlChar(it->second) );
attribs.erase(it);
}
it = attribs.find("lang");
if ( it != attribs.end() ){ // lang is special too
if ( debug ){
cerr << "set lang " << it->second << endl;
}
xmlNodeSetLang( node,
to_xmlChar(it->second) );
attribs.erase(it);
}
it = attribs.find("id");
if ( it != attribs.end() ){
if ( debug ){
cerr << "set id " << it->second << endl;
}
xmlSetProp( node,
to_xmlChar("id"),
to_xmlChar(it->second) );
attribs.erase(it);
}
// and now the rest
for ( const auto& [at,val] : attribs ){
if ( debug ){
cerr << "add attribute: [" << at << "," << val << "]" << endl;
}
xmlSetProp( node,
to_xmlChar(at),
to_xmlChar(val) );
Expand Down

0 comments on commit 5cb1ea4

Please sign in to comment.