Pass std::span to callsign_t::copy_lower
This commit is contained in:
parent
1b92a56648
commit
afb7406127
|
@ -41,10 +41,13 @@ struct callsign_t
|
|||
a = {};
|
||||
std::copy_n(s.data(), std::min(a.size() - 1, s.size()), begin(a));
|
||||
}
|
||||
void copy_lower(const char *s, std::size_t N)
|
||||
template <std::size_t Extent>
|
||||
requires(Extent == std::dynamic_extent || Extent <= array_length)
|
||||
void copy_lower(const std::span<const char, Extent> sc)
|
||||
{
|
||||
a = {};
|
||||
std::transform(s, std::next(s, std::min(a.size() - 1, N)), begin(a), lower_predicate);
|
||||
const auto s = sc.data();
|
||||
std::transform(s, std::next(s, std::min(a.size() - 1, sc.size())), begin(a), lower_predicate);
|
||||
}
|
||||
void lower()
|
||||
{
|
||||
|
@ -62,12 +65,6 @@ struct callsign_t
|
|||
{
|
||||
copy(std::span(s));
|
||||
}
|
||||
template <std::size_t N>
|
||||
void copy_lower(const char (&s)[N])
|
||||
{
|
||||
static_assert(N <= array_length, "string too long");
|
||||
copy_lower(s, N);
|
||||
}
|
||||
void fill(char c) { a.fill(c); }
|
||||
const char &operator[](std::size_t i) const
|
||||
{
|
||||
|
|
|
@ -197,7 +197,7 @@ int ReadConfigFile()
|
|||
gr_palette_set_gamma(CGameCfg.GammaLevel);
|
||||
}
|
||||
else if (cmp(lb, eq, LastPlayerStr))
|
||||
GameCfg.LastPlayer.copy_lower(value, std::distance(value, eol));
|
||||
GameCfg.LastPlayer.copy_lower(std::span(value, std::distance(value, eol)));
|
||||
else if (cmp(lb, eq, LastMissionStr))
|
||||
convert_string(CGameCfg.LastMission, value, eol);
|
||||
else if (cmp(lb, eq, ResolutionXStr))
|
||||
|
|
|
@ -533,7 +533,7 @@ window_event_result pilot_selection_listbox::callback_handler(const d_event &eve
|
|||
else
|
||||
{
|
||||
const auto p = item[citem];
|
||||
InterfaceUniqueState.PilotName.copy_lower(p, strlen(p));
|
||||
InterfaceUniqueState.PilotName.copy_lower(std::span(p, strlen(p)));
|
||||
InterfaceUniqueState.update_window_title();
|
||||
}
|
||||
return window_event_result::close;
|
||||
|
|
|
@ -1750,7 +1750,7 @@ static auto build_udp_sequence_from_untrusted(const std::span<const uint8_t, upi
|
|||
callsign_t callsign;
|
||||
/* Skip over the first byte, since it is the UPID code */
|
||||
std::size_t position = 1;
|
||||
callsign.copy_lower(reinterpret_cast<const char *>(&untrusted[position]), CALLSIGN_LEN);
|
||||
callsign.copy_lower(std::span<const char, CALLSIGN_LEN>(reinterpret_cast<const char *>(&untrusted[position]), CALLSIGN_LEN));
|
||||
position += CALLSIGN_LEN + 1;
|
||||
const netplayer_info::player_rank rank = build_rank_from_untrusted(untrusted[++position]);
|
||||
return std::tuple(callsign, rank);
|
||||
|
@ -3176,7 +3176,7 @@ static void net_udp_process_game_info_heavy(const uint8_t *data, uint_fast32_t,
|
|||
Netgame.protocol.udp.your_index = data[len]; ++len;
|
||||
range_for (auto &i, Netgame.players)
|
||||
{
|
||||
i.callsign.copy_lower(reinterpret_cast<const char *>(&data[len]), CALLSIGN_LEN);
|
||||
i.callsign.copy_lower(std::span<const char, CALLSIGN_LEN>(reinterpret_cast<const char *>(&data[len]), CALLSIGN_LEN));
|
||||
len += CALLSIGN_LEN+1;
|
||||
i.connected = player_connection_status{data[len]}; len++;
|
||||
i.rank = build_rank_from_untrusted(data[len]); len++;
|
||||
|
|
Loading…
Reference in a new issue