01: package com.sun.portal.app.filesharing.util;
02:
03: /**
04: * @author Alejandro Abdelnur
05: */
06: public class MaskTranslator {
07:
08: // [*][2], each [2] is a original/new
09:
10: public static String translate(String[][] swaps, String s) {
11: for (int i = 0; i < swaps.length; i++) {
12: s = replace(s, swaps[i][0], swaps[i][1]);
13: }
14: return s;
15: }
16:
17: private static String replace(String s, String o, String n) {
18: StringBuffer sb = new StringBuffer(s.length() * 2);
19: int pos = 0;
20: int i = s.indexOf(o, pos);
21: while (i > -1) {
22: sb.append(s.substring(pos, i));
23: sb.append(n);
24: pos = i + 1;
25: i = s.indexOf(o, pos);
26: }
27: if (s.length() > pos) {
28: sb.append(s.substring(pos));
29: }
30: return sb.toString();
31: }
32:
33: }
|