diff dwtx/jface/util/Util.d @ 70:46a6e0e6ccd4

Merge with d-fied sources of 3.4M7
author Frank Benoit <benoit@tionex.de>
date Thu, 22 May 2008 01:36:46 +0200
parents e0f0aaf75edd
children 5df4896124c7
line wrap: on
line diff
--- a/dwtx/jface/util/Util.d	Mon May 19 13:41:06 2008 +0200
+++ b/dwtx/jface/util/Util.d	Thu May 22 01:36:46 2008 +0200
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2007 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -498,6 +498,43 @@
 
         return defaultString;
     }
+    
+    /**
+     * Foundation replacement for String.replaceAll(*).
+     * 
+     * @param src the starting string.
+     * @param find the string to find.
+     * @param replacement the string to replace.
+     * @return The new string.
+     * @since 3.4
+     */
+    public static final String replaceAll(String src, String find, String replacement) {
+        final int len = src.length();
+        final int findLen = find.length();
+
+        int idx = src.indexOf(find);
+        if (idx < 0) {
+            return src;
+        }
+
+        StringBuffer buf = new StringBuffer();
+        int beginIndex = 0;
+        while (idx !is -1 && idx < len) {
+            buf.append(src.substring(beginIndex, idx));
+            buf.append(replacement);
+            
+            beginIndex = idx + findLen;
+            if (beginIndex < len) {
+                idx = src.indexOf(find, beginIndex);
+            } else {
+                idx = -1;
+            }
+        }
+        if (beginIndex<len) {
+            buf.append(src.substring(beginIndex, (idxis-1?len:idx)));
+        }
+        return buf.toString();
+    }
 
     /**
      * This class should never be constructed.