From fa0cb6597279d122c0db727ef9d1680ba3862970 Mon Sep 17 00:00:00 2001 From: Artsem Zhuk Date: Tue, 16 Apr 2019 15:48:13 +0300 Subject: [PATCH] Upgraded solidity version, changes signature of one function because of that. --- lib/Addresses.sol | 4 ++-- lib/Integers.sol | 14 +++++++------- lib/Strings.sol | 41 +++++++++++++++++++++++------------------ 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/lib/Addresses.sol b/lib/Addresses.sol index fbd8c42..6c21ed1 100644 --- a/lib/Addresses.sol +++ b/lib/Addresses.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.0; +pragma solidity >=0.4.25 <0.6.0; /** * Addresses Library @@ -17,7 +17,7 @@ library Addresses { * @param _base The address on the network to check if it is a contract * @return bool Returns true if it is a valid contract */ - function isContract(address _base) returns (bool _r) { + function isContract(address _base) public returns (bool _r) { assembly { _r := gt(extcodesize(_base), 0) } diff --git a/lib/Integers.sol b/lib/Integers.sol index 692311f..b34a3e3 100644 --- a/lib/Integers.sol +++ b/lib/Integers.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.0; +pragma solidity >=0.4.25 <0.6.0; /** * Integers Library @@ -18,14 +18,14 @@ library Integers { * @param _value The ASCII string to be converted to an unsigned integer * @return uint The unsigned value of the ASCII string */ - function parseInt(string _value) + function parseInt(string memory _value) public returns (uint _ret) { bytes memory _bytesValue = bytes(_value); uint j = 1; for(uint i = _bytesValue.length-1; i >= 0 && i < _bytesValue.length; i--) { - assert(_bytesValue[i] >= 48 && _bytesValue[i] <= 57); - _ret += (uint(_bytesValue[i]) - 48)*j; + assert(uint8(_bytesValue[i]) >= 48 && uint8(_bytesValue[i]) <= 57); + _ret += (uint(uint8(_bytesValue[i])) - 48)*j; j*=10; } } @@ -40,11 +40,11 @@ library Integers { */ function toString(uint _base) internal - returns (string) { + returns (string memory) { bytes memory _tmp = new bytes(32); uint i; for(i = 0;_base > 0;i++) { - _tmp[i] = byte((_base % 10) + 48); + _tmp[i] = byte(uint8((_base % 10) + 48)); _base /= 10; } bytes memory _real = new bytes(i--); @@ -82,7 +82,7 @@ library Integers { */ function toBytes(uint _base) internal - returns (bytes _ret) { + returns (bytes memory _ret) { assembly { let m_alloc := add(msize(),0x1) _ret := mload(m_alloc) diff --git a/lib/Strings.sol b/lib/Strings.sol index ecff76a..2103e1d 100644 --- a/lib/Strings.sol +++ b/lib/Strings.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.0; +pragma solidity >=0.4.25 <0.6.0; /** * Strings Library @@ -24,10 +24,10 @@ library Strings { * @param _value The value to be the concatenated suffix * @return string The resulting string from combinging the base and value */ - function concat(string _base, string _value) + function concat(string memory _base, string memory _value) internal pure - returns (string) { + returns (string memory) { bytes memory _baseBytes = bytes(_base); bytes memory _valueBytes = bytes(_value); @@ -64,7 +64,7 @@ library Strings { * @return int The position of the needle starting from 0 and returning -1 * in the case of no matches found */ - function indexOf(string _base, string _value) + function indexOf(string memory _base, string memory _value) internal pure returns (int) { @@ -87,7 +87,7 @@ library Strings { * @return int The position of the needle starting from 0 and returning -1 * in the case of no matches found */ - function _indexOf(string _base, string _value, uint _offset) + function _indexOf(string memory _base, string memory _value, uint _offset) internal pure returns (int) { @@ -114,7 +114,7 @@ library Strings { * otherwise this is the string to be measured * @return uint The length of the passed string */ - function length(string _base) + function length(string memory _base) internal pure returns (uint) { @@ -133,10 +133,10 @@ library Strings { * @param _length The length of the sub string to be extracted from the base * @return string The extracted sub string */ - function substring(string _base, int _length) + function substring(string memory _base, int _length) internal pure - returns (string) { + returns (string memory) { return _substring(_base, _length, 0); } @@ -153,10 +153,10 @@ library Strings { * @param _offset The starting point to extract the sub string from * @return string The extracted sub string */ - function _substring(string _base, int _length, int _offset) + function _substring(string memory _base, int _length, int _offset) internal pure - returns (string) { + returns (string memory) { bytes memory _baseBytes = bytes(_base); assert(uint(_offset+_length) <= _baseBytes.length); @@ -186,9 +186,14 @@ library Strings { * @return string[] An array of values split based off the delimiter, but * do not container the delimiter. */ - function split(string _base, string _value) + function split(string memory _base, string memory _value, string[] storage splitArr) internal - returns (string[] storage splitArr) { + returns (string[] storage) { + + while (splitArr.length > 0) { + splitArr.pop(); + } + bytes memory _baseBytes = bytes(_base); uint _offset = 0; @@ -223,7 +228,7 @@ library Strings { * @param _value The string the base is being compared to * @return bool Simply notates if the two string have an equivalent */ - function compareTo(string _base, string _value) + function compareTo(string memory _base, string memory _value) internal pure returns (bool) { @@ -256,7 +261,7 @@ library Strings { * @return bool Simply notates if the two string have an equivalent value * discarding case */ - function compareToIgnoreCase(string _base, string _value) + function compareToIgnoreCase(string memory _base, string memory _value) internal pure returns (bool) { @@ -287,10 +292,10 @@ library Strings { * otherwise this is the string base to convert to upper case * @return string */ - function upper(string _base) + function upper(string memory _base) internal pure - returns (string) { + returns (string memory) { bytes memory _baseBytes = bytes(_base); for (uint i = 0; i < _baseBytes.length; i++) { _baseBytes[i] = _upper(_baseBytes[i]); @@ -308,10 +313,10 @@ library Strings { * otherwise this is the string base to convert to lower case * @return string */ - function lower(string _base) + function lower(string memory _base) internal pure - returns (string) { + returns (string memory) { bytes memory _baseBytes = bytes(_base); for (uint i = 0; i < _baseBytes.length; i++) { _baseBytes[i] = _lower(_baseBytes[i]);