Euphoria
cp437.cc
Go to the documentation of this file.
1 #include "core/cp437.h"
2 
3 #include <array>
4 
5 #include "assert/assert.h"
6 #include "base/random.h"
7 #include "base/range.h"
8 
9 namespace
10 {
11  constexpr std::array<std::string_view, 256> code_page =
12  {
13  // _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _A _B _C _D _E _F
14 /*0_*/ "NULL", "☺", "☻", "♥", "♦", "♣", "♠", "•", "◘", "○", "◙", "♂", "♀", "♪", "♫", "☼",
15 /*1_*/ "►", "◄", "↕", "‼", "¶", "§", "▬", "↨", "↑", "↓", "→", "←", "∟", "↔", "▲", "▼",
16 /*2_*/ " ", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/",
17 /*3_*/ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<", "=", ">", "?",
18 /*4_*/ "@", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O",
19 /*5_*/ "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "[", "\\", "]", "^", "_",
20 /*6_*/ "`", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
21 /*7_*/ "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "{", "|", "}", "~", "⌂",
22 /*8_*/ "Ç", "ü", "é", "â", "ä", "à", "å", "ç", "ê", "ë", "è", "ï", "î", "ì", "Ä", "Å",
23 /*9_*/ "É", "æ", "Æ", "ô", "ö", "ò", "û", "ù", "ÿ", "Ö", "Ü", "¢", "£", "¥", "₧", "ƒ",
24 /*A_*/ "á", "í", "ó", "ú", "ñ", "Ñ", "ª", "º", "¿", "⌐", "¬", "½", "¼", "¡", "«", "»",
25 /*B_*/ "░", "▒", "▓", "│", "┤", "╡", "╢", "╖", "╕", "╣", "║", "╗", "╝", "╜", "╛", "┐",
26 /*C_*/ "└", "┴", "┬", "├", "─", "┼", "╞", "╟", "╚", "╔", "╩", "╦", "╠", "═", "╬", "╧",
27 /*D_*/ "╨", "╤", "╥", "╙", "╘", "╒", "╓", "╫", "╪", "┘", "┌", "█", "▄", "▌", "▐", "▀",
28 /*E_*/ "α", "ß", "Γ", "π", "Σ", "σ", "µ", "τ", "Φ", "Θ", "Ω", "δ", "∞", "φ", "ε", "∩",
29 /*F_*/ "≡", "±", "≥", "≤", "⌠", "⌡", "÷", "≈", "°", "∙", "·", "√", "ⁿ", "²", "■", "nbsp"
30  };
31 }
32 
33 namespace eu::core
34 {
35  std::string_view
36  get_cp437(int c)
37  {
39  return code_page[c];
40  }
41 
42  std::string_view
44  {
45  while(true)
46  {
47  const auto c = get_random_in_range(random, 256);
48  if(c == 0x00) { continue; } // not NULL
49  if(c == 0x20) { continue; } // neither Space
50  if(c == 0xFF) { continue; } // neither NBSP
51  return get_cp437(c);
52  }
53  }
54 }
#define ASSERTX(x,...)
Definition: assert.h:48
std::string_view get_random_cp437_in_utf8(Random *random)
Definition: cp437.cc:43
std::string_view get_cp437(int c)
Definition: cp437.cc:36
bool is_within_inclusive_as_int(int min, int c, int max)
Definition: numeric.cc:116
T get_random_in_range(Random *rand, const Range< T > &range)
Definition: random.h:50
WEL512 Random Number Generator.
Definition: random.h:21