[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
+4 -3
View File
@@ -46,8 +46,7 @@ int main()
auto ConfigLoadResult = EQEmuConfig::LoadConfig();
Config = EQEmuConfig::get();
try {
std::ofstream outfile("test_output.txt");
std::unique_ptr<Test::Output> output(new Test::TextOutput(Test::TextOutput::Verbose, outfile));
std::unique_ptr<Test::Output> output(new Test::TextOutput(Test::TextOutput::Verbose));
Test::Suite tests;
tests.add(new MemoryMappedFileTest());
tests.add(new IPCMutexTest());
@@ -60,7 +59,9 @@ int main()
tests.add(new SkillsUtilsTest());
tests.add(new TaskStateTest());
tests.run(*output, true);
} catch (...) {
}
catch (std::exception &ex) {
LogError("Test Failure [{}]", ex.what());
return -1;
}
return 0;
+22
View File
@@ -31,6 +31,8 @@ public:
TEST_ADD(StringUtilTest::SearchDeliminatedStringTest);
TEST_ADD(StringUtilTest::SplitStringTest);
TEST_ADD(StringUtilTest::FromCharsTest);
TEST_ADD(StringUtilTest::TestIsFloat);
TEST_ADD(StringUtilTest::TestIsNumber);
}
~StringUtilTest() {
@@ -116,6 +118,26 @@ public:
TEST_ASSERT(float_value == 3.14f);
}
void TestIsFloat() {
TEST_ASSERT_EQUALS(Strings::IsFloat("0.23424523"), true);
TEST_ASSERT_EQUALS(Strings::IsFloat("12312312313.23424523"), true);
TEST_ASSERT_EQUALS(Strings::IsFloat("12312312313"), true);
TEST_ASSERT_EQUALS(Strings::IsFloat(".234234"), true);
TEST_ASSERT_EQUALS(Strings::IsFloat(".234234f"), false);
TEST_ASSERT_EQUALS(Strings::IsFloat("Johnson"), false);
}
void TestIsNumber() {
TEST_ASSERT_EQUALS(Strings::IsNumber("0.23424523"), false);
TEST_ASSERT_EQUALS(Strings::IsNumber("12312312313.23424523"), false);
TEST_ASSERT_EQUALS(Strings::IsNumber("12312312313"), true);
TEST_ASSERT_EQUALS(Strings::IsNumber("12312312313f"), false); // character at end
TEST_ASSERT_EQUALS(Strings::IsNumber("18446744073709551616"), true); // 64
TEST_ASSERT_EQUALS(Strings::IsNumber("-18"), true);
TEST_ASSERT_EQUALS(Strings::IsNumber("-f18"), false);
TEST_ASSERT_EQUALS(Strings::IsNumber("-18446744073709551616"), true); // 64
}
};
#endif