Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkuppe2009-02-12 08:56:43 -0500
committermkuppe2009-02-12 08:56:43 -0500
commitf3517ba851a2de28d0e099e1c9ed55e6247dd187 (patch)
treec212103ecc10d8556534d8bf5664516253637673 /framework
parent9fccc5a22b711e41fabec1afdbae8fba2a90d426 (diff)
downloadorg.eclipse.ecf-f3517ba851a2de28d0e099e1c9ed55e6247dd187.tar.gz
org.eclipse.ecf-f3517ba851a2de28d0e099e1c9ed55e6247dd187.tar.xz
org.eclipse.ecf-f3517ba851a2de28d0e099e1c9ed55e6247dd187.zip
NEW - bug 264126: BREE should include Foundation 1.1 as much as possible
https://bugs.eclipse.org/bugs/show_bug.cgi?id=264126
Diffstat (limited to 'framework')
-rw-r--r--framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/StringUtils.java20
1 files changed, 19 insertions, 1 deletions
diff --git a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/StringUtils.java b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/StringUtils.java
index dc7c76998..bb5685c33 100644
--- a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/StringUtils.java
+++ b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/StringUtils.java
@@ -253,5 +253,23 @@ public final class StringUtils {
return string;
return string.substring(0, index) + replace + replaceAllIgnoreCase(string.substring(index + target.length()), target, replace);
}
-
+
+ /**
+ * Returns the string resulting from replacing the first occurrences of the target with the replace
+ * string. Note that the target matches literally, and this is not the same behavior as the
+ * String.replaceAll, which uses regular expressions for doing the matching.
+ * @param string the start string. Must not be <code>null</code>.
+ * @param target the target to search for in the start string. Must not be <code>null</code>.
+ * @param replace the replacement string to substitute when the target is found. Must not be <code>null</code>.
+ * @return String result. Will not be <code>null</code>. If target is not found in the given string,
+ * then the result will be the entire input string.
+ *
+ * @since 3.0
+ */
+ public static String replaceFirst(String string, String target, String replace) {
+ final int index = string.indexOf(target);
+ if (index == -1)
+ return string;
+ return string.substring(0, index) + replace + string.substring(index + target.length());
+ }
}

Back to the top