Function: char-equal

char-equal is a function defined in editfns.c.

Signature

(char-equal C1 C2)

Documentation

Return t if two characters match, optionally ignoring case.

Both arguments must be characters (i.e. integers). Case is ignored if case-fold-search is non-nil in the current buffer.

View in manual

Source Code

// Defined in /usr/src/emacs/src/editfns.c
{
  int i1, i2;
  /* Check they're chars, not just integers, otherwise we could get array
     bounds violations in downcase.  */
  CHECK_CHARACTER (c1);
  CHECK_CHARACTER (c2);

  if (XFIXNUM (c1) == XFIXNUM (c2))
    return Qt;
  if (NILP (Vcase_fold_search))
    return Qnil;

  i1 = XFIXNAT (c1);
  i2 = XFIXNAT (c2);

  /* FIXME: It is possible to compare multibyte characters even when
     the current buffer is unibyte.  Unfortunately this is ambiguous
     for characters between 128 and 255, as they could be either
     eight-bit raw bytes or Latin-1 characters.  Assume the former for
     now.  See Bug#17011, and also see casefiddle.c's casify_object,
     which has a similar problem.  */
  if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
    {
      if (SINGLE_BYTE_CHAR_P (i1))
	i1 = UNIBYTE_TO_CHAR (i1);
      if (SINGLE_BYTE_CHAR_P (i2))
	i2 = UNIBYTE_TO_CHAR (i2);
    }

  return (downcase (i1) == downcase (i2) ? Qt :  Qnil);
}