Ejemplo n.º 1
0
bool
combine_ucs2_ucs2 (RECODE_SUBTASK subtask)
{
  unsigned value;

  if (get_ucs2 (&value, subtask))
    {
      struct state *state = NULL;

      if (subtask->task->byte_order_mark)
	put_ucs2 (BYTE_ORDER_MARK, subtask);

      while (true)
	{
	  struct state *shift
	    = find_shifted_state (state, value, subtask->step);

	  if (shift)
	    {
	      state = shift;
	      if (!get_ucs2 (&value, subtask))
		break;
	    }
	  else if (state)
	    {
	      if (state->result == NOT_A_CHARACTER)
		backtrack_ucs2 (state, subtask);
	      else
		put_ucs2 (state->result, subtask);
	      state = NULL;
	    }
	  else
	    {
	      put_ucs2 (value, subtask);
	      if (!get_ucs2 (&value, subtask))
		break;
	    }
	}

      if (state)
	{
	  if (state->result == NOT_A_CHARACTER)
	    backtrack_ucs2 (state, subtask);
	  else
	    put_ucs2 (state->result, subtask);
	}
    }

  SUBTASK_RETURN (subtask);
}
Ejemplo n.º 2
0
bool
combine_byte_ucs2 (RECODE_CONST_STEP step, RECODE_TASK task)
{
  unsigned value;

  if (value = get_byte (task), value != EOF)
    {
      struct state *state = NULL;

      if (task->byte_order_mark)
	put_ucs2 (BYTE_ORDER_MARK, task);

      while (true)
	{
	  struct state *shift = find_shifted_state (state, value, step);

	  if (shift)
	    {
	      state = shift;
	      if (value = get_byte (task), value == EOF)
		break;
	    }
	  else if (state)
	    {
	      if (state->result == NOT_A_CHARACTER)
		backtrack_ucs2 (state, task);
	      else
		put_ucs2 (state->result, task);
	      state = NULL;
	    }
	  else
	    {
	      put_ucs2 (value, task);
	      if (value = get_byte (task), value == EOF)
		break;
	    }
	}

      if (state)
	if (state->result == NOT_A_CHARACTER)
	  backtrack_ucs2 (state, task);
	else
	  put_ucs2 (state->result, task);
    }

  TASK_RETURN (task);
}
Ejemplo n.º 3
0
static void
backtrack_ucs2 (struct state *state,  RECODE_SUBTASK subtask)
{
  if (state->result == NOT_A_CHARACTER)
    {
      backtrack_ucs2 (state->unshift, subtask);
      put_ucs2 (state->character, subtask);
    }
  else
    put_ucs2 (state->result, subtask);
}