New files.
[chise/xemacs-chise.git] / src / mb-multibyte.h
1 /* Header for generic multibyte string representation.
2    Copyright (C) 1999 Electrotechnical Laboratory, JAPAN.
3    Licensed to the Free Software Foundation.
4
5 This file is part of XEmacs.
6
7 XEmacs is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
10 later version.
11
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with XEmacs; see the file COPYING.  If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 /* Rewritten by MORIOKA Tomohiko <tomo@m17n.org>. */
23
24 #ifndef _XEMACS_MB_MULTIBYTE_H
25 #define _XEMACS_MB_MULTIBYTE_H
26
27 /* ---------------------------------------------------------------------- */
28 /* (A) For working with charptr's (pointers to internally-formatted text) */
29 /* ---------------------------------------------------------------------- */
30
31 # define VALID_CHARPTR_P(ptr) BUFBYTE_FIRST_BYTE_P (* (unsigned char *) ptr)
32
33 #define VALIDATE_CHARPTR_BACKWARD(ptr) do {     \
34   while (!VALID_CHARPTR_P (ptr)) ptr--;         \
35 } while (0)
36
37 /* This needs to be trickier to avoid the possibility of running off
38    the end of the string. */
39
40 #define VALIDATE_CHARPTR_FORWARD(ptr) do {      \
41   Bufbyte *vcf_ptr = (ptr);                     \
42   VALIDATE_CHARPTR_BACKWARD (vcf_ptr);          \
43   if (vcf_ptr != (ptr))                         \
44     {                                           \
45       (ptr) = vcf_ptr;                          \
46       INC_CHARPTR (ptr);                        \
47     }                                           \
48 } while (0)
49
50 /* -------------------------------------------------------------------- */
51 /* (C) For retrieving or changing the character pointed to by a charptr */
52 /* -------------------------------------------------------------------- */
53
54 #define simple_charptr_emchar(ptr)              ((Emchar) (ptr)[0])
55 #define simple_set_charptr_emchar(ptr, x)       ((ptr)[0] = (Bufbyte) (x), 1)
56 #define simple_charptr_copy_char(ptr, ptr2)     ((ptr2)[0] = *(ptr), 1)
57
58 Emchar non_ascii_charptr_emchar (CONST Bufbyte *ptr);
59 Bytecount non_ascii_set_charptr_emchar (Bufbyte *ptr, Emchar c);
60 Bytecount non_ascii_charptr_copy_char (CONST Bufbyte *ptr, Bufbyte *ptr2);
61
62 INLINE Emchar charptr_emchar (CONST Bufbyte *ptr);
63 INLINE Emchar
64 charptr_emchar (CONST Bufbyte *ptr)
65 {
66   return BYTE_ASCII_P (*ptr) ?
67     simple_charptr_emchar (ptr) :
68     non_ascii_charptr_emchar (ptr);
69 }
70
71 INLINE Bytecount set_charptr_emchar (Bufbyte *ptr, Emchar x);
72 INLINE Bytecount
73 set_charptr_emchar (Bufbyte *ptr, Emchar x)
74 {
75   return !CHAR_MULTIBYTE_P (x) ?
76     simple_set_charptr_emchar (ptr, x) :
77     non_ascii_set_charptr_emchar (ptr, x);
78 }
79
80 INLINE Bytecount charptr_copy_char (CONST Bufbyte *ptr, Bufbyte *ptr2);
81 INLINE Bytecount
82 charptr_copy_char (CONST Bufbyte *ptr, Bufbyte *ptr2)
83 {
84   return BYTE_ASCII_P (*ptr) ?
85     simple_charptr_copy_char (ptr, ptr2) :
86     non_ascii_charptr_copy_char (ptr, ptr2);
87 }
88
89 #endif /* _XEMACS_MB_MULTIBYTE_H */