]> code.delx.au - gnu-emacs/blobdiff - src/character.c
Update copyright year to 2015
[gnu-emacs] / src / character.c
index b2caaa290af1d5d1eacaded40af19d710c26c09c..ad3fe129a33ba062f6d1f8fbd12a3bcbc2864034 100644 (file)
@@ -1,6 +1,6 @@
 /* Basic character support.
 
-Copyright (C) 2001-2013 Free Software Foundation, Inc.
+Copyright (C) 2001-2015 Free Software Foundation, Inc.
 Copyright (C) 1995, 1997, 1998, 2001 Electrotechnical Laboratory, JAPAN.
   Licensed to the Free Software Foundation.
 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
@@ -29,8 +29,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <config.h>
 #endif
 
-#define CHARACTER_INLINE EXTERN_INLINE
-
 #include <stdio.h>
 
 #ifdef emacs
@@ -174,11 +172,14 @@ string_char (const unsigned char *p, const unsigned char **advanced, int *len)
 
   if (*p < 0x80 || ! (*p & 0x20) || ! (*p & 0x10))
     {
+      /* 1-, 2-, and 3-byte sequences can be handled by the macro.  */
       c = STRING_CHAR_ADVANCE (p);
     }
   else if (! (*p & 0x08))
     {
-      c = ((((p)[0] & 0xF) << 18)
+      /* A 4-byte sequence of this form:
+        11110xxx 10xxxxxx 10xxxxxx 10xxxxxx  */
+      c = ((((p)[0] & 0x7) << 18)
           | (((p)[1] & 0x3F) << 12)
           | (((p)[2] & 0x3F) << 6)
           | ((p)[3] & 0x3F));
@@ -186,7 +187,14 @@ string_char (const unsigned char *p, const unsigned char **advanced, int *len)
     }
   else
     {
-      c = ((((p)[1] & 0x3F) << 18)
+      /* A 5-byte sequence of this form:
+
+        111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
+
+        Note that the top 4 `x's are always 0, so shifting p[1] can
+        never exceed the maximum valid character codepoint. */
+      c = (/* (((p)[0] & 0x3) << 24) ... always 0, so no need to shift. */
+          (((p)[1] & 0x3F) << 18)
           | (((p)[2] & 0x3F) << 12)
           | (((p)[3] & 0x3F) << 6)
           | ((p)[4] & 0x3F));
@@ -225,32 +233,6 @@ translate_char (Lisp_Object table, int c)
   return c;
 }
 
-/* Convert ASCII or 8-bit character C to unibyte.  If C is none of
-   them, return (C & 0xFF).  */
-
-int
-multibyte_char_to_unibyte (int c)
-{
-  if (c < 0x80)
-    return c;
-  if (CHAR_BYTE8_P (c))
-    return CHAR_TO_BYTE8 (c);
-  return (c & 0xFF);
-}
-
-/* Like multibyte_char_to_unibyte, but return -1 if C is not supported
-   by charset_unibyte.  */
-
-int
-multibyte_char_to_unibyte_safe (int c)
-{
-  if (c < 0x80)
-    return c;
-  if (CHAR_BYTE8_P (c))
-    return CHAR_TO_BYTE8 (c);
-  return -1;
-}
-
 DEFUN ("characterp", Fcharacterp, Scharacterp, 1, 2, 0,
        doc: /* Return non-nil if OBJECT is a character.
 In Emacs Lisp, characters are represented by character codes, which
@@ -1062,10 +1044,6 @@ A char-table for width (columns) of each character.  */);
               doc: /* Char table of script symbols.
 It has one extra slot whose value is a list of script symbols.  */);
 
-  /* Intern this now in case it isn't already done.
-     Setting this variable twice is harmless.
-     But don't staticpro it here--that is done in alloc.c.  */
-  Qchar_table_extra_slots = intern_c_string ("char-table-extra-slots");
   DEFSYM (Qchar_script_table, "char-script-table");
   Fput (Qchar_script_table, Qchar_table_extra_slots, make_number (1));
   Vchar_script_table = Fmake_char_table (Qchar_script_table, Qnil);