예제 #1
0
void linebreak_southeastasian_flagbreak(gcstring_t *gcstr)
{
#ifdef USE_LIBTHAI
    wchar_t *buf;
    size_t i, j, k;
    int brk;

    if (gcstr == NULL || gcstr->gclen == 0)
	return;
    /* Copy string to temp buffer so that abuse of external module avoided. */
    if ((buf = malloc(sizeof(wchar_t) * (gcstr->len + 1))) == NULL)
	return;
    for (i = 0; i < gcstr->len; i++)
	buf[i] = gcstr->str[i];
    buf[i] = (wchar_t)0;
    k = i;

    /* Flag breaking points. */
    for (i = 0, j = 0; buf[j] && th_wbrk(buf + j, &brk, 1); j += brk) {
	/* check if external module is broken. */
	assert(0 <= brk);
	assert(brk != 0);
	assert(brk < k);

	for (; i < gcstr->gclen && gcstr->gcstr[i].idx <= j + brk; i++) {
	    /* check if external module break temp buffer. */
	    assert(buf[i] == gcstr->str[i]);

	    if (gcstr->gcstr[i].lbc == LB_SA && !gcstr->gcstr[i].flag)
		gcstr->gcstr[i].flag = 
		    (gcstr->gcstr[i].idx == j + brk)?
		    LINEBREAK_FLAG_BREAK_BEFORE:
		    LINEBREAK_FLAG_PROHIBIT_BEFORE;
	}
    }
    for (; i < gcstr->gclen && gcstr->gcstr[i].lbc == LB_SA; i++)
	if (!gcstr->gcstr[i].flag)
	    gcstr->gcstr[i].flag = LINEBREAK_FLAG_PROHIBIT_BEFORE;

    free(buf);
#endif /* USE_LIBTHAI */
}
예제 #2
0
int main (int argc, char* argv[])
{
  thchar_t str[MAXLINELENGTH];
  thwchar_t ustr[MAXLINELENGTH], uout[MAXLINELENGTH], unicodeCutCode[6];

  thchar_t out1[MAXLINELENGTH*2+1];
  thchar_t out2[MAXLINELENGTH];
  int pos[MAXLINELENGTH];
  int outputLength, unicodeCutCodeLength;
  int numCut, i;
  
  strcpy ((char *)str, "ÊÇÑÊ´Õ¤ÃѺ ¡Í.ÃÁ¹. ¹Õèà»ç¹¡Ò÷´ÊͺµÑÇàͧ");
  printf ("Testing with input string: %s\n", str);

  printf ("Converting to Unicode...\n");
  th_tis2uni_line (str, ustr, MAXLINELENGTH);

  printf ("Calling th_wbrk()...\n");
  numCut = th_wbrk (ustr, pos, MAXLINELENGTH);

  printf ("Total %d cut points.", numCut);
  if (numCut > 0) { 
    printf ("Cut points list: %d", pos[0]);
    for (i = 1; i < numCut; i++) {
      printf (", %d", pos[i]);
    }
  }
  printf ("\n");
  if (numCut != 7) {
    printf ("Error! Should have 7 cut points.\n Test th_wbrk() failed...\n");
    exit (-1);
  }
	
  unicodeCutCodeLength = th_tis2uni_line ((const thchar_t *) "<WBR>",
                                          (thwchar_t*) unicodeCutCode, 6);

  printf ("Calling th_wbrk_line() ....\n");
  outputLength = th_wbrk_line (ustr, (thwchar_t*) uout, MAXLINELENGTH,
                               unicodeCutCode);

  printf ("Return value from th_wbrk_line is %d\n", outputLength);
  printf ("Output string length is %d\n", wcslen(uout));
  if (outputLength != 75) {
    printf ("Error! Output string length != 75. "
            "Test th_wbrk_line() failed...\n");
    exit (-1);
  }

  printf ("Compare with result from th_brk_line()..\n");
  th_brk_line (str, out1, MAXLINELENGTH*2+1, "<WBR>");
  th_uni2tis_line(uout, out2, MAXLINELENGTH);

  if (strcmp ((const char *)out1, (const char *)out2) == 0) {
    printf ("Correct! .. test th_wbrk_line() passed...\n");
  } else {
    printf ("Error! Comparison of results from th_brk_line() "
            "and th_wbrk_line() failed.\n");
    printf ("th_brk_line :\"%s\"\n", out1);
    printf ("th_wbrk_line:\"%s\"\n", out2);
    printf ("Test th_wbrk_line() failed...\n");
    exit (-1);
  }
  
  return 0;
}