UnicodeUtils.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright (c) 2021, Max Wipfli <mail@maxwipfli.ch>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Array.h>
  7. #include <AK/Optional.h>
  8. #include <AK/StringView.h>
  9. #include <AK/UnicodeUtils.h>
  10. namespace AK::UnicodeUtils {
  11. Optional<StringView> get_unicode_control_code_point_alias(u32 code_point)
  12. {
  13. static constexpr Array<StringView, 32> ascii_controls_lookup_table = {
  14. "NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL",
  15. "BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI",
  16. "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",
  17. "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US"
  18. };
  19. static constexpr Array<StringView, 32> c1_controls_lookup_table = {
  20. "XXX", "XXX", "BPH", "NBH", "IND", "NEL", "SSA", "ESA",
  21. "HTS", "HTJ", "VTS", "PLD", "PLU", "RI", "SS2", "SS3",
  22. "DCS", "PU1", "PU2", "STS", "CCH", "MW", "SPA", "EPA",
  23. "SOS", "XXX", "SCI", "CSI", "ST", "OSC", "PM", "APC"
  24. };
  25. if (code_point < 0x20)
  26. return ascii_controls_lookup_table[code_point];
  27. if (code_point >= 0x80 && code_point < 0xa0)
  28. return c1_controls_lookup_table[code_point - 0x80];
  29. return {};
  30. }
  31. }