text_t rxvt_composite_vec::compose (unicode_t c1, unicode_t c2) { compose_char *cc; // break compose chains, as stupid readline really likes to duplicate // composing characters for some reason near the end of a line. cc = (*this)[c1]; while (cc) { if (cc->c2 == c2) return c1; cc = (*this)[cc->c1]; } // check to see wether this combination already exists otherwise for (cc = v.end (); cc-- > v.begin (); ) { if (cc->c1 == c1 && cc->c2 == c2) return COMPOSE_LO + (cc - v.begin ()); } // allocate a new combination if (v.size () == COMPOSE_HI - COMPOSE_LO + 1) { static int seen; if (!seen++) fprintf (stderr, "too many unrepresentable composite characters, try --enable-unicode3\n"); return REPLACEMENT_CHAR; } v.push_back (compose_char (c1, c2)); return v.size () - 1 + COMPOSE_LO; }
static nsresult mdn__unicode_compose(PRUint32 c1, PRUint32 c2, PRUint32 *compp) { PRInt32 n; PRInt32 lo, hi; const struct composition *cseq; //assert(compp != NULL); /* * Check for Hangul. */ if (LBase <= c1 && c1 < LBase + LCount && VBase <= c2 && c2 < VBase + VCount) { /* * Hangul L and V. */ *compp = SBase + ((c1 - LBase) * VCount + (c2 - VBase)) * TCount; return (NS_OK); } else if (SBase <= c1 && c1 < SLast && TBase <= c2 && c2 < TBase + TCount && (c1 - SBase) % TCount == 0) { /* * Hangul LV and T. */ *compp = c1 + (c2 - TBase); return (NS_OK); } /* * Look up composition table. If the result is 0, no composition * is defined. Otherwise, upper 16bits of the result contains * the number of composition that begins with 'c1', and the lower * 16bits is the offset in 'compose_seq'. */ if ((n = compose_char(c1, &cseq)) == 0) return (NS_SUCCESS_UNORM_NOTFOUND); /* * The composite sequences are sorted by the 2nd character 'c2'. * So we can use binary search. */ lo = 0; hi = n - 1; while (lo <= hi) { PRInt32 mid = (lo + hi) / 2; if (cseq[mid].c2 < c2) { lo = mid + 1; } else if (cseq[mid].c2 > c2) { hi = mid - 1; } else { *compp = cseq[mid].comp; return (NS_OK); } } return (NS_SUCCESS_UNORM_NOTFOUND); }
static PRInt32 mdn__unicode_iscompositecandidate(PRUint32 c) { const struct composition *dummy; /* Check for Hangul */ if ((LBase <= c && c < LBase + LCount) || (SBase <= c && c < SLast)) return (1); /* * Look up composition table. If there are no composition * that begins with the given character, it is not a * composition candidate. */ if (compose_char(c, &dummy) == 0) return (0); else return (1); }