/src/fribidi/lib/fribidi-brackets.c
Line | Count | Source |
1 | | /* fribidi-brackets.c - get bracketed character |
2 | | * |
3 | | * Copyright (C) 2004 Sharif FarsiWeb, Inc |
4 | | * Copyright (C) 2001, 2002, 2004 Behdad Esfahbod |
5 | | * Copyright (C) 1999, 2000, 2017 Dov Grobgeld |
6 | | * |
7 | | * This file is part of GNU FriBidi. |
8 | | * |
9 | | * GNU FriBidi is free software; you can redistribute it and/or |
10 | | * modify it under the terms of the GNU Lesser General Public License |
11 | | * as published by the Free Software Foundation; either version 2.1 |
12 | | * of the License, or (at your option) any later version. |
13 | | * |
14 | | * GNU FriBidi is distributed in the hope that it will be useful, |
15 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | | * GNU Lesser General Public License for more details. |
18 | | * |
19 | | * You should have received a copy of the GNU Lesser General Public License |
20 | | * along with GNU FriBidi; if not, write to the Free Software |
21 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | | * |
23 | | * For licensing issues, contact <fribidi.license@gmail.com> or write to |
24 | | * Sharif FarsiWeb, Inc., PO Box 13445-389, Tehran, Iran. |
25 | | */ |
26 | | /* |
27 | | * Author(s): |
28 | | * Behdad Esfahbod, 2001, 2002, 2004 |
29 | | * Dov Grobgeld, 1999, 2000, 2017 |
30 | | */ |
31 | | |
32 | | #include "common.h" |
33 | | |
34 | | #include <fribidi-brackets.h> |
35 | | |
36 | | #include "brackets.tab.i" |
37 | | #include "brackets-type.tab.i" |
38 | | #include <stdio.h> |
39 | | |
40 | 3.12M | #define FRIBIDI_TYPE_BRACKET_OPEN 2 |
41 | | |
42 | | FRIBIDI_ENTRY FriBidiBracketType |
43 | | fribidi_get_bracket ( |
44 | | /* input */ |
45 | | FriBidiChar ch |
46 | | ) |
47 | 3.29M | { |
48 | 3.29M | FriBidiBracketType bracket_type; |
49 | 3.29M | register uint8_t char_type = FRIBIDI_GET_BRACKET_TYPE (ch); |
50 | | |
51 | | /* The bracket type from the table may be: |
52 | | 0 - Not a bracket |
53 | | 1 - a bracket |
54 | | 2 - closing. |
55 | | |
56 | | This will be recodeded into the FriBidiBracketType as having a |
57 | | bracket_id = 0 if the character is not a bracket. |
58 | | */ |
59 | 3.29M | fribidi_boolean is_open = false; |
60 | | |
61 | 3.29M | if (char_type == 0) |
62 | 168k | bracket_type = FRIBIDI_NO_BRACKET; |
63 | 3.12M | else |
64 | 3.12M | { |
65 | 3.12M | is_open = (char_type & FRIBIDI_TYPE_BRACKET_OPEN) != 0; |
66 | 3.12M | bracket_type = FRIBIDI_GET_BRACKETS (ch) & FRIBIDI_BRACKET_ID_MASK; |
67 | 3.12M | } |
68 | 3.29M | if (is_open) |
69 | 1.56M | bracket_type |= FRIBIDI_BRACKET_OPEN_MASK; |
70 | | |
71 | 3.29M | return bracket_type; |
72 | 3.29M | } |
73 | | |
74 | | FRIBIDI_ENTRY void |
75 | | fribidi_get_bracket_types ( |
76 | | /* input */ |
77 | | const FriBidiChar *str, |
78 | | const FriBidiStrIndex len, |
79 | | const FriBidiCharType *types, |
80 | | /* output */ |
81 | | FriBidiBracketType *btypes |
82 | | ) |
83 | 1.91k | { |
84 | 1.91k | FriBidiStrIndex i; |
85 | 16.9M | for (i=0; i<len; i++) |
86 | 16.9M | { |
87 | | /* Optimization that bracket must be of types ON */ |
88 | 16.9M | if (*types == FRIBIDI_TYPE_ON) |
89 | 3.29M | *btypes = fribidi_get_bracket (*str); |
90 | 13.6M | else |
91 | 13.6M | *btypes = FRIBIDI_NO_BRACKET; |
92 | | |
93 | 16.9M | btypes++; |
94 | 16.9M | types++; |
95 | 16.9M | str++; |
96 | 16.9M | } |
97 | 1.91k | } |
98 | | |
99 | | /* Editor directions: |
100 | | * Local Variables: |
101 | | * mode: c |
102 | | * c-basic-offset: 2 |
103 | | * indent-tabs-mode: t |
104 | | * tab-width: 8 |
105 | | * End: |
106 | | * vim: textwidth=78: autoindent: cindent: shiftwidth=2: tabstop=8: |
107 | | */ |