Line data Source code
1 : /* Procedural lookup of box drawing characters.
2 : Copyright (C) 2023-2026 Free Software Foundation, Inc.
3 : Contributed by David Malcolm <dmalcolm@redhat.com>.
4 :
5 : This file is part of GCC.
6 :
7 : GCC is free software; you can redistribute it and/or modify it under
8 : the terms of the GNU General Public License as published by the Free
9 : Software Foundation; either version 3, or (at your option) any later
10 : version.
11 :
12 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 : 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 GCC; see the file COPYING3. If not see
19 : <http://www.gnu.org/licenses/>. */
20 :
21 : #include "config.h"
22 : #define INCLUDE_VECTOR
23 : #include "system.h"
24 : #include "coretypes.h"
25 : #include "text-art/box-drawing.h"
26 : #include "selftest.h"
27 : #include "text-art/selftests.h"
28 :
29 :
30 : /* According to
31 : https://en.wikipedia.org/wiki/Box-drawing_character#Character_code
32 : "DOS line- and box-drawing characters are not ordered in any programmatic
33 : manner, so calculating a particular character shape needs to use a look-up
34 : table. "
35 : Hence this array. */
36 : static const cppchar_t box_drawing_chars[] = {
37 : #include "text-art/box-drawing-chars.inc"
38 : };
39 :
40 : cppchar_t
41 16554 : text_art::get_box_drawing_char (directions line_dirs)
42 : {
43 16554 : const size_t idx = line_dirs.as_index ();
44 16554 : gcc_assert (idx < 16);
45 16554 : return box_drawing_chars[idx];
46 : }
47 :
48 : #if CHECKING_P
49 :
50 : namespace selftest {
51 :
52 : /* Run all selftests in this file. */
53 :
54 : void
55 4 : text_art_box_drawing_cc_tests ()
56 : {
57 4 : ASSERT_EQ (text_art::get_box_drawing_char
58 : (text_art::directions (false, false, false, false)),
59 : ' ');
60 4 : ASSERT_EQ (text_art::get_box_drawing_char
61 : (text_art::directions (false, false, true, true)),
62 : 0x2500); /* BOX DRAWINGS LIGHT HORIZONTAL */
63 4 : ASSERT_EQ (text_art::get_box_drawing_char
64 : (text_art::directions (true, true, false, false)),
65 : 0x2502); /* BOX DRAWINGS LIGHT VERTICAL */
66 4 : ASSERT_EQ (text_art::get_box_drawing_char
67 : (text_art::directions (true, false, true, false)),
68 : 0x2518); /* BOX DRAWINGS LIGHT UP AND LEFT */
69 4 : }
70 :
71 : } // namespace selftest
72 :
73 : #endif /* #if CHECKING_P */
|