From aa28b87b8a93cf825ee8fc4242a05fe7a14b938f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Dr=C3=B6ge?= Date: Wed, 6 Apr 2016 19:37:55 +0200 Subject: [PATCH] fix #43 (path ending with semicolon) --- taxknife.cpp | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/taxknife.cpp b/taxknife.cpp index b5fdf8a..501a049 100644 --- a/taxknife.cpp +++ b/taxknife.cpp @@ -292,15 +292,25 @@ int main( int argc, char** argv ) { taxid = boost::lexical_cast< TaxonID >( *field_it ); node = interface.getNode( taxid ); cout << buffer.str(); + const TaxonNode* root = interface.getRoot(); - for ( Taxonomy::CPathDownIterator it( root, node ); it != node; ++it ) { - if ( allnodes || it->data->mark_special ) { - if( it->data->annotation ) cout << it->data->annotation->name << ';'; - else cout << "node_without_annotation;"; + Taxonomy::CPathDownIterator it( root, node ); + while(true) { + if (allnodes || it->data->mark_special) { + if( it->data->annotation ) cout << it->data->annotation->name; + else cout << "node_without_annotation"; + break; } + if(it == node) break; + ++it; } - if ( allnodes || node->data->mark_special ) cout << node->data->annotation->name << ';'; - if ( ! (++field_it)->empty() ) cout << default_field_separator << *field_it; + while ( it != node ) { + ++it; + if ( allnodes || it->data->mark_special ) { + if( it->data->annotation ) cout << ';' << it->data->annotation->name; + else cout << ";node_without_annotation"; + } + }; cout << endl; } catch ( TaxonNotFound& ) { @@ -341,12 +351,21 @@ int main( int argc, char** argv ) { taxid = boost::lexical_cast< TaxonID >( *field_it ); node = interface.getNode( taxid ); cout << buffer.str(); + const TaxonNode* root = interface.getRoot(); - for ( Taxonomy::CPathDownIterator it( root, node ); it != node; ++it ) { - if ( allnodes || it->data->mark_special ) cout << it->data->taxid << ';'; + Taxonomy::CPathDownIterator it( root, node ); + while(true) { + if (allnodes || it->data->mark_special) { + cout << it->data->taxid; + break; + } + if(it == node) break; + ++it; } - if ( allnodes || node->data->mark_special ) cout << node->data->taxid << ';'; - if ( ! (++field_it)->empty() ) cout << default_field_separator << *field_it; + while ( it != node ) { + ++it; + if ( allnodes || it->data->mark_special ) cout << ';' << it->data->taxid; + }; cout << endl; } catch ( TaxonNotFound& ) {