Skip to content

Commit

Permalink
iox-eclipse-iceoryx#2055 Rename fromString to from_string
Browse files Browse the repository at this point in the history
Rename `fromString` to `from_string`. Note that the name of test cases
are not included.

Signed-off-by: Dennis Liu <[email protected]>
  • Loading branch information
Dennis40816 committed Dec 11, 2023
1 parent 79f038b commit 765cdec
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 102 deletions.
2 changes: 1 addition & 1 deletion iceoryx_dust/cli/include/iox/cli/arguments.inl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ template <typename T>
inline expected<T, Arguments::Error> Arguments::convertFromString(const Argument_t& stringValue) const noexcept
{
T value;
if (!convert::fromString(stringValue.c_str(), value))
if (!convert::from_string(stringValue.c_str(), value))
{
std::cout << "\"" << stringValue.c_str() << "\" could not be converted to the requested type" << std::endl;
return err(Error::UNABLE_TO_CONVERT_VALUE);
Expand Down
6 changes: 3 additions & 3 deletions iceoryx_dust/utility/include/iox/detail/serialization.inl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ inline bool Serialization::deserialize(const std::string& serializedString, T& t
return false;
}

if (!convert::fromString(entry.c_str(), t))
if (!convert::from_string(entry.c_str(), t))
{
return false;
}
Expand All @@ -111,7 +111,7 @@ inline bool Serialization::removeFirstEntry(std::string& firstEntry, std::string
}

uint64_t length{0};
if (!convert::fromString(remainder.substr(0, pos).c_str(), length))
if (!convert::from_string(remainder.substr(0, pos).c_str(), length))
{
return false;
}
Expand Down Expand Up @@ -140,7 +140,7 @@ inline bool Serialization::getNth(const unsigned int index, T& t) const noexcept
}
}

return convert::fromString(entry.c_str(), t);
return convert::from_string(entry.c_str(), t);
}
} // namespace iox

Expand Down
2 changes: 1 addition & 1 deletion iceoryx_examples/iceperf/main_follower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int main(int argc, char* argv[])
constexpr decltype(EXIT_SUCCESS) MOO{EXIT_SUCCESS};

uint64_t intensity{0U};
if (!iox::convert::fromString(optarg, intensity))
if (!iox::convert::from_string(optarg, intensity))
{
std::cerr << "Could not parse 'intensity' paramater!" << std::endl;
return EXIT_FAILURE;
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_examples/iceperf/main_leader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ int main(int argc, char* argv[])
}
break;
case 'n':
if (!iox::convert::fromString(optarg, settings.numberOfSamples))
if (!iox::convert::from_string(optarg, settings.numberOfSamples))
{
std::cerr << "Could not parse 'number-of-samples' paramater!" << std::endl;
return EXIT_FAILURE;
Expand Down
88 changes: 44 additions & 44 deletions iceoryx_hoofs/test/moduletests/test_utility_convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ TEST_F(convert_test, FromString_String)
::testing::Test::RecordProperty("TEST_ID", "22463da5-0fcb-4aa2-a7e5-68b863278a81");
std::string source = "hello";
std::string destination;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(true));
EXPECT_THAT(source, Eq(destination));
}

Expand All @@ -118,7 +118,7 @@ TEST_F(convert_test, fromString_Char_Success)
::testing::Test::RecordProperty("TEST_ID", "a15825c9-536a-4671-a502-6973490022e7");
std::string source = "h";
char destination = '\0';
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(true));
EXPECT_THAT(source[0], Eq(destination));
}

Expand All @@ -127,7 +127,7 @@ TEST_F(convert_test, fromString_Char_Fail)
::testing::Test::RecordProperty("TEST_ID", "656e87ad-6fdb-42d7-bf49-23f81a4f5a31");
std::string source = "hasd";
char destination = '\0';
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(false));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(false));
}

TEST_F(convert_test, stringIsNumber_IsINTEGER)
Expand Down Expand Up @@ -189,7 +189,7 @@ TEST_F(convert_test, fromString_FLOAT_Success)
::testing::Test::RecordProperty("TEST_ID", "d6255c3e-369e-43a0-a1ab-03f7b13d03c2");
std::string source = "123.01";
float destination = 0.0F;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(true));
EXPECT_FLOAT_EQ(destination, 123.01F);
}

Expand All @@ -198,15 +198,15 @@ TEST_F(convert_test, fromString_FLOAT_Fail)
::testing::Test::RecordProperty("TEST_ID", "e2b94d50-664c-4f9e-be4f-99212c6fa165");
std::string source = "hasd";
float destination = 0.0F;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(false));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(false));
}

