Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrush committed Aug 29, 2023
1 parent fb3531c commit 05f1f82
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
21 changes: 6 additions & 15 deletions src/libs/conduit/conduit_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,18 +522,8 @@ namespace utils
template< typename T >
std::string to_hex_string(T value)
{
// Note:
// std::stringstream w/ std::hex seems to not prepend 0x on windows,
// but does on linux and macOS, so we have custom logic for windows.
//
// I also tried to use fmt with "#x", but this caused a compile
// disaster for windows CI cases
std::stringstream oss;
#if defined(CONDUIT_PLATFORM_WINDOWS)
oss << "0x" << std::hex << value;
#else
oss << "0x" << std::hex << value;
#endif
oss << std::hex << value;
return oss.str();
}

Expand Down Expand Up @@ -576,7 +566,7 @@ namespace utils
T res;
std::istringstream iss(s);
iss >> res;
return res;
return res;
}

// declare then define to avoid icc warnings
Expand All @@ -586,9 +576,10 @@ namespace utils
template< typename T >
T hex_string_to_value(const std::string &s)
{
char *str_end = nullptr;
unsigned long long ull_value = strtoull(s.c_str(),&str_end,0);
return (T)(ull_value);
T res;
std::istringstream iss(s);
iss >> std::hex >> res;
return res;
}


Expand Down
1 change: 0 additions & 1 deletion src/tests/conduit/t_conduit_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,6 @@ TEST(conduit_utils, to_and_from_hex_string)
int64 val = 1024;
std::string hstring = utils::to_hex_string(val);
std::cout << hstring << std::endl;
EXPECT_EQ(hstring,"0x400");
int64 val_check = conduit::utils::hex_string_to_value<int64>(hstring);
EXPECT_EQ(val,val_check);
}
Expand Down

0 comments on commit 05f1f82

Please sign in to comment.