Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNitin Dahyabhai2020-01-08 15:20:56 +0000
committerNitin Dahyabhai2020-01-08 15:20:56 +0000
commitc6ebbaa292c1d25523cda24316b299eb8ddd43fc (patch)
tree7b1a310c352a6feb9702549250fcd864b396caf7
parenteecb7ca88cf1ead6f1e0c1217f4298009c77e9a0 (diff)
downloadwebtools.sourceediting-c6ebbaa292c1d25523cda24316b299eb8ddd43fc.tar.gz
webtools.sourceediting-c6ebbaa292c1d25523cda24316b299eb8ddd43fc.tar.xz
webtools.sourceediting-c6ebbaa292c1d25523cda24316b299eb8ddd43fc.zip
[nobug] add a first line truncator to the StringUtils
-rw-r--r--core/bundles/org.eclipse.wst.sse.core/META-INF/MANIFEST.MF2
-rw-r--r--core/bundles/org.eclipse.wst.sse.core/pom.xml2
-rw-r--r--core/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/utils/StringUtils.java61
3 files changed, 53 insertions, 12 deletions
diff --git a/core/bundles/org.eclipse.wst.sse.core/META-INF/MANIFEST.MF b/core/bundles/org.eclipse.wst.sse.core/META-INF/MANIFEST.MF
index 604a84364e..2469d4b93f 100644
--- a/core/bundles/org.eclipse.wst.sse.core/META-INF/MANIFEST.MF
+++ b/core/bundles/org.eclipse.wst.sse.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.wst.sse.core; singleton:=true
-Bundle-Version: 1.2.100.qualifier
+Bundle-Version: 1.2.200.qualifier
Bundle-Activator: org.eclipse.wst.sse.core.internal.SSECorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
diff --git a/core/bundles/org.eclipse.wst.sse.core/pom.xml b/core/bundles/org.eclipse.wst.sse.core/pom.xml
index 78b2fa40ce..65f2f8b68a 100644
--- a/core/bundles/org.eclipse.wst.sse.core/pom.xml
+++ b/core/bundles/org.eclipse.wst.sse.core/pom.xml
@@ -21,7 +21,7 @@
<groupId>org.eclipse.webtools.sourceediting</groupId>
<artifactId>org.eclipse.wst.sse.core</artifactId>
- <version>1.2.100-SNAPSHOT</version>
+ <version>1.2.200-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<build>
diff --git a/core/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/utils/StringUtils.java b/core/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/utils/StringUtils.java
index 83feb7ec37..3f054c01b4 100644
--- a/core/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/utils/StringUtils.java
+++ b/core/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/utils/StringUtils.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2001, 2018 IBM Corporation and others.
+ * Copyright (c) 2001, 2019 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -15,11 +15,8 @@
*******************************************************************************/
package org.eclipse.wst.sse.core.utils;
-
-
import java.util.ArrayList;
import java.util.List;
-import com.ibm.icu.util.StringTokenizer;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
@@ -27,6 +24,8 @@ import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.wst.sse.core.internal.Logger;
+import com.ibm.icu.util.StringTokenizer;
+
public class StringUtils {
protected static final String AMPERSTAND = "&"; //$NON-NLS-1$
@@ -224,7 +223,7 @@ public class StringUtils {
String newText = ""; //$NON-NLS-1$
int lineCount = tempDoc.getNumberOfLines();
- StringBuffer sb = new StringBuffer(newText);
+ StringBuilder sb = new StringBuilder(newText);
for (int i = 0; i < lineCount; i++) {
try {
org.eclipse.jface.text.IRegion lineInfo = tempDoc.getLineInformation(i);
@@ -283,7 +282,7 @@ public class StringUtils {
public static String escape(String normalString) {
if (normalString == null)
return null;
- StringBuffer escapedBuffer = new StringBuffer();
+ StringBuilder escapedBuffer = new StringBuilder();
StringTokenizer toker = new StringTokenizer(normalString, EQUAL_SIGN + LINE_FEED + CARRIAGE_RETURN + LINE_TAB, true);
String chunk = null;
while (toker.hasMoreTokens()) {
@@ -309,7 +308,7 @@ public class StringUtils {
/**
* Returns the first line of the given text without a trailing delimiter
- *
+ *
* @param text
* @return
*/
@@ -329,6 +328,48 @@ public class StringUtils {
return text;
}
+ /**
+ * Returns the first line of the given text, up to a certain length, appending ellipses as indicated
+ *
+ * @return
+ */
+ public static final String firstLine(String s, int limit, boolean appendEllipsesIfExceeded) {
+ int lineSeparatorIndex = 0;
+ int fullLength = s.length();
+ int startOffset = -1;
+ do {
+ startOffset++;
+ }
+ while (startOffset < fullLength && Character.isWhitespace(s.charAt(startOffset)));
+
+ if (startOffset == fullLength) {
+ return ""; //$NON-NLS-1$
+ }
+
+ // find the first line delimiter
+ if ((lineSeparatorIndex = s.indexOf('\r', startOffset)) < 0) {
+ lineSeparatorIndex = s.indexOf('\n', startOffset);
+ }
+
+ if (lineSeparatorIndex > 0) {
+ if (appendEllipsesIfExceeded) {
+ return s.substring(startOffset, Math.min(startOffset + limit, lineSeparatorIndex)).concat("...");
+ }
+ else {
+ return s.substring(startOffset, Math.min(startOffset + limit, lineSeparatorIndex));
+ }
+ }
+ else if (fullLength - startOffset > limit) {
+ if (appendEllipsesIfExceeded) {
+ return s.substring(startOffset, startOffset + limit).concat("...");
+ }
+ else {
+ return s.substring(startOffset, startOffset + limit);
+ }
+ }
+ return s;
+ }
+
public static int indexOfLastLineDelimiter(String aString) {
return indexOfLastLineDelimiter(aString, aString.length());
}
@@ -507,7 +548,7 @@ public class StringUtils {
* @todo Generated comment
*/
public static String pack(String[] strings) {
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder();
for (int i = 0; i < strings.length; i++) {
buf.append(StringUtils.replace(strings[i], ",", "&comma;")); //$NON-NLS-1$ //$NON-NLS-2$
if (i < strings.length - 1)
@@ -522,7 +563,7 @@ public class StringUtils {
*/
public static String paste(String oldText, String newText, int start, int length) {
String result = null;
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
int startIndex = start;
int endIndex = start + length;
if (startIndex > oldText.length()) {
@@ -552,7 +593,7 @@ public class StringUtils {
int position = 0;
int previous = 0;
int spacer = source.length();
- StringBuffer sb = new StringBuffer(normalString);
+ StringBuilder sb = new StringBuilder(normalString);
while (position + spacer - 1 < length && aString.indexOf(source, position) > -1) {
position = aString.indexOf(source, previous);
sb.append(normalString);

Back to the top