1 /* Header for character representation.
2 Copyright (C) 1999,2000,2003 MORIOKA Tomohiko
4 This file is part of XEmacs.
6 XEmacs is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with XEmacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #ifndef _XEMACS_CHARACTER_H
22 #define _XEMACS_CHARACTER_H
24 #if !defined(MULE) /* unibyte representation */
25 # include "char-1byte.h"
26 #elif !defined(CHAR_IS_UCS4) /* leading-byte representation */
28 #else /* CHAR_IS_UCS4 */
29 # include "char-ucs.h"
30 #endif /* CHAR_IS_UCS4 */
32 /********************************/
34 /* Interface for characters */
36 /********************************/
39 Return whether the given Emchar is valid.
42 Return whether the given Lisp_Object is a character.
44 CHECK_CHAR_COERCE_INT (ch):
45 Signal an error if CH is not a valid character or integer
47 If CH is an integer Lisp_Object, convert it to a character
48 Lisp_Object, but merely by repackaging, without performing
49 tests for char validity.
51 Functions/macros when MULE is defined:
54 Return whether the given Emchar is ASCII.
56 MAKE_CHAR (CHARSET, B1, B2):
57 Return a character whose coded-charset is CHARSET and
58 position-codes are B1 and B2. 1 byte character ignores B2.
60 BREAKUP_CHAR (ch, charset, B1, B2):
61 Break up the given Emchar, and store found coded-charset and
62 position-codes to CHARSET, B1 and B2.
65 Return coded-charset object of Emchar CH.
67 CHAR_LEADING_BYTE (CH):
68 Return Charset-ID of Emchar CH.
71 #define CHAR_INTP(x) (INTP (x) && valid_char_p (XINT (x)))
73 #define CHAR_OR_CHAR_INTP(x) (CHARP (x) || CHAR_INTP (x))
75 INLINE_HEADER Emchar XCHAR_OR_CHAR_INT (Lisp_Object obj);
77 XCHAR_OR_CHAR_INT (Lisp_Object obj)
79 return CHARP (obj) ? XCHAR (obj) : XINT (obj);
82 #define CHECK_CHAR_COERCE_INT(x) do { \
85 else if (CHAR_INTP (x)) \
86 x = make_char (XINT (x)); \
88 x = wrong_type_argument (Qcharacterp, x); \
92 #define CHARC_CHARSET(cc) ((cc).charset)
93 #define CHARC_CHARSET_ID(cc) XCHARSET_ID (CHARC_CHARSET (cc))
94 #define CHARC_CODE_POINT(cc) ((cc).code_point)
95 #define CHARC_COLUMNS(cc) CHARSET_COLUMNS (XCHARSET (CHARC_CHARSET (cc)))
97 INLINE_HEADER Emchar CHARC_TO_CHAR (Charc cc);
99 CHARC_TO_CHAR (Charc cc)
101 return DECODE_CHAR (cc.charset, cc.code_point, 0);
104 INLINE_HEADER int CHARC_EQ (Charc cc1, Charc cc2);
106 CHARC_EQ (Charc cc1, Charc cc2)
108 return EQ (cc1.charset, cc2.charset) && (cc1.code_point == cc2.code_point);
111 INLINE_HEADER int CHARC_ASCII_EQ (Charc cc, int ch);
113 CHARC_ASCII_EQ (Charc cc, int ch)
115 return EQ (cc.charset, Vcharset_ascii) && (cc.code_point == ch);
118 INLINE_HEADER int CHARC_IS_SPACE (Charc cc);
120 CHARC_IS_SPACE (Charc cc)
122 return (EQ (cc.charset, Vcharset_ascii) ||
123 EQ (cc.charset, Vcharset_control_1) ||
124 EQ (cc.charset, Vcharset_latin_iso8859_1))
125 && isspace (cc.code_point);
128 INLINE_HEADER Charc ASCII_TO_CHARC (int ch);
130 ASCII_TO_CHARC (int ch)
134 cc.charset = Vcharset_ascii;
142 Dynarr_declare (Charc);
145 #endif /* _XEMACS_CHARACTER_H */