refactor: AprsSymbol.normalize_symbol_table pattern-matches on input

- Three-way cond (known-table / overlay-capable char / fallback) becomes
  three function heads: a guard-matched clause for the canonical
  "/"/"\\"/"]" tables, an is_binary clause that decides via regex match
  whether the input is a single alphanumeric overlay character, and a
  catch-all fallback.
This commit is contained in:
Graham McIntire 2026-04-23 14:29:12 -05:00
parent 2e5034f8c3
commit 9053eef2c6
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -164,14 +164,19 @@ defmodule AprsmeWeb.AprsSymbol do
"/"
"""
@spec normalize_symbol_table(String.t() | nil) :: String.t()
def normalize_symbol_table(symbol_table) do
cond do
symbol_table in ["/", "\\", "]"] -> symbol_table
symbol_table && String.match?(symbol_table, ~r/^[A-Z0-9]$/) -> "]"
true -> "/"
def normalize_symbol_table(table) when table in ["/", "\\", "]"], do: table
def normalize_symbol_table(table) when is_binary(table) do
# A single alphanumeric character is an overlay — map to the overlay table.
if String.match?(table, ~r/^[A-Z0-9]$/) do
"]"
else
"/"
end
end
def normalize_symbol_table(_), do: "/"
@doc """
Normalizes a symbol code.