From c9522fb740200ccef6230cec452c48efb31e5394 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 11 May 2023 22:05:17 +0200 Subject: Removed all Printf-family functions from StringUtils. Replaced them with fmt::format calls, including changes to the format strings. Also changed the format strings to use FMT_STRING, so that the format is checked compile-time against the arguments. Also fixed code-style violations already present in the code. --- src/IniFile.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'src/IniFile.cpp') diff --git a/src/IniFile.cpp b/src/IniFile.cpp index d65154072..a5e2bc41c 100644 --- a/src/IniFile.cpp +++ b/src/IniFile.cpp @@ -378,7 +378,7 @@ void cIniFile::AddValue(const AString & a_KeyName, const AString & a_ValueName, void cIniFile::AddValueI(const AString & a_KeyName, const AString & a_ValueName, const int a_Value) { - AddValue(a_KeyName, a_ValueName, Printf("%d", a_Value)); + AddValue(a_KeyName, a_ValueName, fmt::format(FMT_STRING("{}"), a_Value)); } @@ -387,7 +387,7 @@ void cIniFile::AddValueI(const AString & a_KeyName, const AString & a_ValueName, void cIniFile::AddValueF(const AString & a_KeyName, const AString & a_ValueName, const double a_Value) { - AddValue(a_KeyName, a_ValueName, Printf("%f", a_Value)); + AddValue(a_KeyName, a_ValueName, fmt::format(FMT_STRING("{}"), a_Value)); } @@ -444,7 +444,7 @@ bool cIniFile::SetValue(const AString & a_KeyName, const AString & a_ValueName, bool cIniFile::SetValueI(const AString & a_KeyName, const AString & a_ValueName, const int a_Value, const bool a_CreateIfNotExists) { - return SetValue(a_KeyName, a_ValueName, Printf("%d", a_Value), a_CreateIfNotExists); + return SetValue(a_KeyName, a_ValueName, fmt::format(FMT_STRING("{}"), a_Value), a_CreateIfNotExists); } @@ -453,7 +453,7 @@ bool cIniFile::SetValueI(const AString & a_KeyName, const AString & a_ValueName, bool cIniFile::SetValueI(const AString & a_Keyname, const AString & a_ValueName, const Int64 a_Value, const bool a_CreateIfNotExists) { - return SetValue(a_Keyname, a_ValueName, Printf("%lld", a_Value), a_CreateIfNotExists); + return SetValue(a_Keyname, a_ValueName, fmt::format(FMT_STRING("{}"), a_Value), a_CreateIfNotExists); } @@ -462,7 +462,7 @@ bool cIniFile::SetValueI(const AString & a_Keyname, const AString & a_ValueName, bool cIniFile::SetValueF(const AString & a_KeyName, const AString & a_ValueName, double const a_Value, const bool a_CreateIfNotExists) { - return SetValue(a_KeyName, a_ValueName, Printf("%f", a_Value), a_CreateIfNotExists); + return SetValue(a_KeyName, a_ValueName, fmt::format(FMT_STRING("{}"), a_Value), a_CreateIfNotExists); } @@ -505,8 +505,7 @@ AString cIniFile::GetValue(const AString & keyname, const AString & valuename, c int cIniFile::GetValueI(const AString & keyname, const AString & valuename, const int defValue) const { - AString Data; - Printf(Data, "%d", defValue); + auto Data = fmt::format(FMT_STRING("{}"), defValue); return atoi(GetValue(keyname, valuename, Data).c_str()); } @@ -516,8 +515,7 @@ int cIniFile::GetValueI(const AString & keyname, const AString & valuename, cons double cIniFile::GetValueF(const AString & keyname, const AString & valuename, double const defValue) const { - AString Data; - Printf(Data, "%f", defValue); + auto Data = fmt::format(FMT_STRING("{}"), defValue); return atof(GetValue(keyname, valuename, Data).c_str()); } @@ -550,8 +548,7 @@ AString cIniFile::GetValueSet(const AString & keyname, const AString & valuename double cIniFile::GetValueSetF(const AString & keyname, const AString & valuename, const double defValue) { - AString Data; - Printf(Data, "%f", defValue); + auto Data = fmt::format(FMT_STRING("{}"), defValue); return atof(GetValueSet(keyname, valuename, Data).c_str()); } @@ -561,8 +558,7 @@ double cIniFile::GetValueSetF(const AString & keyname, const AString & valuename int cIniFile::GetValueSetI(const AString & keyname, const AString & valuename, const int defValue) { - AString Data; - Printf(Data, "%d", defValue); + auto Data = fmt::format(FMT_STRING("{}"), defValue); return atoi(GetValueSet(keyname, valuename, Data).c_str()); } @@ -572,8 +568,7 @@ int cIniFile::GetValueSetI(const AString & keyname, const AString & valuename, c Int64 cIniFile::GetValueSetI(const AString & keyname, const AString & valuename, const Int64 defValue) { - AString Data; - Printf(Data, "%lld", defValue); + auto Data = fmt::format(FMT_STRING("{}"), defValue); AString resultstring = GetValueSet(keyname, valuename, Data); Int64 result = defValue; #ifdef _WIN32 -- cgit v1.2.3