aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/include/string_tools.h
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2017-04-24 10:29:19 +0200
committerRiccardo Spagni <ric@spagni.net>2017-04-24 10:29:19 +0200
commita059e91d7fbdbf8745e48dd1c86e336483ff778c (patch)
tree27b42a557478acdee579b1f0ce649ca06218c1fc /contrib/epee/include/string_tools.h
parentMerge pull request #1956 (diff)
parentSimplified the implementation and features of span (diff)
downloadmonero-a059e91d7fbdbf8745e48dd1c86e336483ff778c.tar.xz
Merge pull request #1816
93e10f1c Simplified the implementation and features of span (Lee Clagett) 4a8f96f9 Improvements for epee binary to hex functions: (Lee Clagett)
Diffstat (limited to 'contrib/epee/include/string_tools.h')
-rw-r--r--contrib/epee/include/string_tools.h33
1 files changed, 5 insertions, 28 deletions
diff --git a/contrib/epee/include/string_tools.h b/contrib/epee/include/string_tools.h
index 530000028..67984b9e4 100644
--- a/contrib/epee/include/string_tools.h
+++ b/contrib/epee/include/string_tools.h
@@ -45,6 +45,8 @@
#include <boost/uuid/uuid_io.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
+#include "hex.h"
+#include "span.h"
#include "warnings.h"
@@ -114,33 +116,10 @@ namespace string_tools
return false;
}
}
- //----------------------------------------------------------------------------
- template<class CharT>
- std::basic_string<CharT> buff_to_hex(const std::basic_string<CharT>& s)
- {
- using namespace std;
- basic_stringstream<CharT> hexStream;
- hexStream << hex << noshowbase << setw(2);
-
- for(typename std::basic_string<CharT>::const_iterator it = s.begin(); it != s.end(); it++)
- {
- hexStream << "0x"<< static_cast<unsigned int>(static_cast<unsigned char>(*it)) << " ";
- }
- return hexStream.str();
- }
//----------------------------------------------------------------------------
- template<class CharT>
- std::basic_string<CharT> buff_to_hex_nodelimer(const std::basic_string<CharT>& s)
+ inline std::string buff_to_hex_nodelimer(const std::string& src)
{
- using namespace std;
- basic_stringstream<CharT> hexStream;
- hexStream << hex << noshowbase;
-
- for(typename std::basic_string<CharT>::const_iterator it = s.begin(); it != s.end(); it++)
- {
- hexStream << setw(2) << setfill('0') << static_cast<unsigned int>(static_cast<unsigned char>(*it));
- }
- return hexStream.str();
+ return to_hex::string(to_byte_span(to_span(src)));
}
//----------------------------------------------------------------------------
template<class CharT>
@@ -559,9 +538,7 @@ POP_WARNINGS
std::string pod_to_hex(const t_pod_type& s)
{
static_assert(std::is_pod<t_pod_type>::value, "expected pod type");
- std::string buff;
- buff.assign(reinterpret_cast<const char*>(&s), sizeof(s));
- return buff_to_hex_nodelimer(buff);
+ return to_hex::string(as_byte_span(s));
}
//----------------------------------------------------------------------------
template<class t_pod_type>