Skip to content

Commit

Permalink
cleared out last cppcheck warning (with a nifty solution)
Browse files Browse the repository at this point in the history
  • Loading branch information
kosloot committed Jun 10, 2023
1 parent c63ab45 commit d78b097
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
12 changes: 8 additions & 4 deletions include/frog/mblem_mod.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@

/// \brief Helper class for Mblem. A datastructure to hold lemma/tag information
class mblemData {
public:
mblemData( const icu::UnicodeString& l, const icu::UnicodeString& t ):
lemma( l ),
public:
mblemData( const icu::UnicodeString& l, const icu::UnicodeString& t ):
lemma( l ),
tag( t ) { };
icu::UnicodeString getLemma() const { return lemma; };
icu::UnicodeString getTag() const { return tag; };
private:
bool operator==( const mblemData& rhs ){
return ( lemma == rhs.lemma )
&& ( tag == rhs.tag );
}
private:
icu::UnicodeString lemma;
icu::UnicodeString tag;
};
Expand Down
31 changes: 8 additions & 23 deletions src/mblem_mod.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -322,34 +322,19 @@ void Mblem::filterTag( const icu::UnicodeString& postag ){
}
}

bool cmp_lemma( const mblemData& lhs, const mblemData& rhs ){
return lhs.getLemma() == rhs.getLemma();
}

void Mblem::makeUnique( ){
/// filter out all results that are equal
/*
should be called AFTER filterTag() and cleans out doubles
*/
auto it = mblemResult.begin();
while( it != mblemResult.end() ){
UnicodeString lemma = it->getLemma();
auto it2 = it+1;
while( it2 != mblemResult.end() ){
if (debug > 1){
DBG << "compare lemma " << lemma << " with " << it2->getLemma() << " ";
}
if ( lemma == it2->getLemma() ){
if ( debug > 1){
DBG << "equal " << endl;
}
it2 = mblemResult.erase(it2);
}
else {
if ( debug > 1){
DBG << "NOT equal! " << endl;
}
++it2;
}
}
++it;
}
// unique shifts unique elements to the front
auto last = std::unique(mblemResult.begin(), mblemResult.end(), cmp_lemma );
// remove the rest
mblemResult.erase( last, mblemResult.end() );
if (debug > 1){
DBG << "final result after filter and unique" << endl;
for ( const auto& mbr : mblemResult ){
Expand Down

0 comments on commit d78b097

Please sign in to comment.