mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[Yul] Format string literals back to quoted string literals
This commit is contained in:
@@ -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 + "\"";
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user