TEST_F(convert_test, fromString_Double_Success)
{
::testing::Test::RecordProperty("TEST_ID", "95ba379e-120e-4b80-a829-33fe54f1bfed");
std::string source = "123.04";
double destination = 0.0;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(true));
EXPECT_THAT(destination, Eq(123.04));
}

Expand All @@ -215,7 +215,7 @@ TEST_F(convert_test, fromString_Double_Fail)
::testing::Test::RecordProperty("TEST_ID", "f4ace11b-a056-47b1-b6c5-6fb2c58e1a06");
std::string source = "hasd";
double destination = 0.0;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(false));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(false));
}

TEST_F(convert_test, fromString_LongDouble_Success)
Expand All @@ -224,7 +224,7 @@ TEST_F(convert_test, fromString_LongDouble_Success)
std::string source = "121.01";
long double destination = 0.0;
constexpr long double VERIFY = 121.01;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(true));
EXPECT_THAT(static_cast<double>(destination), DoubleEq(static_cast<double>(VERIFY)));
}

Expand All @@ -233,15 +233,15 @@ TEST_F(convert_test, fromString_LongDouble_Fail)
::testing::Test::RecordProperty("TEST_ID", "519f2ac5-8836-419e-8034-377230a88a09");
std::string source = "hasd";
double destination = 0.0;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(false));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(false));
}

TEST_F(convert_test, fromString_UNSIGNED_Int_Success)
{
::testing::Test::RecordProperty("TEST_ID", "1edb8d5f-c42d-4d02-bc31-477f48898bbb");
std::string source = "100";
unsigned int destination = 0.0;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(true));
EXPECT_THAT(destination, Eq(100U));
}

Expand All @@ -250,15 +250,15 @@ TEST_F(convert_test, fromString_UNSIGNED_Int_Fail)
::testing::Test::RecordProperty("TEST_ID", "6ce6de82-a6c0-4562-9c5c-663b93d768b3");
std::string source = "-331";
unsigned int destination = 0U;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(false));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(false));
}

TEST_F(convert_test, fromString_UNSIGNED_LongInt_Success)
{
::testing::Test::RecordProperty("TEST_ID", "054b08b2-54e1-4191-91b6-e6bec415612f");
std::string source = "999";
uint64_t destination = 0U;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(true));
EXPECT_THAT(destination, Eq(999LU));
}

Expand All @@ -267,15 +267,15 @@ TEST_F(convert_test, fromString_UNSIGNED_LongInt_Fail)
::testing::Test::RecordProperty("TEST_ID", "4b215747-90b2-4ca2-97ee-517c07597b1b");
std::string source = "-a123";
uint64_t destination = 0U;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(false));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(false));
}

TEST_F(convert_test, fromString_Int_Success)
{
::testing::Test::RecordProperty("TEST_ID", "9318ee60-f2e0-445a-b32d-c718cf918b18");
std::string source = "3331";
int destination = 0;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(true));
EXPECT_THAT(destination, Eq(3331));
}

Expand All @@ -284,15 +284,15 @@ TEST_F(convert_test, fromString_Int_Fail)
::testing::Test::RecordProperty("TEST_ID", "f8e698a9-054d-4441-b196-bcd58a72b1d9");
std::string source = "-+321";
int destination = 0;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(false));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(false));
}

TEST_F(convert_test, fromString_ShortInt_Success)
{
::testing::Test::RecordProperty("TEST_ID", "e804f821-157d-4c52-81a7-75fce5a43805");
std::string source = "12345";
short destination = 0;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(true));
EXPECT_THAT(destination, Eq(12345));
}

Expand All @@ -301,15 +301,15 @@ TEST_F(convert_test, fromString_ShortInt_Fail)
::testing::Test::RecordProperty("TEST_ID", "1150066b-cb42-4055-9927-2f20fb40bc87");
std::string source = "-+123321";
short destination = 0;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(false));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(false));
}

TEST_F(convert_test, fromString_Bool_Success)
{
::testing::Test::RecordProperty("TEST_ID", "893723fc-dfb8-46a4-b446-badaf8bad25a");
std::string source = "1";
bool destination = false;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(true));
EXPECT_THAT(destination, Eq(true));
}

Expand All @@ -318,15 +318,15 @@ TEST_F(convert_test, fromString_Bool_Fail)
::testing::Test::RecordProperty("TEST_ID", "1c937da6-29ea-49cf-a7d0-4c46f564c16e");
std::string source = "-+222";
bool destination = false;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(false));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(false));
}

TEST_F(convert_test, fromString_UShortInt_Success)
{
::testing::Test::RecordProperty("TEST_ID", "99d22d80-3860-47fa-9f98-f11ff9629815");
std::string source = "333";
unsigned short destination = 0U;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(true));
EXPECT_THAT(destination, Eq(333));
}

