Change variable view behaviour.
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / util / StringUtil.java
1 /* Created on Jan 19, 2004 */
2 package com.quantum.util;
3
4 import java.util.Arrays;
5
6 /**
7  * @author holmesbc
8  */
9 public class StringUtil {
10         
11         public static String substituteString(String original, String placeHolder, String replacementValue) {
12                 StringBuffer buffer = new StringBuffer();
13                 char[] originalChars = original == null ? new char[0] : original.toCharArray();
14                 char[] placeHolderChars = placeHolder.toCharArray();
15                 char[] placeHolderComparisonArray = new char[placeHolderChars.length];
16                 
17                 for (int i = 0, length = originalChars.length; i < length; i++) {
18                         if (i <= length - placeHolderChars.length) {
19                                 System.arraycopy(originalChars, i, placeHolderComparisonArray, 0, placeHolderComparisonArray.length);
20                                 if (Arrays.equals(placeHolderComparisonArray, placeHolderChars)) {
21                                         i += placeHolderComparisonArray.length - 1;
22                                         buffer.append(replacementValue);
23                                 } else {
24                                         buffer.append(originalChars[i]);
25                                 }
26                         } else {
27                                 buffer.append(originalChars[i]);
28                         }
29                 }
30                 
31                 return original == null ? null : buffer.toString();
32         }
33 }