[Yul] Format string literals back to quoted string literals

This commit is contained in:
Leonardo Alt
2019-11-26 15:28:39 +01:00
committed by chriseth
parent 200a92b40e
commit ce83bfb088
16 changed files with 842 additions and 4 deletions
+13
View File
@@ -23,6 +23,7 @@
#include <libdevcore/Exceptions.h>
#include <libdevcore/Assertions.h>
#include <libdevcore/Keccak256.h>
#include <libdevcore/FixedHash.h>
#include <boost/algorithm/string.hpp>
@@ -181,3 +182,15 @@ bool dev::isValidDecimal(string const& _string)
return false;
return true;
}
// Returns a quoted string if all characters are printable ASCII chars,
// or its hex representation otherwise.
std::string dev::formatAsStringOrNumber(std::string const& _value)
{
if (_value.length() <= 32)
for (auto const& c: _value)
if (c <= 0x1f || c >= 0x7f || c == '"')
return "0x" + h256(_value, h256::AlignLeft).hex();
return "\"" + _value + "\"";
}
+4 -1
View File
@@ -290,7 +290,6 @@ void iterateReplacing(std::vector<T>& _vector, F const& _f)
_vector = std::move(modifiedVector);
}
namespace detail
{
template <typename T, typename F, std::size_t... I>
@@ -355,6 +354,10 @@ std::string getChecksummedAddress(std::string const& _addr);
bool isValidHex(std::string const& _string);
bool isValidDecimal(std::string const& _string);
/// @returns a quoted string if all characters are printable ASCII chars,
/// or its hex representation otherwise.
std::string formatAsStringOrNumber(std::string const& _value);
template<typename Container, typename Compare>
bool containerEqual(Container const& _lhs, Container const& _rhs, Compare&& _compare)
{