This is an automated email from the ASF dual-hosted git repository.
pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git
The following commit(s) were added to refs/heads/trunk by this push:
new dedd1ce96e add StringUtil.equalsIgnoreCase that uses root locale
dedd1ce96e is described below
commit dedd1ce96e123aaf1f10748d589bf67b514708d3
Author: PJ Fanning <[email protected]>
AuthorDate: Fri Jun 12 10:42:23 2026 +0100
add StringUtil.equalsIgnoreCase that uses root locale
---
.../main/java/org/apache/poi/util/StringUtil.java | 25 ++++++++++++++++++++++
.../java/org/apache/poi/util/TestStringUtil.java | 14 ++++++++++++
2 files changed, 39 insertions(+)
diff --git a/poi/src/main/java/org/apache/poi/util/StringUtil.java
b/poi/src/main/java/org/apache/poi/util/StringUtil.java
index cf9524f0a4..ad263c3355 100644
--- a/poi/src/main/java/org/apache/poi/util/StringUtil.java
+++ b/poi/src/main/java/org/apache/poi/util/StringUtil.java
@@ -348,22 +348,47 @@ public final class StringUtil {
return haystack.regionMatches(true, start, suffix, 0, length);
}
+ /**
+ * Uses Locale.ROOT
+ */
@Internal
public static String toLowerCase(char c) {
return Character.toString(c).toLowerCase(Locale.ROOT);
}
+ /**
+ * Uses Locale.ROOT
+ */
@Internal
public static String toUpperCase(char c) {
return Character.toString(c).toUpperCase(Locale.ROOT);
}
+ /**
+ * Uses Locale.ROOT
+ */
@Internal
public static boolean isUpperCase(char c) {
String s = Character.toString(c);
return s.toUpperCase(Locale.ROOT).equals(s);
}
+ /**
+ * Uses Locale.ROOT. Does null safe checks.
+ * @since 6.0.0
+ */
+ @Internal
+ public static boolean equalsIgnoreCase(String s1, String s2) {
+ if (s1 == null) {
+ return s2 == null;
+ } else if (s2 == null) {
+ return false;
+ } else if (s1.length() != s2.length()) {
+ return false;
+ }
+ return s1.toLowerCase(Locale.ROOT).equals(s2.toLowerCase(Locale.ROOT));
+ }
+
/**
* Some strings may contain encoded characters of the unicode private use
area.
* Currently the characters of the symbol fonts are mapped to the
corresponding
diff --git a/poi/src/test/java/org/apache/poi/util/TestStringUtil.java
b/poi/src/test/java/org/apache/poi/util/TestStringUtil.java
index 82a65b1bfb..f8c5462738 100644
--- a/poi/src/test/java/org/apache/poi/util/TestStringUtil.java
+++ b/poi/src/test/java/org/apache/poi/util/TestStringUtil.java
@@ -152,5 +152,19 @@ class TestStringUtil {
// search for unicode characters
assertEquals(1, StringUtil.countMatches(test, '\u00a9'), "Unicode");
}
+
+ @Test
+ void equalsIgnoreCase() {
+ assertTrue(StringUtil.equalsIgnoreCase(null, null), "2 nulls are
equal");
+ assertFalse(StringUtil.equalsIgnoreCase(null, ""), "null and empty
strings are not equal");
+ assertFalse(StringUtil.equalsIgnoreCase("", null), "null and empty
strings are not equal");
+ assertFalse(StringUtil.equalsIgnoreCase("abc", "abcd"), "different
lengths do not match");
+ assertFalse(StringUtil.equalsIgnoreCase("abcd", "abc"), "different
lengths do not match");
+ assertTrue(StringUtil.equalsIgnoreCase("abc", "abc"), "abc and abc
match");
+ assertTrue(StringUtil.equalsIgnoreCase("abc", "Abc"), "abc and Abc
match");
+ assertFalse(StringUtil.equalsIgnoreCase("İ", "i"), "Turkish dotted İ
and i do not match (root locale)");
+ assertFalse(StringUtil.equalsIgnoreCase("İ", "I"), "Turkish dotted İ
and I do not match (root locale)");
+ assertFalse(StringUtil.equalsIgnoreCase("ı", "I"), "Turkish dotless ı
and I do not match (root locale)");
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]