Skip to main content
added 4 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369

The following should make the definition of an impropera reject string clear without dragging you through needless details:

Relieved of the need to call filterStringOut() the requirement test functions become shorter and their names are much simpler. I've also put everything they're dependantdependent on in their parameter list to make it easier to understand them without looking inside.

I think you'll find any of these more readable than nested for loops. CombinedThose, combined with the if's and you, were starting to havegive you a real arrow anti-pattern. I think the lesson here is that tiny functions are a good thing.

The following should make the definition of an improper string clear without dragging you through needless details:

Relieved of the need to call filterStringOut() the requirement test functions become shorter and their names are much simpler. I've also put everything they're dependant on in their parameter list to make it easier to understand them without looking inside.

I think you'll find any of these more readable than nested for loops. Combined with the if's and you were starting to have a real arrow anti-pattern. I think the lesson here is that tiny functions are a good thing.

The following should make the definition of a reject string clear without dragging you through needless details:

Relieved of the need to call filterStringOut() the requirement test functions become shorter and their names are much simpler. I've also put everything they're dependent on in their parameter list to make it easier to understand them without looking inside.

I think you'll find any of these more readable than nested for loops. Those, combined with the if's, were starting to give you a real arrow anti-pattern. I think the lesson here is that tiny functions are a good thing.

added 1 character in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
void ParsingTools::filterStrings(QStringList &sl)
{
    for (int i=0; i<sl.length(); i++) {
        QString s = sl.at(i);
        if ( isRejectString(s) ) {
            filterStringOut(i);
        }
    }
}
void ParsingTools::filterStrings(QStringList &sl)
{
    for (int i=0; i<sl.length(); i++) {
        QString s = sl.at(i);
        if( isRejectString(s) ) {
            filterStringOut(i);
        }
    }
}
void ParsingTools::filterStrings(QStringList &sl)
{
    for (int i=0; i<sl.length(); i++) {
        QString s = sl.at(i);
        if ( isRejectString(s) ) {
            filterStringOut(i);
        }
    }
}
deleted 3 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
void ParsingTools::filterStrings(QStringList &sl)
{
    for (int i=0; i<sl.length(); i++) {
        QString s = sl.at(i);
        if( isImproperStringisRejectString(s) ) {
            filterStringOut(i);
        }
    }
}
bool isImproperStringisRejectString(QString s) {
    return isImproperLengthisDifferentLength(s, m_Length) 
        || sansRequiredSubstring(s, m_Include)
        || hasForbiddenSubstring(s, m_Exclude)
    ;
}
bool isImproperLengthisDifferentLength(QString s, int length) {
    return ( s.length() != length );
}

bool sansRequiredSubstring(QString s, QStringList &include) {
    for (int j=0; j<include.length(); j++) {
        QString requiredSubstring = include.at(j);
        if ( !s.contains(requiredSubstring) ) { 
            return true; 
        }
    }
    return false;
}

bool hasForbiddenSubstring(QString s, QStringList &exclude) {
    for (int j=0; j<exclude.length(); j++) {
    QString forbiddenSubstring = exclude.at(j);
        if ( s.contains(forbiddenSubstring) ) { 
            return true; 
        }
    }
    return false;
}
void ParsingTools::filterStrings(QStringList &sl)
{
    for (int i=0; i<sl.length(); i++) {
        QString s = sl.at(i);
        if( isImproperString(s) ) {
            filterStringOut(i);
        }
    }
}
bool isImproperString(QString s) {
    return isImproperLength(s, m_Length) 
        || sansRequiredSubstring(s, m_Include)
        || hasForbiddenSubstring(s, m_Exclude)
    ;
}
bool isImproperLength(QString s, int length) {
    return ( s.length() != length );
}

bool sansRequiredSubstring(QString s, QStringList &include) {
    for (int j=0; j<include.length(); j++) {
        QString requiredSubstring = include.at(j);
        if ( !s.contains(requiredSubstring) ) { 
            return true; 
        }
    }
    return false;
}

bool hasForbiddenSubstring(QString s, QStringList &exclude) {
    for (int j=0; j<exclude.length(); j++) {
    QString forbiddenSubstring = exclude.at(j);
        if ( s.contains(forbiddenSubstring) ) { 
            return true; 
        }
    }
    return false;
}
void ParsingTools::filterStrings(QStringList &sl)
{
    for (int i=0; i<sl.length(); i++) {
        QString s = sl.at(i);
        if( isRejectString(s) ) {
            filterStringOut(i);
        }
    }
}
bool isRejectString(QString s) {
    return isDifferentLength(s, m_Length) 
        || sansRequiredSubstring(s, m_Include)
        || hasForbiddenSubstring(s, m_Exclude)
    ;
}
bool isDifferentLength(QString s, int length) {
    return ( s.length() != length );
}

bool sansRequiredSubstring(QString s, QStringList &include) {
    for (int j=0; j<include.length(); j++) {
        QString requiredSubstring = include.at(j);
        if ( !s.contains(requiredSubstring) ) { 
            return true; 
        }
    }
    return false;
}

bool hasForbiddenSubstring(QString s, QStringList &exclude) {
    for (int j=0; j<exclude.length(); j++) {
    QString forbiddenSubstring = exclude.at(j);
        if ( s.contains(forbiddenSubstring) ) { 
            return true; 
        }
    }
    return false;
}
added 5 characters in body
Source Link
kevin cline
  • 33.9k
  • 3
  • 73
  • 143
Loading
edited body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
Loading
added 163 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
Loading
added 60 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
Loading
deleted 2 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
Loading
deleted 12 characters in body; deleted 2 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
Loading
added 11 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
Loading
deleted 1 character in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
Loading
added 108 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
Loading
added 2 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
Loading
added 139 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
Loading
added 67 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
Loading
added 24 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
Loading
added 35 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
Loading
added 22 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
Loading
added 54 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
Loading
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
Loading