private void compact(CharVector kx, TernaryTree map, char p) { int k; if (p == 0) { return; } if (sc[p] == 0xFFFF) { k = map.find(kv.Arr, lo[p]); if (k < 0) { k = kx.alloc(strlen(kv.Arr, lo[p]) + 1); strcpy(kx.Arr, k, kv.Arr, lo[p]); map.insert(kx.Arr, k, (char)k); } lo[p] = (char)k; } else { compact(kx, map, lo[p]); if (sc[p] != 0) { compact(kx, map, eq[p]); } compact(kx, map, hi[p]); } }
/** * Add a pattern to the tree. Mainly, to be used by * PatternParser class as callback to * add a pattern to the tree. * @param pattern the hyphenation pattern * @param ivalue interletter weight values indicating the * desirability and priority of hyphenating at a given point * within the pattern. It should contain only digit characters. * (i.e. '0' to '9'). */ public void addPattern(string pattern, string ivalue) { int k = ivalues.find(ivalue); if (k <= 0) { k = packValues(ivalue); ivalues.insert(ivalue, (char)k); } insert(pattern, (char)k); }
/** * Hyphenate word and return an array of hyphenation points. * @param w char array that contains the word * @param offset Offset to first character in word * @param len Length of word * @param remainCharCount Minimum number of characters allowed * before the hyphenation point. * @param pushCharCount Minimum number of characters allowed after * the hyphenation point. * @return a {@link Hyphenation Hyphenation} object representing * the hyphenated word or null if word is not hyphenated. */ public Hyphenation hyphenate(char[] w, int offset, int len, int remainCharCount, int pushCharCount) { int i; char[] word = new char[len + 3]; // normalize word char[] c = new char[2]; for (i = 1; i <= len; i++) { c[0] = w[offset + i - 1]; int nc = classmap.find(c, 0); if (nc < 0) // found a non-letter character, abort { return(null); } word[i] = (char)nc; } int[] result = new int[len + 1]; int k = 0; // check exception list first string sw = new string(word, 1, len); if (stoplist.ContainsKey(sw)) { // assume only simple hyphens (Hyphen.pre="-", Hyphen.post = Hyphen.no = null) ArrayList hw = (ArrayList)stoplist[sw]; int j = 0; for (i = 0; i < hw.Count; i++) { Object o = hw[i]; if (o is string) { j += ((string)o).Length; if (j >= remainCharCount && j < (len - pushCharCount)) { result[k++] = j; } } } } else { // use algorithm to get hyphenation points word[0] = '.'; // word start marker word[len + 1] = '.'; // word end marker word[len + 2] = (char)0; // null terminated byte[] il = new byte[len + 3]; // initialized to zero for (i = 0; i < len + 1; i++) { searchPatterns(word, i, il); } // hyphenation points are located where interletter value is odd for (i = 0; i < len; i++) { if (((il[i + 1] & 1) == 1) && i >= remainCharCount && i < (len - pushCharCount)) { result[k++] = i; } } } if (k > 0) { // trim result array int[] res = new int[k]; Array.Copy(result, 0, res, 0, k); return(new Hyphenation(new string(w, offset, len), res)); } else { return(null); } }