From fc88ce7ff1491eeb6a59f3354f77767132649601 Mon Sep 17 00:00:00 2001 From: Ko van der Sloot Date: Fri, 27 Sep 2024 11:01:44 +0200 Subject: [PATCH] small refactorings --- src/FoLiA-alto.cxx | 8 ++++---- src/FoLiA-stats.cxx | 28 +++++++++++----------------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/FoLiA-alto.cxx b/src/FoLiA-alto.cxx index 00287fb..aa53fb3 100644 --- a/src/FoLiA-alto.cxx +++ b/src/FoLiA-alto.cxx @@ -132,7 +132,7 @@ xmlDoc *docCache::find( const string& f ) const { xmlNode *findPart2Level( const xmlNode *start ){ if ( start && start->next ){ xmlNode *pnt = start->next->children; - while ( pnt != 0 ){ + while ( pnt ){ if ( pnt->type == XML_ELEMENT_NODE && TiCC::Name(pnt) == "String" ){ break; @@ -162,7 +162,7 @@ xmlNode *findPart2Block( const xmlNode *start ){ if ( pnt ){ // found a node "TextLine" pnt = pnt->children; - while ( pnt != 0 ){ + while ( pnt ){ if ( pnt->type == XML_ELEMENT_NODE && TiCC::Name(pnt) == "String" ){ break; @@ -309,7 +309,7 @@ void createFile( folia::FoliaElement *text, int cnt = 0; for ( const auto *line : lv ){ xmlNode *pnt = line->children; - while ( pnt != 0 ){ + while ( pnt ){ if ( pnt->type == XML_ELEMENT_NODE ){ if ( TiCC::Name(pnt) == "String" ){ string sub_t = TiCC::getAttribute( pnt, "SUBS_TYPE" ); @@ -1018,7 +1018,7 @@ void solveBook( const string& altoFile, list lv = TiCC::FindNodes( node, "*[local-name()='TextLine']" ); for ( const auto *line : lv ){ xmlNode *pnt = line->children; - while ( pnt != 0 ){ + while ( pnt ){ if ( pnt->type == XML_ELEMENT_NODE ){ if ( TiCC::Name(pnt) == "String" ){ string sub_t = TiCC::getAttribute( pnt, "SUBS_TYPE" ); diff --git a/src/FoLiA-stats.cxx b/src/FoLiA-stats.cxx index f39c954..300476f 100644 --- a/src/FoLiA-stats.cxx +++ b/src/FoLiA-stats.cxx @@ -117,15 +117,13 @@ void create_agg_list( const map>> map> totals; for ( const auto& wc0 : wcv ){ string lang = wc0.first; - auto cit = wc0.second[ng].begin(); - while( cit != wc0.second[ng].end() ){ - if ( cit->second <= clip ){ + for ( auto const &[str,val] : wc0.second[ng] ){ + if ( val <= clip ){ ++clipped; } else { - totals[cit->first].insert( make_pair(lang, cit->second ) ); + totals[str].insert( make_pair(lang, val ) ); } - ++cit; } } map lang_tot; @@ -207,15 +205,13 @@ void create_wf_list( const map>>& } ofstream os( ofilename ); map> wf; - auto cit = wc0.second[ng].begin(); - while( cit != wc0.second[ng].end() ){ - if ( cit->second <= clip ){ - total_n -= cit->second; + for ( auto const& [str,val] : wc0.second[ng] ){ + if ( val <= clip ){ + total_n -= val; } else { - wf[cit->second].insert( cit->first ); + wf[val].insert( str ); } - ++cit; } unsigned int sum=0; unsigned int types=0; @@ -282,15 +278,13 @@ void create_collected_wf_list( const map 0 ){ - auto cit = wc0.second[ng].begin(); - while( cit != wc0.second[ng].end() ){ - if ( cit->second <= clip ){ - total_n -= cit->second; + for ( const auto& [str,val] : wc0.second[ng] ){ + if ( val <= clip ){ + total_n -= val; } else { - wf[cit->second].insert( cit->first ); + wf[val].insert( str ); } - ++cit; } grand_total_clipped += total_n; }