aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/include/string_tools.h
diff options
context:
space:
mode:
authorLee Clagett <code@leeclagett.com>2017-02-27 13:33:16 -0500
committerLee Clagett <code@leeclagett.com>2017-04-11 16:35:00 -0400
commit4a8f96f95da51e6b570a00ddcfefe100844d8f8b (patch)
treeac8e18d7c08d336eac28481727f2accc00b1b544 /contrib/epee/include/string_tools.h
parentMerge pull request #1956 (diff)
downloadmonero-4a8f96f95da51e6b570a00ddcfefe100844d8f8b.tar.xz
Improvements for epee binary to hex functions:
- Performance improvements - Added `span` for zero-copy pointer+length arguments - Added `std::ostream` overload for direct writing to output buffers - Removal of unused `string_tools::buff_to_hex`
Diffstat (limited to '')
-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>