1 7 8 package com.ibm.icu.text; 9 10 import com.ibm.icu.impl.Utility; 11 12 15 final class RBNFChinesePostProcessor extends RBNFPostProcessor { 16 private NFRuleSet lastRuleSet; 17 private boolean longForm; 18 private int format; 19 20 private static final String [] rulesetNames = { 21 "%traditional", "%simplified", "%accounting", "%time" 22 }; 23 24 28 void init(RuleBasedNumberFormat formatter, String rules) { 29 } 30 31 35 void process(StringBuffer buf, NFRuleSet ruleSet) { 36 38 if (ruleSet != lastRuleSet) { 39 String name = ruleSet.getName(); 40 for (int i = 0; i < rulesetNames.length; ++i) { 41 if (rulesetNames[i].equals(name)) { 42 format = i; 43 longForm = i == 1 || i == 3; 44 break; 45 } 46 } 47 } 48 49 if (longForm) { 50 for (int i = Utility.indexOf(buf,"*"); i != -1; i = Utility.indexOf(buf, "*", i)) { 51 buf.delete(i, i+1); 52 } 53 return; 54 } 55 56 final String DIAN = "\u9ede"; 58 final String [][] markers = { 59 { "\u842c", "\u5104", "\u5146", "\u3007" }, { "\u4e07", "\u4ebf", "\u5146", "\u3007" }, 61 { "\u842c", "\u5104", "\u5146", "\u96f6" } 62 }; 64 65 72 80 { 82 String [] m = markers[format]; 83 for (int i = 0; i < m.length-1; ++i) { 84 int n = Utility.indexOf(buf, m[i]); 85 if (n != -1) { 86 buf.insert(n+m[i].length(), '|'); 87 } 88 } 89 } 90 91 int x = Utility.indexOf(buf, DIAN); 92 if (x == -1) { 93 x = buf.length(); 94 } 95 int s = 0; int n = -1; String ling = markers[format][3]; 98 while (x >= 0) { 99 int m = Utility.lastIndexOf(buf, "|", x); 100 int nn = Utility.lastIndexOf(buf, ling, x); 101 int ns = 0; 102 if (nn > m) { 103 ns = (nn > 0 && buf.charAt(nn-1) != '*') ? 2 : 1; 104 } 105 x = m - 1; 106 107 switch (s*3+ns) { 109 case 0: 110 s = ns; n = -1; 112 break; 113 case 1: 114 s = ns; 115 n = nn; break; 117 case 2: 118 s = ns; 119 n = -1; 120 break; 121 case 3: 122 s = ns; 123 n = -1; 124 break; 125 case 4: 126 buf.delete(nn-1, nn+ling.length()); s = 0; 128 n = -1; 129 break; 130 case 5: 131 buf.delete(n-1, n+ling.length()); s = ns; 133 n = -1; 134 break; 135 case 6: 136 s = ns; 137 n = -1; 138 break; 139 case 7: 140 buf.delete(nn-1, nn+ling.length()); s = 0; 142 n = -1; 143 break; 144 case 8: 145 s = ns; 146 n = -1; 147 break; 148 default: 149 throw new IllegalStateException (); 150 } 151 } 152 153 for (int i = buf.length(); --i >= 0;) { 154 char c = buf.charAt(i); 155 if (c == '*' || c == '|') { 156 buf.delete(i, i+1); 157 } 158 } 159 } 160 } 161 | Popular Tags |