Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 cdec2582a..1292ecf3d 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 733c831cb..29e1b3e05 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