Function: encode-char
encode-char is a function defined in charset.c.
Signature
(encode-char CH CHARSET)
Documentation
Encode the character CH into a code-point of CHARSET.
Return the encoded code-point as an integer, or nil if CHARSET doesn't support CH.
Probably introduced at or before Emacs version 23.1.
Source Code
// Defined in /usr/src/emacs/src/charset.c
{
int c, id;
unsigned code;
struct charset *charsetp;
CHECK_CHARSET_GET_ID (charset, id);
CHECK_CHARACTER (ch);
c = XFIXNAT (ch);
charsetp = CHARSET_FROM_ID (id);
code = ENCODE_CHAR (charsetp, c);
if (code == CHARSET_INVALID_CODE (charsetp))
return Qnil;
/* There are much fewer codepoints in the world than we have positive
fixnums, so it could be argued that we never really need a bignum,
e.g. Unicode codepoints only need 21bit, and China's GB-10830
can fit in 22bit. Yet we encode GB-10830's chars in a sparse way
(we just take the 4byte sequences as a 32bit int), so some
GB-10830 chars (such as 0x81308130 in etc/charsets/gb108304.map) end
up represented as bignums if EMACS_INT is 32 bits. */
return INT_TO_INTEGER (code);
}