I am trying to write a search text implementation in Java
With the below code below:
public String log(Object... source) {...//simple System.out.println for debugging purposes}
public boolean searchInLoweCase(CharSequence searchTag, CharSequence containsTag) {
var contains = containsTag.toString().contains(searchTag);
log("search", "searchTag", searchTag, contains, "containsTag", containsTag);
IntStream.range(0, searchTag.length()).forEachOrdered(charIdx -> {
log("search",
"searchTag[" + charIdx + "].charAt/codePointAt/int", searchTag.charAt(charIdx), searchTag.codePointAt(charIdx), "as", (int) searchTag.charAt(charIdx),
"containsTag[" + charIdx + "].charAt/codePointAt/int", containsTag.charAt(charIdx), searchTag.codePointAt(charIdx), "as", (int) containsTag.charAt(charIdx)
);
});
return contains;
}
the output is
{searchTag, i, true, containsTag, i̇letişim}
{searchTag[0].charAt/codePointAt/int, i, 105, as, 105, containsTag[0].charAt/codePointAt/int, i, 105, as, 105}
the output is
{searchTag, il, false, containsTag, i̇letişim}
{searchTag[0].charAt/codePointAt/int, i, 105, as, 105, containsTag[0].charAt/codePointAt/int, i, 105, as, 105}
{searchTag[1].charAt/codePointAt/int, l, 108, as, 108, containsTag[1].charAt/codePointAt/int, ̇, 108, as, 775}
Here you can see the hidden character there.
I tried to remove the hidden character with answer here;
however it did not work.
Did you exprienced it before?
Implementation
To search strings, one can use equals or contains after uppercasing them with locale tuned.
The Bug:
However, I figured that there is a bug in JDK and Javascript for turkish and german character convertions.
JavaScript:
In JavaScript, one should detect the locale first:
var lng = navigator.language; //tr
According to this answer, one can use below code to uppercase strings in native javascript.
"iıöçşğü".toLocaleUpperCase('tr-TR'); //İIÖÇŞĞÜ
JAVA | GWT:
In Java, one should detect the locale first: (like here)
Locale.getDefault().getLanguage().equals("tr");
Or in Java GWT, one should detect the locale first: (like here)
LocaleInfo.getCurrentLocale().getLocaleName().contains("tr");
Then, according to language detected, If it is an unsupported language, he should use the below fix: (like here)
"iıöçşğü".toUpperCase(Locale.ROOT); //İIÖÇŞĞÜ