Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Pazderski2019-10-04 14:38:18 +0000
committerPaul Pazderski2019-10-04 14:46:52 +0000
commit1363fef4438fcbeeff43bdfc8f2503f7e16881de (patch)
tree79039275d48a5e13328cf0282a417450af06801d
parentf759612dc8cad1ee3c57f234defb33606c5ea90e (diff)
downloadeclipse.platform.text-1363fef4438fcbeeff43bdfc8f2503f7e16881de.tar.gz
eclipse.platform.text-1363fef4438fcbeeff43bdfc8f2503f7e16881de.tar.xz
eclipse.platform.text-1363fef4438fcbeeff43bdfc8f2503f7e16881de.zip
Change-Id: I2673f7ee6b18d2705d6353054ec042a1fe6a1f9c Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
-rw-r--r--org.eclipse.text.tests/src/org/eclipse/text/tests/TextUtilitiesTest.java44
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/AbstractLineTracker.java3
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java32
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindNextAction.java2
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java2
5 files changed, 44 insertions, 39 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 1292ecf3d..05f752eb2 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
@@ -20,11 +20,11 @@ import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
+import org.eclipse.jface.text.AbstractLineTracker.DelimiterInfo;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.DocumentEvent;
@@ -347,45 +347,45 @@ public class TextUtilitiesTest {
@Test
public void testNextDelimiter() {
- Map.Entry<Integer, String> result;
+ DelimiterInfo result;
result = TextUtilities.nextDelimiter("abc\ndef", 0);
- assertEquals(3, result.getKey().intValue());
- assertEquals("\n", result.getValue());
+ assertEquals(3, result.delimiterIndex);
+ assertEquals("\n", result.delimiter);
result = TextUtilities.nextDelimiter("abc\ndef", 5);
- assertEquals(-1, result.getKey().intValue());
- assertEquals(null, result.getValue());
+ assertEquals(-1, result.delimiterIndex);
+ assertEquals(null, result.delimiter);
result = TextUtilities.nextDelimiter("abc\rdef\n123", 0);
- assertEquals(3, result.getKey().intValue());
- assertEquals("\r", result.getValue());
+ assertEquals(3, result.delimiterIndex);
+ assertEquals("\r", result.delimiter);
result = TextUtilities.nextDelimiter("abc+\r\ndef\n123", 0);
- assertEquals(4, result.getKey().intValue());
- assertEquals("\r\n", result.getValue());
+ assertEquals(4, result.delimiterIndex);
+ assertEquals("\r\n", result.delimiter);
result = TextUtilities.nextDelimiter("abc~>\r\r\ndef\n123", 0);
- assertEquals(5, result.getKey().intValue());
- assertEquals("\r", result.getValue());
+ assertEquals(5, result.delimiterIndex);
+ assertEquals("\r", result.delimiter);
result = TextUtilities.nextDelimiter("\nabc~>\r\r\ndef\n123", 0);
- assertEquals(0, result.getKey().intValue());
- assertEquals("\n", result.getValue());
+ assertEquals(0, result.delimiterIndex);
+ assertEquals("\n", result.delimiter);
result = TextUtilities.nextDelimiter("abc~>123\r\n", 0);
- assertEquals(8, result.getKey().intValue());
- assertEquals("\r\n", result.getValue());
+ assertEquals(8, result.delimiterIndex);
+ assertEquals("\r\n", result.delimiter);
result = TextUtilities.nextDelimiter("abc~>\r\r\ndef\n123", 9);
- assertEquals(11, result.getKey().intValue());
- assertEquals("\n", result.getValue());
+ assertEquals(11, result.delimiterIndex);
+ assertEquals("\n", result.delimiter);
result = TextUtilities.nextDelimiter("", 0);
- assertEquals(-1, result.getKey().intValue());
- assertEquals(null, result.getValue());
+ assertEquals(-1, result.delimiterIndex);
+ assertEquals(null, result.delimiter);
result = TextUtilities.nextDelimiter("abc123", 0);
- assertEquals(-1, result.getKey().intValue());
- assertEquals(null, result.getValue());
+ assertEquals(-1, result.delimiterIndex);
+ assertEquals(null, result.delimiter);
}
}
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/AbstractLineTracker.java b/org.eclipse.text/src/org/eclipse/jface/text/AbstractLineTracker.java
index 88e3ecc65..b13fa0479 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/AbstractLineTracker.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/AbstractLineTracker.java
@@ -46,8 +46,9 @@ public abstract class AbstractLineTracker implements ILineTracker, ILineTrackerE
* Combines the information of the occurrence of a line delimiter. <code>delimiterIndex</code>
* is the index where a line delimiter starts, whereas <code>delimiterLength</code>,
* indicates the length of the delimiter.
+ * @since 3.10
*/
- protected static class DelimiterInfo {
+ public static class DelimiterInfo {
public int delimiterIndex;
public int delimiterLength;
public String delimiter;
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 29e1b3e05..fceca67e3 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java
@@ -13,7 +13,6 @@
*******************************************************************************/
package org.eclipse.jface.text;
-import java.util.AbstractMap;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -27,6 +26,7 @@ import java.util.Set;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.text.AbstractLineTracker.DelimiterInfo;
/**
* A collection of text functions.
@@ -63,7 +63,7 @@ public class TextUtilities {
* @return the line delimiter
*/
public static String determineLineDelimiter(String text, String hint) {
- String delimiter = nextDelimiter(text, 0).getValue();
+ String delimiter = nextDelimiter(text, 0).delimiter;
return delimiter != null ? delimiter : hint;
}
@@ -593,32 +593,36 @@ public class TextUtilities {
*
* @param text the text to be searched. Not <code>null</code>.
* @param offset the offset in text at which to start the search
- * @return a <code>Map.Entry&lt;Integer, String&gt;</code> where key is index of found delimiter
- * or <code>-1</code> if non found and value is the delimiter found or <code>null</code>
- * if non found. The return value itself is never <code>null</code>.
+ * @return a {@link DelimiterInfo}. If no delimiter was found
+ * {@link DelimiterInfo#delimiterIndex} is <code>-1</code> and
+ * {@link DelimiterInfo#delimiter} is <code>null</code>.
* @since 3.10
*/
- public static Map.Entry<Integer, String> nextDelimiter(CharSequence text, int offset) {
- int delimiterIndex= -1;
- String delimiter= null;
+ public static DelimiterInfo nextDelimiter(CharSequence text, int offset) {
+ final DelimiterInfo info= new DelimiterInfo();
char ch;
final int length= text.length();
for (int i= offset; i < length; i++) {
ch= text.charAt(i);
if (ch == '\r') {
- delimiterIndex= i;
+ info.delimiterIndex= i;
if (i + 1 < length && text.charAt(i + 1) == '\n') {
- delimiter= DELIMITERS[2];
+ info.delimiter= DELIMITERS[2];
break;
}
- delimiter= DELIMITERS[1];
+ info.delimiter= DELIMITERS[1];
break;
} else if (ch == '\n') {
- delimiterIndex= i;
- delimiter= DELIMITERS[0];
+ info.delimiterIndex= i;
+ info.delimiter= DELIMITERS[0];
break;
}
}
- return new AbstractMap.SimpleImmutableEntry<>(Integer.valueOf(delimiterIndex), delimiter);
+ if (info.delimiter == null) {
+ info.delimiterIndex= -1;
+ } else {
+ info.delimiterLength= info.delimiter.length();
+ }
+ return info;
}
}
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindNextAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindNextAction.java
index 9276b7710..76b3c0d49 100644
--- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindNextAction.java
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindNextAction.java
@@ -398,7 +398,7 @@ public class FindNextAction extends ResourceAction implements IUpdate {
*/
private String getFirstLine(String selection) {
if (!selection.isEmpty()) {
- int delimiterOffset = TextUtilities.nextDelimiter(selection, 0).getKey().intValue();
+ int delimiterOffset = TextUtilities.nextDelimiter(selection, 0).delimiterIndex;
if (delimiterOffset > 0)
return selection.substring(0, delimiterOffset);
}
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java
index 937dce647..6b65bafd2 100644
--- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java
@@ -1048,7 +1048,7 @@ class FindReplaceDialog extends Dialog {
*/
private String getFirstLine(String selection) {
if (!selection.isEmpty()) {
- int delimiterOffset = TextUtilities.nextDelimiter(selection, 0).getKey().intValue();
+ int delimiterOffset = TextUtilities.nextDelimiter(selection, 0).delimiterIndex;
if (delimiterOffset > 0)
return selection.substring(0, delimiterOffset);
else if (delimiterOffset == -1)

Back to the top