Show nicknames on profile cards

C++ · C++ · intermediate · modification

Members can set a nickname, but cards still show their legal first and last name. This PR adds `profile::display_name` (declared in `src/profile/display_name.hpp`, implemented in `src/profile/display_name.cpp`): it trims the nickname with the existing `text::trim` and uses it when anything is left, and otherwise falls back to the first and last name, trimmed so that a member without a last name gets no trailing space. `src/profile/card.cpp` now builds the card from the display name followed by the handle. `tests/display_name_test.cpp` (new) adds unit tests for `display_name` and the card.

C++20, standard library only, built with CMake (unchanged: it builds `src/**/*.cpp` into the service library and every `tests/*_test.cpp` together with `tests/check_main.cpp` into the test runner) by Apple clang 17 locally and GCC 13 in CI, with `-Wall -Wextra -Wconversion -Werror`. Request handlers run on several threads; each loads its own copy of a `Profile` from the store, and no `Profile` is shared between threads or modified while a card is rendered. Existing and unchanged: `profile::Profile` (`src/profile/profile.hpp`) is a struct of four `std::string` fields: `handle` (1 to 32 ASCII lowercase letters, digits and underscores), `nickname` (0 to 32 bytes of UTF-8 as the member typed it, possibly empty, blank, or with leading and trailing spaces and tabs), `first_name` (1 to 64 bytes, never empty, stored without leading or trailing whitespace) and `last_name` (0 to 64 bytes, stored without leading or trailing whitespace); sign-up rejects control characters other than tab and whitespace other than ASCII space and tab in all of them. `text::trim` (`src/text/trim.hpp`) is `std::string_view trim(std::string_view s) noexcept`: it returns the part of `s` without leading and trailing ASCII spaces and tabs (an empty view when nothing is left), pointing into the characters of `s` without copying them. `profile::render_card(const Profile&)` is declared in `src/profile/card.hpp` and returns `std::string`. `tests/check.hpp` is the repo's tiny test helper: `TEST(name) { ... }` registers a test, `CHECK(expr)` and `CHECK_EQ(a, b)` record a failure with file and line, and the `main` in `tests/check_main.cpp` runs every registered test and exits non-zero if any check failed.

Requirements

Files touched

Review this PR

C++ practice