示例#1
0
文件: nfkc.c 项目: AlekSi/Jabbin
static gboolean
combine (gunichar a, gunichar b, gunichar * result)
{
  gushort index_a, index_b;

  if (combine_hangul (a, b, result))
    return TRUE;

  index_a = COMPOSE_INDEX (a);

  if (index_a >= COMPOSE_FIRST_SINGLE_START && index_a < COMPOSE_SECOND_START)
    {
      if (b == compose_first_single[index_a - COMPOSE_FIRST_SINGLE_START][0])
	{
	  *result =
	    compose_first_single[index_a - COMPOSE_FIRST_SINGLE_START][1];
	  return TRUE;
	}
      else
	return FALSE;
    }

  index_b = COMPOSE_INDEX (b);

  if (index_b >= COMPOSE_SECOND_SINGLE_START)
    {
      if (a ==
	  compose_second_single[index_b - COMPOSE_SECOND_SINGLE_START][0])
	{
	  *result =
	    compose_second_single[index_b - COMPOSE_SECOND_SINGLE_START][1];
	  return TRUE;
	}
      else
	return FALSE;
    }

  if (index_a >= COMPOSE_FIRST_START && index_a < COMPOSE_FIRST_SINGLE_START
      && index_b >= COMPOSE_SECOND_START
      && index_b < COMPOSE_SECOND_SINGLE_START)
    {
      gunichar res =
	compose_array[index_a - COMPOSE_FIRST_START][index_b -
						     COMPOSE_SECOND_START];

      if (res)
	{
	  *result = res;
	  return TRUE;
	}
    }

  return FALSE;
}
示例#2
0
文件: decompose.c 项目: now/ned
/* {{{1
 * Try to combine the Unicode characters ‘a’ and ‘b’ storing the result in
 * ‘result’.
 */
static bool
combine(unichar a, unichar b, unichar *result)
{
	if (combine_hangul(a, b, result))
		return true;

	unsigned short index_a = COMPOSE_INDEX(a);
	if (index_a >= COMPOSE_FIRST_SINGLE_START && index_a < COMPOSE_SECOND_START) {
		if (b == compose_first_single[index_a - COMPOSE_FIRST_SINGLE_START][0]) {
			*result = compose_first_single[index_a - COMPOSE_FIRST_SINGLE_START][1];
			return true;
		} else {
			return false;
		}
	}

	unsigned short index_b = COMPOSE_INDEX(b);
	if (index_b >= COMPOSE_SECOND_SINGLE_START) {
		if (a == compose_second_single[index_b - COMPOSE_SECOND_SINGLE_START][0]) {
			*result = compose_second_single[index_b - COMPOSE_SECOND_SINGLE_START][1];
			return true;
		} else {
			return false;
		}
	}

	if (index_a >= COMPOSE_FIRST_START &&
	    index_a < COMPOSE_FIRST_SINGLE_START &&
	    index_b >= COMPOSE_SECOND_START &&
	    index_b < COMPOSE_SECOND_SINGLE_START) {
		unichar r = compose_array[index_a - COMPOSE_FIRST_START][index_b - COMPOSE_SECOND_START];

		if (r != 0) {
			*result = r;
			return true;
		} else {
			return false;
		}
	}

	return false;
}