Skip to content
Permalink
Browse files
Merge pull request #847 from nadment/HOP-2930
HOP-2930 The ContextDialog should ignore diacritics marks
  • Loading branch information
hansva committed Jun 2, 2021
2 parents e539705 + caf38f9 commit 729d29263ae28741ad8c03bb80f92b457c4dd464
Showing 2 changed files with 19 additions and 2 deletions.
@@ -19,7 +19,7 @@

import org.apache.commons.lang.StringUtils;
import org.apache.hop.core.gui.plugin.IGuiActionLambda;

import org.apache.hop.core.util.StringUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@@ -111,11 +111,14 @@ public boolean containsFilterStrings( String[] filters ) {
}
return true;
}

public boolean containsFilterString( String filter ) {
if ( filter == null ) {
return false;
}

filter = StringUtil.removeDiacriticalMarks(filter);

if ( matchesString( name, filter ) ) {
return true;
}
@@ -140,6 +143,9 @@ private boolean matchesString( String string, String filter ) {
if ( StringUtils.isEmpty( string ) ) {
return false;
}

string = StringUtil.removeDiacriticalMarks(string);

// TODO: consider some fuzzy matching algorithm
// TODO: Do a Levenshtein distance on the filter string across all valid string indexes 0..
return string.toUpperCase().contains( filter.toUpperCase() );
@@ -25,6 +25,7 @@
import java.text.DateFormatSymbols;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.Normalizer;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Collections;
@@ -617,4 +618,14 @@ public static String trimEnd( final String source, char c ) {

return source.substring( 0, index );
}

/**
* Remove diacritical marks from a string (accents and cedilla) and return the same string withour marks.
*
* @param source the {@link String} to clean
* @return the string without marks
*/
public static String removeDiacriticalMarks(String source) {
return Normalizer.normalize(source, Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
}
}

0 comments on commit 729d292

Please sign in to comment.