[Strings] Add more number formatters (#2873)

* [Strings] Add more number formatters

# Notes
- Adds `Strings::ToUnsignedInt` for `uint32` support.
- Adds `Strings::ToBigInt` for `int64` support.
- Adds `Strings::ToUnsignedBigInt` for `uint64` support.
- Adds `Strings::ToFloat` for `float` support.
- Replaces all `std::stoi` references with `Strings::ToInt`.
- Replaces all `atoi` references with `Strings::ToInt`.
- Replaces all `std::stoul` references with `Strings::ToUnsignedInt`.
- Replaces all `atoul` references with `Strings::ToUnsignedInt`.
- Replaces all `std::stoll` references with `Strings::ToBigInt`.
- Replaces all `atoll` references with `Strings::ToBigInt`.
- Replaces all `std::stoull` references with `Strings::ToUnsignedBigInt`.
- Replaces all `atoull` references with `Strings::ToUnsignedBigInt`.
- Replaces all `std::stof` references with `Strings::ToFloat`.

* [Strings] Add more number formatters

- Adds `Strings::ToUnsignedInt` for `uint32` support.
- Adds `Strings::ToBigInt` for `int64` support.
- Adds `Strings::ToUnsignedBigInt` for `uint64` support.
- Adds `Strings::ToFloat` for `float` support.
- Replaces all `std::stoi` references with `Strings::ToInt`.
- Replaces all `atoi` references with `Strings::ToInt`.
- Replaces all `std::stoul` references with `Strings::ToUnsignedInt`.
- Replaces all `atoul` references with `Strings::ToUnsignedInt`.
- Replaces all `std::stoll` references with `Strings::ToBigInt`.
- Replaces all `atoll` references with `Strings::ToBigInt`.
- Replaces all `std::stoull` references with `Strings::ToUnsignedBigInt`.
- Replaces all `atoull` references with `Strings::ToUnsignedBigInt`.
- Replaces all `std::stof` references with `Strings::ToFloat`.

* Rebase cleanup

* Changes/benchmarks/tests

---------

Co-authored-by: Akkadius <akkadius1@gmail.com>
This commit is contained in:
Alex King
2023-03-04 18:01:19 -05:00
committed by GitHub
parent be567af70d
commit 2a6cf8c8e7
261 changed files with 3178 additions and 3012 deletions
+1 -1
View File
@@ -657,7 +657,7 @@ ChatChannel *ChatChannelList::RemoveClientFromChannel(const std::string& in_chan
std::string channel_name = in_channel_name;
if (in_channel_name.length() > 0 && isdigit(channel_name[0])) {
channel_name = c->ChannelSlotName(atoi(in_channel_name.c_str()));
channel_name = c->ChannelSlotName(Strings::ToInt(in_channel_name.c_str()));
}
auto *required_channel = FindChannel(channel_name);
+14 -14
View File
@@ -379,14 +379,14 @@ static void ProcessSetMessageStatus(std::string SetMessageCommand) {
if (NumEnd == std::string::npos) {
MessageNumber = atoi(SetMessageCommand.substr(NumStart).c_str());
MessageNumber = Strings::ToInt(SetMessageCommand.substr(NumStart).c_str());
database.SetMessageStatus(MessageNumber, Status);
break;
}
MessageNumber = atoi(SetMessageCommand.substr(NumStart, NumEnd - NumStart).c_str());
MessageNumber = Strings::ToInt(SetMessageCommand.substr(NumStart, NumEnd - NumStart).c_str());
database.SetMessageStatus(MessageNumber, Status);
@@ -876,7 +876,7 @@ void Clientlist::ProcessOPMailCommand(Client *c, std::string command_string, boo
break;
case CommandGetBody:
database.SendBody(c, atoi(parameters.c_str()));
database.SendBody(c, Strings::ToInt(parameters.c_str()));
break;
case CommandMailTo:
@@ -891,7 +891,7 @@ void Clientlist::ProcessOPMailCommand(Client *c, std::string command_string, boo
case CommandSelectMailBox:
{
std::string::size_type NumStart = parameters.find_first_of("0123456789");
c->ChangeMailBox(atoi(parameters.substr(NumStart).c_str()));
c->ChangeMailBox(Strings::ToInt(parameters.substr(NumStart).c_str()));
break;
}
case CommandSetMailForwarding:
@@ -1253,7 +1253,7 @@ void Client::ProcessChannelList(std::string Input) {
std::string ChannelName = Input;
if (isdigit(ChannelName[0]))
ChannelName = ChannelSlotName(atoi(ChannelName.c_str()));
ChannelName = ChannelSlotName(Strings::ToInt(ChannelName.c_str()));
ChatChannel *RequiredChannel = ChannelList->FindChannel(ChannelName);
@@ -1414,7 +1414,7 @@ void Client::SendChannelMessageByNumber(std::string Message) {
if (MessageStart == std::string::npos)
return;
int ChannelNumber = atoi(Message.substr(0, MessageStart).c_str());
int ChannelNumber = Strings::ToInt(Message.substr(0, MessageStart).c_str());
if ((ChannelNumber < 1) || (ChannelNumber > MAX_JOINED_CHANNELS)) {
@@ -1657,7 +1657,7 @@ void Client::SetChannelPassword(std::string ChannelPassword) {
std::string ChannelName = ChannelPassword.substr(ChannelStart);
if ((ChannelName.length() > 0) && isdigit(ChannelName[0]))
ChannelName = ChannelSlotName(atoi(ChannelName.c_str()));
ChannelName = ChannelSlotName(Strings::ToInt(ChannelName.c_str()));
std::string Message;
@@ -1722,7 +1722,7 @@ void Client::SetChannelOwner(std::string CommandString) {
std::string ChannelName = CapitaliseName(CommandString.substr(ChannelStart));
if ((ChannelName.length() > 0) && isdigit(ChannelName[0]))
ChannelName = ChannelSlotName(atoi(ChannelName.c_str()));
ChannelName = ChannelSlotName(Strings::ToInt(ChannelName.c_str()));
LogInfo("Set owner of channel [[{}]] to [[{}]]", ChannelName.c_str(), NewOwner.c_str());
@@ -1768,7 +1768,7 @@ void Client::OPList(std::string CommandString) {
std::string ChannelName = CapitaliseName(CommandString.substr(ChannelStart));
if ((ChannelName.length() > 0) && isdigit(ChannelName[0]))
ChannelName = ChannelSlotName(atoi(ChannelName.c_str()));
ChannelName = ChannelSlotName(Strings::ToInt(ChannelName.c_str()));
ChatChannel *RequiredChannel = ChannelList->FindChannel(ChannelName);
@@ -1811,7 +1811,7 @@ void Client::ChannelInvite(std::string CommandString) {
std::string ChannelName = CapitaliseName(CommandString.substr(ChannelStart));
if ((ChannelName.length() > 0) && isdigit(ChannelName[0]))
ChannelName = ChannelSlotName(atoi(ChannelName.c_str()));
ChannelName = ChannelSlotName(Strings::ToInt(ChannelName.c_str()));
LogInfo("[[{}]] invites [[{}]] to channel [[{}]]", GetName().c_str(), Invitee.c_str(), ChannelName.c_str());
@@ -1881,7 +1881,7 @@ void Client::ChannelModerate(std::string CommandString) {
std::string ChannelName = CapitaliseName(CommandString.substr(ChannelStart));
if ((ChannelName.length() > 0) && isdigit(ChannelName[0]))
ChannelName = ChannelSlotName(atoi(ChannelName.c_str()));
ChannelName = ChannelSlotName(Strings::ToInt(ChannelName.c_str()));
ChatChannel *RequiredChannel = ChannelList->FindChannel(ChannelName);
@@ -1939,7 +1939,7 @@ void Client::ChannelGrantModerator(std::string CommandString) {
std::string ChannelName = CapitaliseName(CommandString.substr(ChannelStart));
if ((ChannelName.length() > 0) && isdigit(ChannelName[0]))
ChannelName = ChannelSlotName(atoi(ChannelName.c_str()));
ChannelName = ChannelSlotName(Strings::ToInt(ChannelName.c_str()));
LogInfo("[[{}]] gives [[{}]] moderator rights to channel [[{}]]", GetName().c_str(), Moderator.c_str(), ChannelName.c_str());
@@ -2020,7 +2020,7 @@ void Client::ChannelGrantVoice(std::string CommandString) {
std::string ChannelName = CapitaliseName(CommandString.substr(ChannelStart));
if ((ChannelName.length() > 0) && isdigit(ChannelName[0]))
ChannelName = ChannelSlotName(atoi(ChannelName.c_str()));
ChannelName = ChannelSlotName(Strings::ToInt(ChannelName.c_str()));
LogInfo("[[{}]] gives [[{}]] voice to channel [[{}]]", GetName().c_str(), Voicee.c_str(), ChannelName.c_str());
@@ -2108,7 +2108,7 @@ void Client::ChannelKick(std::string CommandString) {
std::string ChannelName = CapitaliseName(CommandString.substr(ChannelStart));
if ((ChannelName.length() > 0) && isdigit(ChannelName[0]))
ChannelName = ChannelSlotName(atoi(ChannelName.c_str()));
ChannelName = ChannelSlotName(Strings::ToInt(ChannelName.c_str()));
LogInfo("[[{}]] kicks [[{}]] from channel [[{}]]", GetName().c_str(), Kickee.c_str(), ChannelName.c_str());
+11 -11
View File
@@ -84,10 +84,10 @@ void UCSDatabase::GetAccountStatus(Client *client)
auto row = results.begin();
client->SetAccountStatus(atoi(row[0]));
client->SetHideMe(atoi(row[1]) != 0);
client->SetKarma(atoi(row[2]));
client->SetRevoked((atoi(row[3]) == 1 ? true : false));
client->SetAccountStatus(Strings::ToInt(row[0]));
client->SetHideMe(Strings::ToInt(row[1]) != 0);
client->SetKarma(Strings::ToInt(row[2]));
client->SetRevoked((Strings::ToInt(row[3]) == 1 ? true : false));
LogDebug(
"Set account status to [{}], hideme to [{}] and karma to [{}] for [{}]",
@@ -119,9 +119,9 @@ int UCSDatabase::FindAccount(const char *characterName, Client *client)
}
auto row = results.begin();
client->AddCharacter(atoi(row[0]), characterName, atoi(row[2]));
client->AddCharacter(Strings::ToInt(row[0]), characterName, Strings::ToInt(row[2]));
int accountID = atoi(row[1]);
int accountID = Strings::ToInt(row[1]);
LogInfo("Account ID for [{}] is [{}]", characterName, accountID);
@@ -137,7 +137,7 @@ int UCSDatabase::FindAccount(const char *characterName, Client *client)
}
for (auto row = results.begin(); row != results.end(); ++row)
client->AddCharacter(atoi(row[0]), row[1], atoi(row[2]));
client->AddCharacter(Strings::ToInt(row[0]), row[1], Strings::ToInt(row[2]));
return accountID;
}
@@ -197,7 +197,7 @@ int UCSDatabase::FindCharacter(const char *characterName)
auto row = results.begin();
int characterID = atoi(row[0]);
int characterID = Strings::ToInt(row[0]);
return characterID;
}
@@ -224,7 +224,7 @@ bool UCSDatabase::GetVariable(const char *varname, char *varvalue, uint16 varval
bool UCSDatabase::LoadChatChannels()
{
{
if (!RuleB(Chat, ChannelsIgnoreNameFilter)) {
LoadFilteredNamesFromDB();
}
@@ -244,7 +244,7 @@ bool UCSDatabase::LoadChatChannels()
auto channel_min_status = row[3];
if (!ChannelList->FindChannel(channel_name)) {
ChannelList->CreateChannel(channel_name, channel_owner, channel_password, true, atoi(channel_min_status), false);
ChannelList->CreateChannel(channel_name, channel_owner, channel_password, true, Strings::ToInt(channel_min_status), false);
}
}
return true;
@@ -743,7 +743,7 @@ void UCSDatabase::GetFriendsAndIgnore(const int& charID, std::vector<std::string
for (auto row = results.begin(); row != results.end(); ++row) {
std::string name = row[1];
if (atoi(row[0]) == 0) {
if (Strings::ToInt(row[0]) == 0) {
ignorees.push_back(name);
LogInfo("Added Ignoree from DB [{}]", name.c_str());
continue;
-2
View File
@@ -35,8 +35,6 @@
#include <vector>
#include <map>
//atoi is not uint32 or uint32 safe!!!!
#define atoul(str) strtoul(str, nullptr, 10)
class UCSDatabase : public Database {
public: