ExampleReplacement.java

Go to the documentation of this file.
00001 import java.io.*; 00002 00024 public class ExampleReplacement 00025 extends InputReplacement implements ReplacementFactory { 00026 char character; 00027 00033 public String getInputInfo() { 00034 char ch = character; if (ch==0) ch = 'x'; 00035 return ""+ch+ch+ch+ch+ch+ 00036 "… (n times)"; 00037 } 00041 public String getReplacementInfo() { 00042 char ch = character; if (ch==0) ch = 'x'; 00043 return ch+"ⁿ"; 00044 } 00051 public String[] isContinuationOf(String input) { 00052 char ch = character; if (ch==0) ch = input.charAt(0); 00053 int len = input.length(); 00054 for (int i=0; i<len; i++) 00055 if (input.charAt(i)!=ch) return null; 00056 return new String[] { input+ch+"..." }; 00057 } 00063 public String replacesPrefixOf(String input) { 00064 char ch = character; if (ch==0) ch = input.charAt(0); 00065 int len = input.length(); 00066 for (int i=0; i<len; i++) 00067 if (input.charAt(i)!=ch) { 00068 if (i<=1) return null; 00069 return input.substring(0,i); 00070 } 00071 if (len<=1) return null; 00072 return input; 00073 } 00074 private final char digits[] = { 00075 '⁰', '¹', '²', '³', '⁴', '⁵', '⁶', '⁷', '⁸', '⁹' }; 00085 public String getReplacement(String input) { 00086 char ch = character; if (ch==0) ch = input.charAt(0); 00087 int len = input.length(); 00088 int replLen; 00089 for (replLen=0; replLen<len; replLen++) 00090 if (input.charAt(replLen)!=ch) 00091 break; 00092 StringBuffer result = new StringBuffer(); 00093 result.append(ch); 00094 result.append(replLen); 00095 len = result.length(); 00096 for (int i=1; i<len; i++) 00097 result.setCharAt(i,digits[result.charAt(i)-'0']); 00098 return result.toString(); 00099 } 00100 00108 public ExampleReplacement(BufferedReader config) 00109 throws IOException, FileFormatException { 00110 String charLine = config.readLine(); 00111 if (charLine==null) 00112 throw new FileFormatException 00113 ("ExampleReplacement (in =JAVAREPLACE) needs a line containing a character"); 00114 if (charLine.equals("any")) { 00115 character = 0; 00116 } else { 00117 if (charLine.length()!=1) 00118 throw new FileFormatException 00119 ("in ExampleReplacement (in =JAVAREPLACE): config line does not contain exactly one character"); 00120 character = charLine.charAt(0); 00121 } 00122 } 00123 }

Generated on Sun Aug 15 11:56:53 2004 for International Input by doxygen 1.3.7