Expand All @@ -335,15 +335,15 @@ TEST_F(convert_test, fromString_UShortInt_Fail)
::testing::Test::RecordProperty("TEST_ID", "6ab6ded6-dff3-401a-8a7f-98326da7cca6");
std::string source = "-+111";
unsigned short destination = 0U;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(false));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(false));
}

TEST_F(convert_test, fromString_LongInt_Success)
{
::testing::Test::RecordProperty("TEST_ID", "37133256-ae79-45c7-8c86-56bd33fa7bd8");
std::string source = "-1123";
int64_t destination = 0;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(true));
EXPECT_THAT(destination, Eq(-1123L));
}

Expand All @@ -352,79 +352,79 @@ TEST_F(convert_test, fromString_LongInt_Fail)
::testing::Test::RecordProperty("TEST_ID", "0e368bf3-cb16-4829-a4cc-dc56e0bde958");
std::string source = "-a121";
int64_t destination = 0;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(false));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(false));
}

TEST_F(convert_test, fromString_MinMaxShort)
{
::testing::Test::RecordProperty("TEST_ID", "98e33efd-ba39-4b88-8307-358be30e4e73");
std::string source = "32767";
int16_t destination = 0;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(true));
source = "32768";
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(false));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(false));
source = "-32768";
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(true));
source = "-32769";
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(false));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(false));
}

TEST_F(convert_test, fromString_MinMaxUNSIGNED_Short)
{
::testing::Test::RecordProperty("TEST_ID", "f9196939-ae5d-4c27-85bf-b3b084343261");
std::string source = "65535";
uint16_t destination = 0U;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(true));
source = "65536";
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(false));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(false));
source = "0";
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(true));
source = "-1";
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(false));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(false));
}

TEST_F(convert_test, fromString_MinMaxInt)
{
::testing::Test::RecordProperty("TEST_ID", "abf0fda5-044e-4f1b-bb1e-31b701578a3d");
std::string source = "2147483647";
int32_t destination = 0;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(true));
source = "2147483648";
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(false));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(false));
source = "-2147483648";
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(true));
source = "-2147483649";
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(false));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(false));
}

TEST_F(convert_test, fromString_MinMaxUNSIGNED_Int)
{
::testing::Test::RecordProperty("TEST_ID", "c2a832ef-3e86-4303-a98c-63c7b11ea789");
std::string source = "4294967295";
uint32_t destination = 0U;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(true));
source = "4294967296";
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(false));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(false));
source = "0";
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(true));
source = "-1";
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(false));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(false));
}

TEST_F(convert_test, fromString_cxxString)
{
::testing::Test::RecordProperty("TEST_ID", "dbf015bb-5f51-47e1-9d0e-0525f65e7803");
std::string source = "hello";
iox::string<8> destination;
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(true));
source = "";
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(true));
source = "12345678";
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(true));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(true));
source = "123456789";
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(false));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(false));
source = "this_is_a_very_long_string";
EXPECT_THAT(iox::convert::fromString(source.c_str(), destination), Eq(false));
EXPECT_THAT(iox::convert::from_string(source.c_str(), destination), Eq(false));
}

} // namespace
8 changes: 4 additions & 4 deletions iceoryx_hoofs/utility/include/iox/detail/convert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ namespace iox
///
/// int i;
/// unsigned int a;
/// if ( iox::convert::fromString("123", i) ) {} // will succeed
/// if ( iox::convert::fromString("-123", a) ) {} // will fail since -123 is not unsigned
/// if ( iox::convert::from_string("123", i) ) {} // will succeed
/// if ( iox::convert::from_string("-123", a) ) {} // will fail since -123 is not unsigned
/// @endcode
/// @todo iox-#260 Refactor 'convert' so that one can use 'into' to directly to convert numbers to strings:
/// 'ClassExpectingAnIoxString(iox::into<iox::string<100>>(42)'
Expand Down Expand Up @@ -81,15 +81,15 @@ class convert
/// @param[in] dest destination to which the value should be written
/// @return false = if the conversion fails otherwise true
template <typename Destination>
static bool fromString(const char* v, Destination& dest) noexcept;
static bool from_string(const char* v, Destination& dest) noexcept;

/// @brief Sets dest from a given string. If the conversion fails false is
/// returned and the value of dest is undefined.
/// @param[in] v string which contains the value of dest
/// @param[in] dest destination to which the value should be written
/// @return false = if the conversion fails otherwise true
template <uint64_t Capacity>
static bool fromString(const char* v, string<Capacity>& dest) noexcept;
static bool from_string(const char* v, string<Capacity>& dest) noexcept;

/// @brief checks if a given string v is a number
/// @param[in] v string which contains the number
Expand Down
Loading

0 comments on commit 765cdec

Please sign in to comment.