Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preserve cursor #21

Merged
merged 2 commits into from
Nov 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/lib/parse/LibParseDecimalFloat.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ library LibParseDecimalFloat {
uint256 intStart = cursor;
cursor = LibParseChar.skipMask(cursor, end, CMASK_NUMERIC_0_9);
if (cursor == intStart) {
return (ParseEmptyDecimalString.selector, 0, 0, 0);
return (ParseEmptyDecimalString.selector, cursor, 0, 0);
}
}
{
(bytes4 signedCoefficientErrorSelector, int256 signedCoefficientTmp) =
LibParseDecimal.unsafeDecimalStringToSignedInt(start, cursor);
if (signedCoefficientErrorSelector != 0) {
return (signedCoefficientErrorSelector, 0, 0, 0);
return (signedCoefficientErrorSelector, cursor, 0, 0);
}
signedCoefficient = signedCoefficientTmp;
}
Expand All @@ -73,7 +73,7 @@ library LibParseDecimalFloat {
uint256 fracStart = cursor;
cursor = LibParseChar.skipMask(cursor, end, CMASK_NUMERIC_0_9);
if (cursor == fracStart) {
return (MalformedDecimalPoint.selector, 0, 0, 0);
return (MalformedDecimalPoint.selector, cursor, 0, 0);
}
// Trailing zeros are allowed in fractional literals but should
// not be counted in the precision.
Expand All @@ -86,13 +86,13 @@ library LibParseDecimalFloat {
(bytes4 fracErrorSelector, int256 fracValueTmp) =
LibParseDecimal.unsafeDecimalStringToSignedInt(fracStart, nonZeroCursor);
if (fracErrorSelector != 0) {
return (fracErrorSelector, 0, 0, 0);
return (fracErrorSelector, cursor, 0, 0);
}
fracValue = fracValueTmp;
}
// Frac value inherits its sign from the coefficient.
if (fracValue < 0) {
return (MalformedDecimalPoint.selector, 0, 0, 0);
return (MalformedDecimalPoint.selector, cursor, 0, 0);
}
if (signedCoefficient < 0) {
fracValue = -fracValue;
Expand All @@ -103,12 +103,12 @@ library LibParseDecimalFloat {
exponent = int256(fracStart) - int256(nonZeroCursor);
uint256 scale = uint256(-exponent);
if (scale >= 77 && signedCoefficient != 0) {
return (ParseDecimalPrecisionLoss.selector, 0, 0, 0);
return (ParseDecimalPrecisionLoss.selector, cursor, 0, 0);
}
scale = 10 ** scale;
int256 rescaledIntValue = signedCoefficient * int256(scale);
if (rescaledIntValue / int256(scale) != signedCoefficient) {
return (ParseDecimalPrecisionLoss.selector, 0, 0, 0);
return (ParseDecimalPrecisionLoss.selector, cursor, 0, 0);
}
signedCoefficient = rescaledIntValue + fracValue;
}
Expand All @@ -122,15 +122,15 @@ library LibParseDecimalFloat {
uint256 digitsStart = cursor;
cursor = LibParseChar.skipMask(cursor, end, CMASK_NUMERIC_0_9);
if (cursor == digitsStart) {
return (MalformedExponentDigits.selector, 0, 0, 0);
return (MalformedExponentDigits.selector, cursor, 0, 0);
}
}

{
(bytes4 eErrorSelector, int256 eValueTmp) =
LibParseDecimal.unsafeDecimalStringToSignedInt(eStart, cursor);
if (eErrorSelector != 0) {
return (eErrorSelector, 0, 0, 0);
return (eErrorSelector, cursor, 0, 0);
}
eValue = eValueTmp;
}
Expand Down