1 /*
2 * Copyright 2007 Werner Guttmann
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.castor.core.util;
17
18 import org.apache.commons.lang.StringUtils;
19
20 /**
21 * Common functionality relate to String processing.
22 *
23 * @since 1.2
24 */
25 public class StringUtil {
26
27 /**
28 * Replaces all occurences of a pattern within a String.
29 * @param source The source string.
30 * @param toReplace The character to replace.
31 * @param replacement The replacement.
32 * @return The new String with characters replaced.
33 */
34 public static String replaceAll(final String source, final String toReplace,
35 final String replacement) {
36 // if (source == null) {
37 // return null;
38 // }
39 // String returnValue = source;
40 // int idx = source.lastIndexOf(toReplace);
41 // if (idx != -1) {
42 // StringBuffer ret = new StringBuffer(source);
43 // ret.replace(idx, idx + toReplace.length(), replacement);
44 // while ((idx = source.lastIndexOf(toReplace, idx - 1)) != -1) {
45 // ret.replace(idx, idx + toReplace.length(), replacement);
46 // }
47 // returnValue = ret.toString();
48 // }
49 // return returnValue;
50 return StringUtils.replace(source, toReplace, replacement);
51 }
52
53 }