1 /* Procedural lookup of box drawing characters.
2 Copyright (C) 2023-2024 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
5 This file is part of GCC.
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
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
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/>. */
22 #define INCLUDE_MEMORY
23 #define INCLUDE_VECTOR
25 #include "coretypes.h"
26 #include "text-art/box-drawing.h"
28 #include "text-art/selftests.h"
32 https://en.wikipedia.org/wiki/Box-drawing_character#Character_code
33 "DOS line- and box-drawing characters are not ordered in any programmatic
34 manner, so calculating a particular character shape needs to use a look-up
37 static const cppchar_t box_drawing_chars
[] = {
38 #include "text-art/box-drawing-chars.inc"
42 text_art::get_box_drawing_char (directions line_dirs
)
44 const size_t idx
= line_dirs
.as_index ();
45 gcc_assert (idx
< 16);
46 return box_drawing_chars
[idx
];
53 /* Run all selftests in this file. */
56 text_art_box_drawing_cc_tests ()
58 ASSERT_EQ (text_art::get_box_drawing_char
59 (text_art::directions (false, false, false, false)),
61 ASSERT_EQ (text_art::get_box_drawing_char
62 (text_art::directions (false, false, true, true)),
63 0x2500); /* BOX DRAWINGS LIGHT HORIZONTAL */
64 ASSERT_EQ (text_art::get_box_drawing_char
65 (text_art::directions (true, true, false, false)),
66 0x2502); /* BOX DRAWINGS LIGHT VERTICAL */
67 ASSERT_EQ (text_art::get_box_drawing_char
68 (text_art::directions (true, false, true, false)),
69 0x2518); /* BOX DRAWINGS LIGHT UP AND LEFT */
72 } // namespace selftest
74 #endif /* #if CHECKING_P */