/* Header for multibyte character handler.
- Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
- Copyright (C) 1995, 1997, 1998, 2003
+ Copyright (C) 2001, 2002, 2003, 2004, 2005,
+ 2006, 2007 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+ 2005, 2006, 2007
National Institute of Advanced Industrial Science and Technology (AIST)
Registration Number H14PRO021
GNU Emacs is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Emacs is distributed in the hope that it will be useful,
| ((c1) <= 0 ? 0 : (((c1) & 0x7F) << 7))))))
-/* If GENERICP is nonzero, return nonzero iff C is a valid normal or
- generic character. If GENERICP is zero, return nonzero iff C is a
+/* If GENERICP is nonzero, return nonzero if C is a valid normal or
+ generic character. If GENERICP is zero, return nonzero if C is a
valid normal character. */
#define CHAR_VALID_P(c, genericp) \
((c) >= 0 \
#define VALID_LEADING_CODE_P(code) \
(! NILP (CHARSET_TABLE_ENTRY (code)))
-/* Return 1 iff the byte sequence at unibyte string STR (LENGTH bytes)
+/* Return 1 if the byte sequence at unibyte string STR (LENGTH bytes)
is valid as a multibyte form. If valid, by a side effect, BYTES is
set to the byte length of the multibyte form. */
&& VALID_LEADING_CODE_P (str[1]))))))))
-/* Return 1 iff the byte sequence at multibyte string STR is valid as
+/* Return 1 if the byte sequence at multibyte string STR is valid as
a unibyte form. By a side effect, BYTES is set to the byte length
of one character at STR. */
c1 = CHAR_FIELD3 (c), \
c2 = -1)))
-/* Return 1 iff character C has valid printable glyph. */
+/* Return 1 if character C has valid printable glyph. */
#define CHAR_PRINTABLE_P(c) (ASCII_BYTE_P (c) || char_printable_p (c))
/* The charset of the character at STR is stored in CHARSET, and the
} while (0)
-/* If P is after LIMIT, advance P to the previous character boundary.
- It assumes that P is already at a character boundary of the sane
- mulitbyte form whose beginning address is LIMIT. */
+/* If P is after LIMIT, advance P to the previous character boundary. */
#define PREV_CHAR_BOUNDARY(p, limit) \
do { \
if ((p) > (limit)) \
{ \
const unsigned char *p0 = (p); \
+ const unsigned char *p_limit = max (limit, p0 - MAX_MULTIBYTE_LENGTH);\
do { \
p0--; \
- } while (p0 >= limit && ! CHAR_HEAD_P (*p0)); \
- (p) = (BYTES_BY_CHAR_HEAD (*p0) == (p) - p0) ? p0 : (p) - 1; \
+ } while (p0 >= p_limit && ! CHAR_HEAD_P (*p0)); \
+ /* If BBCH(*p0) > p-p0, it means we were not on a boundary. */ \
+ (p) = (BYTES_BY_CHAR_HEAD (*p0) >= (p) - p0) ? p0 : (p) - 1; \
} \
} while (0)
+#define AT_CHAR_BOUNDARY_P(result, p, limit) \
+ do { \
+ if (CHAR_HEAD_P (*(p)) || (p) <= limit) \
+ /* Optimization for the common case. */ \
+ (result) = 1; \
+ else \
+ { \
+ const unsigned char *p_aux = (p)+1; \
+ PREV_CHAR_BOUNDARY (p_aux, limit); \
+ (result) = (p_aux == (p)); \
+ } \
+} while (0)
#ifdef emacs
/* This is the maximum byte length of multi-byte sequence. */
#define MAX_MULTIBYTE_LENGTH 4
-extern void invalid_character P_ ((int));
+extern void invalid_character P_ ((int)) NO_RETURN;
extern int translate_char P_ ((Lisp_Object, int, int, int, int));
extern int split_string P_ ((const unsigned char *, int, int *,