blob: 334acd3d420097651008765175f46b94c821b6a1 [file] [log] [blame]
Havoc Pennington54951422000-11-29 23:49:44 +00001/* gunibreak.c - line break properties
2 *
3 * Copyright 2000 Red Hat, Inc.
4 *
Sébastien Wilmetf6059052016-12-27 17:40:22 +01005 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
Sébastien Wilmetf9faac72017-01-05 12:47:07 +01008 * version 2.1 of the License, or (at your option) any later version.
Havoc Pennington54951422000-11-29 23:49:44 +00009 *
Sébastien Wilmetf6059052016-12-27 17:40:22 +010010 * This library is distributed in the hope that it will be useful,
Havoc Pennington54951422000-11-29 23:49:44 +000011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
Sébastien Wilmetf6059052016-12-27 17:40:22 +010015 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, see <http://www.gnu.org/licenses/>.
Havoc Pennington54951422000-11-29 23:49:44 +000017 */
18
Owen Taylorbbbd3292002-12-04 01:27:44 +000019#include "config.h"
20
21#include <stdlib.h>
Owen Taylor57d9c092002-02-17 23:28:43 +000022
Havoc Pennington54951422000-11-29 23:49:44 +000023#include "gunibreak.h"
24
Noah Levitt05f99522003-07-31 02:27:56 +000025#define TPROP_PART1(Page, Char) \
26 ((break_property_table_part1[Page] >= G_UNICODE_MAX_TABLE_INDEX) \
27 ? (break_property_table_part1[Page] - G_UNICODE_MAX_TABLE_INDEX) \
28 : (break_property_data[break_property_table_part1[Page]][Char]))
Havoc Pennington54951422000-11-29 23:49:44 +000029
Noah Levitt05f99522003-07-31 02:27:56 +000030#define TPROP_PART2(Page, Char) \
31 ((break_property_table_part2[Page] >= G_UNICODE_MAX_TABLE_INDEX) \
32 ? (break_property_table_part2[Page] - G_UNICODE_MAX_TABLE_INDEX) \
33 : (break_property_data[break_property_table_part2[Page]][Char]))
Havoc Pennington54951422000-11-29 23:49:44 +000034
Noah Levitt05f99522003-07-31 02:27:56 +000035#define PROP(Char) \
36 (((Char) <= G_UNICODE_LAST_CHAR_PART1) \
37 ? TPROP_PART1 ((Char) >> 8, (Char) & 0xff) \
38 : (((Char) >= 0xe0000 && (Char) <= G_UNICODE_LAST_CHAR) \
39 ? TPROP_PART2 (((Char) - 0xe0000) >> 8, (Char) & 0xff) \
40 : G_UNICODE_BREAK_UNKNOWN))
Havoc Pennington54951422000-11-29 23:49:44 +000041
Havoc Pennington4eab8752001-04-16 20:05:25 +000042/**
43 * g_unichar_break_type:
44 * @c: a Unicode character
45 *
46 * Determines the break type of @c. @c should be a Unicode character
47 * (to derive a character from UTF-8 encoded text, use
48 * g_utf8_get_char()). The break type is used to find word and line
49 * breaks ("text boundaries"), Pango implements the Unicode boundary
Matthias Clasen50d0ad92001-09-24 21:28:57 +000050 * resolution algorithms and normally you would use a function such
Havoc Pennington4eab8752001-04-16 20:05:25 +000051 * as pango_break() instead of caring about break types yourself.
52 *
William Jon McCann20f4d182014-02-19 19:35:23 -050053 * Returns: the break type of @c
Havoc Pennington4eab8752001-04-16 20:05:25 +000054 **/
Havoc Pennington54951422000-11-29 23:49:44 +000055GUnicodeBreakType
56g_unichar_break_type (gunichar c)
57{
58 return PROP (c);
59}