# HG changeset patch # User Kenichi Handa # Date 1171538835 0 # Node ID 2951f3d44eba1639dc955fa89f278294e613f1a0 # Parent 656ca684d32696bd952bba9cebbc9732263aef38 (multibyte_char_to_unibyte_safe): New function. diff -r 656ca684d326 -r 2951f3d44eba src/character.c --- a/src/character.c Thu Feb 15 11:26:52 2007 +0000 +++ b/src/character.c Thu Feb 15 11:27:15 2007 +0000 @@ -275,6 +275,22 @@ return ((c1 != CHARSET_INVALID_CODE (charset)) ? c1 : c & 0xFF); } +/* Like multibyte_char_to_unibyte, but return -1 if C is not supported + by charset_unibyte. */ + +int +multibyte_char_to_unibyte_safe (c) + int c; +{ + struct charset *charset; + unsigned c1; + + if (CHAR_BYTE8_P (c)) + return CHAR_TO_BYTE8 (c); + charset = CHARSET_FROM_ID (charset_unibyte); + c1 = ENCODE_CHAR (charset, c); + return ((c1 != CHARSET_INVALID_CODE (charset)) ? c1 : -1); +} DEFUN ("characterp", Fcharacterp, Scharacterp, 1, 2, 0, doc: /* Return non-nil if OBJECT is a character. */)