1/* Procedural lookup of box drawing characters.
2 Copyright (C) 2023-2024 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 3, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along 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. */
36static const cppchar_t box_drawing_chars[] = {
37#include "text-art/box-drawing-chars.inc"
38};
39
40cppchar_t
41text_art::get_box_drawing_char (directions line_dirs)
42{
43 const size_t idx = line_dirs.as_index ();
44 gcc_assert (idx < 16);
45 return box_drawing_chars[idx];
46}
47
48#if CHECKING_P
49
50namespace selftest {
51
52/* Run all selftests in this file. */
53
54void
55text_art_box_drawing_cc_tests ()
56{
57 ASSERT_EQ (text_art::get_box_drawing_char
58 (text_art::directions (false, false, false, false)),
59 ' ');
60 ASSERT_EQ (text_art::get_box_drawing_char
61 (text_art::directions (false, false, true, true)),
62 0x2500); /* BOX DRAWINGS LIGHT HORIZONTAL */
63 ASSERT_EQ (text_art::get_box_drawing_char
64 (text_art::directions (true, true, false, false)),
65 0x2502); /* BOX DRAWINGS LIGHT VERTICAL */
66 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}
70
71} // namespace selftest
72
73#endif /* #if CHECKING_P */
74

source code of gcc/text-art/box-drawing.cc