Skip to content

Commit

Permalink
replace JsmnSolLib.sol with compatible version
Browse files Browse the repository at this point in the history
  • Loading branch information
ltfschoen committed Oct 16, 2024
1 parent d9f772d commit 512906d
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/hardhat/contracts/JsmnSolLib.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Reference: https://github.com/chrisdotn/jsmnSol/issues/18

// SPDX-License-Identifier: MIT
/*
Copyright (c) 2017 Christoph Niemann
Permission is hereby granted, free of charge, to any person obtaining a copy of
Expand Down Expand Up @@ -112,8 +115,8 @@ library JsmnSolLib {
function parsePrimitive(Parser memory parser, Token[] memory tokens, bytes memory s) internal pure returns (uint) {
bool found = false;
uint start = parser.pos;
bool success;
bytes1 c;
bool success;
Token memory token;
for (; parser.pos < s.length; parser.pos++) {
c = s[parser.pos];
Expand Down Expand Up @@ -207,7 +210,7 @@ library JsmnSolLib {
if (i==0) {
token = tokens[i];
if (token.startSet && !token.endSet) {
parser.toksuper = int256(i);
parser.toksuper = int128(uint128(i));
}
}
continue;
Expand Down Expand Up @@ -301,7 +304,7 @@ library JsmnSolLib {
// parseInt(parseFloat*10^_b)
function parseInt(string memory _a, uint _b) internal pure returns (int) {
bytes memory bresult = bytes(_a);
int8 mint = 0;
int mint = 0;
bool decimals = false;
bool negative = false;
for (uint i=0; i<bresult.length; i++){
Expand All @@ -313,16 +316,12 @@ library JsmnSolLib {
if (_b == 0) break;
else _b--;
}
// max value of 10
mint *= 10;
// max value 57-48 = 9, min value 48 - 48 = 0
mint += int8(uint8(bresult[i]) - 48);
mint += int256(uint256(uint8(bresult[i]) - 48));
} else if (uint8(bresult[i]) == 46) decimals = true;
}
// FIXME: if _b is very large then it may need to be int256 not int8
if (_b > 0) mint *= int8(uint8(10)**uint8(_b));
if (_b > 0) mint *= int(10**_b);
if (negative) mint *= -1;

return mint;
}

Expand Down

0 comments on commit 512906d

Please sign in to comment.