removeStopWords method
Returns the string without the the stop words in it.
Every word of the stopWords
is removed when found in the string.
Implementation
String removeStopWords(List<String> stopWords) {
/// Does not remove stopwords in empty strings
if (isEmpty) {
return this;
}
/// Removes the [stopWords] from the string.
String manipulated = '$this ';
final splitted = split(' ');
for (final String word in splitted) {
for (final String stopWord in stopWords) {
if (word.toLowerCase() != stopWord.toLowerCase()) {
continue;
}
manipulated = manipulated.replaceAll('$word ', '');
}
}
if (manipulated.isEmpty) {
if (splitted.length == 1) {
return this;
}
return '';
}
// Removes the added space
return manipulated.substring(0, manipulated.length - 1);
}