Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Pazderski2019-09-11 19:01:05 +0000
committerPaul Pazderski2019-09-11 19:12:18 +0000
commit9ab9a34a4ad3f57abb6f67f137f41fe06e57d029 (patch)
treeb079d4947225ac71dc7ffcff362d329a1fb36489
parent649437b71ca4d7ef65fa24637e1f67f15a9bc723 (diff)
downloadeclipse.platform.text-9ab9a34a4ad3f57abb6f67f137f41fe06e57d029.tar.gz
eclipse.platform.text-9ab9a34a4ad3f57abb6f67f137f41fe06e57d029.tar.xz
eclipse.platform.text-9ab9a34a4ad3f57abb6f67f137f41fe06e57d029.zip
Bug 550471 - Improve compatibility of new TextUtilities.indexOfI20190912-1800
Old implementation allowed negative offsets then the improved variant must also. Change-Id: Idf732397d62419690f3f870e590178b3ff0bcbbd Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
-rw-r--r--org.eclipse.text.tests/src/org/eclipse/text/tests/TextUtilitiesTest.java19
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java13
2 files changed, 28 insertions, 4 deletions
diff --git a/org.eclipse.text.tests/src/org/eclipse/text/tests/TextUtilitiesTest.java b/org.eclipse.text.tests/src/org/eclipse/text/tests/TextUtilitiesTest.java
index cdec2582a2e..1292ecf3d18 100644
--- a/org.eclipse.text.tests/src/org/eclipse/text/tests/TextUtilitiesTest.java
+++ b/org.eclipse.text.tests/src/org/eclipse/text/tests/TextUtilitiesTest.java
@@ -281,6 +281,10 @@ public class TextUtilitiesTest {
@SuppressWarnings("deprecation")
public void testIndexOf() {
int[] result;
+ result = TextUtilities.indexOf(new String[0], "xxxxxxxxxx", 0);
+ assertEquals(-1, result[0]);
+ assertEquals(-1, result[1]);
+
result = TextUtilities.indexOf(new String[] { "a", "ab", "abc" }, "xxxxxxxxxx", 0);
assertEquals(-1, result[0]);
assertEquals(-1, result[1]);
@@ -311,6 +315,14 @@ public class TextUtilitiesTest {
assertEquals(0, result[0]);
assertEquals(0, result[1]);
+ result = TextUtilities.indexOf(new String[] { "abc" }, "foobarabcd", -5);
+ assertEquals(6, result[0]);
+ assertEquals(0, result[1]);
+
+ result = TextUtilities.indexOf(new String[] { "abc" }, "foobarabcd", 20);
+ assertEquals(-1, result[0]);
+ assertEquals(-1, result[1]);
+
try {
TextUtilities.indexOf(null, "foobarabcd", 0);
fail("Exception not thrown");
@@ -324,6 +336,13 @@ public class TextUtilitiesTest {
} catch (NullPointerException ex) {
// expected
}
+
+ try {
+ TextUtilities.indexOf(new String[] { "abc" }, null, 0);
+ fail("Exception not thrown");
+ } catch (NullPointerException ex) {
+ // expected
+ }
}
@Test
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java b/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java
index 733c831cb00..29e1b3e0578 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java
@@ -81,10 +81,12 @@ public class TextUtilities {
* @deprecated use {@link MultiStringMatcher#indexOf(CharSequence, int, String...)} instead.
* Notable differences:
* <ul>
- * <li>new indexOf will tolerate <code>null</code> and empty search strings (old
- * accepted empty but throw on <code>null</code>)</li>
- * <li>new indexOf will <b>not</b> match empty string (old matched empty if nothing
- * else matched)</li>
+ * <li>new matcher indexOf does not allow negative offsets (old matcher treated them
+ * as <code>0</code>)</li>
+ * <li>new matcher indexOf will tolerate <code>null</code> and empty search strings
+ * (old accepted empty but throw on <code>null</code>)</li>
+ * <li>new matcher indexOf will <b>not</b> match empty string (old matched empty if
+ * nothing else matched)</li>
* </ul>
* For the common case of searching the next default {@link #DELIMITERS delimiter}
* use the optimized {@link #nextDelimiter(CharSequence, int)} method instead.
@@ -98,6 +100,9 @@ public class TextUtilities {
for (String searchString : searchStrings) {
Objects.requireNonNull(searchString);
}
+ if (offset < 0) {
+ offset = 0; // for compatibility with old implementation
+ }
final MultiStringMatcher.Match match= MultiStringMatcher.indexOf(text, offset, searchStrings);
if (match != null) {
for (int i= 0; i < searchStrings.length; i++) {

Back to the top