From f3517ba851a2de28d0e099e1c9ed55e6247dd187 Mon Sep 17 00:00:00 2001
From: mkuppe
Date: Thu, 12 Feb 2009 13:56:43 +0000
Subject: NEW - bug 264126: BREE should include Foundation 1.1 as much as
possible https://bugs.eclipse.org/bugs/show_bug.cgi?id=264126
---
.../src/org/eclipse/ecf/core/util/StringUtils.java | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
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 null
.
+ * @param target the target to search for in the start string. Must not be null
.
+ * @param replace the replacement string to substitute when the target is found. Must not be null
.
+ * @return String result. Will not be null
. 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());
+ }
}
--
cgit v1.2.3