Update copyright years
[m17n/m17n-lib.git] / src / mtext.h
1 /* mtext.h -- header file for the M-text module.
2    Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3      National Institute of Advanced Industrial Science and Technology (AIST)
4      Registration Number H15PRO112
5
6    This file is part of the m17n library.
7
8    The m17n library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU Lesser General Public License
10    as published by the Free Software Foundation; either version 2.1 of
11    the License, or (at your option) any later version.
12
13    The m17n library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    Lesser General Public License for more details.
17
18    You should have received a copy of the GNU Lesser General Public
19    License along with the m17n library; if not, write to the Free
20    Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21    02111-1307, USA.  */
22
23 #ifndef _M17N_MTEXT_H_
24 #define _M17N_MTEXT_H_
25
26 /** @file mtext.h
27     @brief Header for M-text handling.
28 */
29
30 #define POS_CHAR_TO_BYTE(mt, pos)                               \
31   (mtext_nchars (mt) == mtext_nbytes (mt) ? (pos)               \
32    : (pos) == (mt)->cache_char_pos ? (mt)->cache_byte_pos       \
33    : mtext__char_to_byte ((mt), (pos)))
34
35 #define POS_BYTE_TO_CHAR(mt, pos_byte)                          \
36   (mtext_nchars (mt) == mtext_nbytes (mt) ? (pos_byte)          \
37    : (pos_byte) == (mt)->cache_byte_pos ? (mt)->cache_char_pos  \
38    : mtext__byte_to_char ((mt), (pos_byte)))
39
40
41 #define MTEXT_DATA(mt) ((mt)->data)
42
43 extern int mtext__char_to_byte (MText *mt, int pos);
44
45 extern int mtext__byte_to_char (MText *mt, int pos_byte);
46
47 extern void mtext__enlarge (MText *mt, int nbytes);
48
49 extern int mtext__takein (MText *mt, int nchars, int nbytes);
50
51 extern int mtext__cat_data (MText *mt, unsigned char *p, int nbytes,
52                             enum MTextFormat format);
53
54 #define MTEXT_CAT_ASCII(mt, str)                                \
55   mtext__cat_data ((mt), (unsigned char *) (str), strlen (str), \
56                    MTEXT_FORMAT_US_ASCII)
57
58 extern MText *mtext__from_data (const void *data, int nitems,
59                                 enum MTextFormat format, int need_copy);
60
61 extern void mtext__adjust_format (MText *mt, enum MTextFormat format);
62
63 extern int mtext__bol (MText *mt, int pos);
64
65 extern int mtext__eol (MText *mt, int pos);
66
67 extern void mtext__wseg_fini ();
68
69 extern int mtext__word_segment (MText *mt, int pos, int *from, int *to);
70
71 #endif /* _M17N_MTEXT_H_ */