]> code.delx.au - gnu-emacs/blobdiff - src/charset.h
*** empty log message ***
[gnu-emacs] / src / charset.h
index 42ab2308d68950b1d8e33f081d5ad863e80481ab..3a4eb5cbfcce6f1d582c84e421e730d56463bcdb 100644 (file)
@@ -437,25 +437,33 @@ extern int width_by_char_head[256];
 #else  /* not BYTE_COMBINING_DEBUG */
 
 #define PARSE_MULTIBYTE_SEQ(str, length, bytes)        \
-  (bytes) = BYTES_BY_CHAR_HEAD ((str)[0])
+  ((void)(length), (bytes) = BYTES_BY_CHAR_HEAD ((str)[0]))
 
 #endif /* not BYTE_COMBINING_DEBUG */
 
+#define VALID_LEADING_CODE_P(code)     \
+  (! NILP (CHARSET_TABLE_ENTRY (code)))
+
 /* Return 1 iff 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.  */
 
-#define UNIBYTE_STR_AS_MULTIBYTE_P(str, length, bytes) \
-  (((str)[0] < 0x80 || (str)[0] >= 0xA0)               \
-   ? ((bytes) = 1)                                     \
-   : (((bytes) = BYTES_BY_CHAR_HEAD ((str)[0])),       \
-      ((bytes) > 1 && (bytes) <= (length)              \
-       && (str)[0] != LEADING_CODE_8_BIT_CONTROL       \
-       && !CHAR_HEAD_P ((str)[1])                      \
-       && ((bytes) == 2                                        \
-          || (!CHAR_HEAD_P ((str)[2])                  \
-              && ((bytes) == 3                         \
-                  || !CHAR_HEAD_P ((str)[3])))))))
+#define UNIBYTE_STR_AS_MULTIBYTE_P(str, length, bytes)         \
+  (((str)[0] < 0x80 || (str)[0] >= 0xA0)                       \
+   ? ((bytes) = 1)                                             \
+   : (((bytes) = BYTES_BY_CHAR_HEAD ((str)[0])),               \
+      ((bytes) <= (length)                                     \
+       && !CHAR_HEAD_P ((str)[1])                              \
+       && ((bytes) == 2                                                \
+          ? (str)[0] != LEADING_CODE_8_BIT_CONTROL             \
+          : (!CHAR_HEAD_P ((str)[2])                           \
+             && ((bytes) == 3                                  \
+                 ? (((str)[0] != LEADING_CODE_PRIVATE_11       \
+                     && (str)[0] != LEADING_CODE_PRIVATE_12)   \
+                    || VALID_LEADING_CODE_P (str[1]))          \
+                 : (!CHAR_HEAD_P ((str)[3])                    \
+                    && VALID_LEADING_CODE_P (str[1]))))))))
+
 
 /* Return 1 iff the byte sequence at multibyte string STR is valid as
    a unibyte form.  By a side effect, BYTES is set to the byte length
@@ -573,15 +581,15 @@ if (1)                                                                       \
     CHARIDX++;                                                            \
     if (STRING_MULTIBYTE (STRING))                                        \
       {                                                                           \
-       unsigned char *ptr = &XSTRING (STRING)->data[BYTEIDX];             \
-       int space_left = XSTRING (STRING)->size_byte - BYTEIDX;            \
+       const unsigned char *ptr = SDATA (STRING) + BYTEIDX;               \
+       int space_left = SBYTES (STRING) - BYTEIDX;                        \
        int actual_len;                                                    \
                                                                           \
        OUTPUT = STRING_CHAR_AND_LENGTH (ptr, space_left, actual_len);     \
        BYTEIDX += actual_len;                                             \
       }                                                                           \
     else                                                                  \
-      OUTPUT = XSTRING (STRING)->data[BYTEIDX++];                         \
+      OUTPUT = SREF (STRING, BYTEIDX++);                                  \
   }                                                                       \
 else
 
@@ -590,8 +598,8 @@ else
 #define FETCH_STRING_CHAR_ADVANCE_NO_CHECK(OUTPUT, STRING, CHARIDX, BYTEIDX)  \
 if (1)                                                                       \
   {                                                                          \
-    unsigned char *fetch_string_char_ptr = &XSTRING (STRING)->data[BYTEIDX];  \
-    int fetch_string_char_space_left = XSTRING (STRING)->size_byte - BYTEIDX; \
+    const unsigned char *fetch_string_char_ptr = SDATA (STRING) + BYTEIDX;    \
+    int fetch_string_char_space_left = SBYTES (STRING) - BYTEIDX;            \
     int actual_len;                                                          \
                                                                              \
     OUTPUT                                                                   \
@@ -634,6 +642,34 @@ else
    ? 1                                                 \
    : multibyte_form_length (str, len))
 
+/* If P is before LIMIT, advance P to the next character boundary.  It
+   assumes that P is already at a character boundary of the sane
+   mulitbyte form whose end address is LIMIT.  */
+
+#define NEXT_CHAR_BOUNDARY(p, limit)   \
+  do {                                 \
+    if ((p) < (limit))                 \
+      (p) += BYTES_BY_CHAR_HEAD (*(p));        \
+  } 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.  */
+
+#define PREV_CHAR_BOUNDARY(p, limit)                                   \
+  do {                                                                 \
+    if ((p) > (limit))                                                 \
+      {                                                                        \
+       const unsigned char *p0 = (p);                                  \
+       do {                                                            \
+         p0--;                                                         \
+       } while (p0 >= limit && ! CHAR_HEAD_P (*p0));                   \
+       (p) = (BYTES_BY_CHAR_HEAD (*p0) == (p) - p0) ? p0 : (p) - 1;    \
+      }                                                                        \
+  } while (0)
+
+
 #ifdef emacs
 
 /* Increase the buffer byte position POS_BYTE of the current buffer to
@@ -794,20 +830,23 @@ extern int char_to_string_1 P_ ((int, unsigned char *));
 extern int string_to_char P_ ((const unsigned char *, int, int *));
 extern int char_printable_p P_ ((int c));
 extern int multibyte_form_length P_ ((const unsigned char *, int));
-extern void parse_str_as_multibyte P_ ((unsigned char *, int, int *, int *));
+extern void parse_str_as_multibyte P_ ((const unsigned char *, int, int *,
+                                       int *));
 extern int str_as_multibyte P_ ((unsigned char *, int, int, int *));
 extern int parse_str_to_multibyte P_ ((unsigned char *, int));
 extern int str_to_multibyte P_ ((unsigned char *, int, int));
 extern int str_as_unibyte P_ ((unsigned char *, int));
 extern int get_charset_id P_ ((Lisp_Object));
-extern int find_charset_in_text P_ ((unsigned char *, int, int, int *,
+extern int find_charset_in_text P_ ((const unsigned char *, int, int, int *,
                                    Lisp_Object));
 extern int strwidth P_ ((unsigned char *, int));
-extern int c_string_width P_ ((unsigned char *, int, int, int *, int *));
+extern int c_string_width P_ ((const unsigned char *, int, int, int *, int *));
 extern int lisp_string_width P_ ((Lisp_Object, int, int *, int *));
 extern int char_bytes P_ ((int));
 extern int char_valid_p P_ ((int, int));
 
+EXFUN (Funibyte_char_to_multibyte, 1);
+
 extern Lisp_Object Vtranslation_table_vector;
 
 /* Return a translation table of id number ID.  */
@@ -825,8 +864,12 @@ extern Lisp_Object Vauto_fill_chars;
 #define BCOPY_SHORT(from, to, len)             \
   do {                                         \
     int i = len;                               \
-    unsigned char *from_p = from, *to_p = to;  \
+    const unsigned char *from_p = from;                \
+    unsigned char *to_p = to;                  \
     while (i--) *to_p++ = *from_p++;           \
   } while (0)
 
 #endif /* EMACS_CHARSET_H */
+
+/* arch-tag: 3b96db55-4961-481d-ac3e-219f46a2b3aa
+   (do not change this comment) */