diff --git a/libdevcore/CommonJS.cpp b/libdevcore/CommonJS.cpp index f173e779e..262944b65 100644 --- a/libdevcore/CommonJS.cpp +++ b/libdevcore/CommonJS.cpp @@ -23,15 +23,17 @@ #include "CommonJS.h" +using namespace std; + namespace dev { -bytes jsToBytes(std::string const& _s) +bytes jsToBytes(string const& _s) { if (_s.substr(0, 2) == "0x") // Hex return fromHex(_s.substr(2)); - else if (_s.find_first_not_of("0123456789") == std::string::npos) + else if (_s.find_first_not_of("0123456789") == string::npos) // Decimal return toCompactBigEndian(bigint(_s)); else @@ -42,7 +44,7 @@ bytes padded(bytes _b, unsigned _l) { while (_b.size() < _l) _b.insert(_b.begin(), 0); - return asBytes(asString(_b).substr(_b.size() - std::max(_l, _l))); + return asBytes(asString(_b).substr(_b.size() - max(_l, _l))); } bytes paddedRight(bytes _b, unsigned _l) @@ -54,7 +56,7 @@ bytes paddedRight(bytes _b, unsigned _l) bytes unpadded(bytes _b) { auto p = asString(_b).find_last_not_of((char)0); - _b.resize(p == std::string::npos ? 0 : (p + 1)); + _b.resize(p == string::npos ? 0 : (p + 1)); return _b; } @@ -72,18 +74,18 @@ bytes unpadLeft(bytes _b) return _b; } -std::string fromRaw(h256 _n, unsigned* _inc) +string fromRaw(h256 _n, unsigned* _inc) { if (_n) { - std::string s((char const*)_n.data(), 32); + string s((char const*)_n.data(), 32); auto l = s.find_first_of('\0'); if (!l) return ""; - if (l != std::string::npos) + if (l != string::npos) { auto p = s.find_first_not_of('\0', l); - if (!(p == std::string::npos || (_inc && p == 31))) + if (!(p == string::npos || (_inc && p == 31))) return ""; if (_inc) *_inc = (byte)s[31]; diff --git a/libdevcore/CommonJS.h b/libdevcore/CommonJS.h index 38159da25..567572afd 100644 --- a/libdevcore/CommonJS.h +++ b/libdevcore/CommonJS.h @@ -38,12 +38,12 @@ template std::string toJS(FixedHash const& _h) template std::string toJS(boost::multiprecision::number> const& _n) { - return "0x" + toHex(toCompactBigEndian(_n)); + return "0x" + toHex(toCompactBigEndian(_n, 1)); } -inline std::string toJS(dev::bytes const& _n) +inline std::string toJS(bytes const& _n) { - return "0x" + dev::toHex(_n); + return "0x" + toHex(_n); } template< typename T >std::string toJS( T const& i ) @@ -81,7 +81,7 @@ template FixedHash jsToFixed(std::string const& _s) inline std::string jsToFixed(double _s) { - return toJS(dev::u256(_s * (double)(dev::u256(1) << 128))); + return toJS(u256(_s * (double)(u256(1) << 128))); } template boost::multiprecision::number> jsToInt(std::string const& _s) @@ -106,13 +106,13 @@ inline int jsToInt(std::string const& _s) inline std::string jsToDecimal(std::string const& _s) { - return dev::toString(jsToU256(_s)); + return toString(jsToU256(_s)); } -inline std::string jsFromBinary(dev::bytes _s, unsigned _padding = 32) +inline std::string jsFromBinary(bytes _s, unsigned _padding = 32) { _s.resize(std::max(_s.size(), _padding)); - return "0x" + dev::toHex(_s); + return "0x" + toHex(_s); } inline std::string jsFromBinary(std::string const& _s, unsigned _padding = 32) @@ -122,7 +122,7 @@ inline std::string jsFromBinary(std::string const& _s, unsigned _padding = 32) inline double jsFromFixed(std::string const& _s) { - return (double)jsToU256(_s) / (double)(dev::u256(1) << 128); + return (double)jsToU256(_s) / (double)(u256(1) << 128); } }