Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2007-11-30 09:23:23 +0000
committerslewis2007-11-30 09:23:23 +0000
commita9205c8839365365854e9430130226c7dbd57067 (patch)
tree8979d4a6aa2c9c47bc87cf4f99b7e866327eff28 /framework/bundles/org.eclipse.ecf.identity
parent4d945741fc194e6fb6ba1defc4ec92c081118785 (diff)
downloadorg.eclipse.ecf-a9205c8839365365854e9430130226c7dbd57067.tar.gz
org.eclipse.ecf-a9205c8839365365854e9430130226c7dbd57067.tar.xz
org.eclipse.ecf-a9205c8839365365854e9430130226c7dbd57067.zip
Added StringUtils.replaceAll(String,String,String) for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=211463
Diffstat (limited to 'framework/bundles/org.eclipse.ecf.identity')
-rw-r--r--framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/StringUtils.java27
1 files changed, 25 insertions, 2 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 1174daa2f..c32e08c6f 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
@@ -207,7 +207,30 @@ public final class StringUtils {
return string;
}
- public static boolean contains(String string, String seq) {
- return (string.indexOf(seq) != -1);
+ /**
+ * Returns whether the first parameter contains the second parameter.
+ * @param string must not be <code>.
+ * @param target must not be <code> null.
+ * @return true if the target is contained within the string.
+ */
+ public static boolean contains(String string, String target) {
+ return (string.indexOf(target) != -1);
+ }
+
+ /**
+ * Returns the string resulting from replacing all 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.
+ */
+ public static String replaceAll(String string, String target, String replace) {
+ final int index = string.indexOf(target);
+ if (index == -1)
+ return string;
+ return string.substring(0, index) + replace + replaceAll(string.substring(index + replace.length()), target, replace);
}
}

Back to the top