-
Notifications
You must be signed in to change notification settings - Fork 29
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
Remove dependency on solidity-stringutils
#91
base: main
Are you sure you want to change the base?
Changes from all commits
32c7c5c
8c13526
6dbf358
d2dbf48
d2c8419
6baa0e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
[submodule "lib/forge-std"] | ||
path = lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
[submodule "lib/solidity-stringutils"] | ||
path = lib/solidity-stringutils | ||
url = https://github.com/Arachnid/solidity-stringutils |
+6 −12 | .github/workflows/ci.yml | |
+3 −1 | .github/workflows/sync.yml | |
+193 −0 | CONTRIBUTING.md | |
+17 −1 | README.md | |
+3 −3 | foundry.toml | |
+1 −1 | package.json | |
+12 −1 | scripts/vm.py | |
+1 −1 | src/StdAssertions.sol | |
+22 −9 | src/StdChains.sol | |
+5 −5 | src/StdCheats.sol | |
+18 −3 | src/StdInvariant.sol | |
+104 −0 | src/StdJson.sol | |
+1 −1 | src/StdStorage.sol | |
+104 −0 | src/StdToml.sol | |
+1 −1 | src/StdUtils.sol | |
+4 −1 | src/Test.sol | |
+674 −67 | src/Vm.sol | |
+635 −608 | src/console.sol | |
+1 −1,555 | src/console2.sol | |
+2 −2 | src/interfaces/IERC4626.sol | |
+1 −5 | src/mocks/MockERC721.sol | |
+693 −4 | src/safeconsole.sol | |
+1 −1 | test/StdAssertions.t.sol | |
+30 −24 | test/StdChains.t.sol | |
+11 −11 | test/StdCheats.t.sol | |
+12 −12 | test/StdError.t.sol | |
+1 −1 | test/StdJson.t.sol | |
+4 −14 | test/StdMath.t.sol | |
+13 −5 | test/StdStorage.t.sol | |
+1 −1 | test/StdStyle.t.sol | |
+1 −1 | test/StdToml.t.sol | |
+12 −12 | test/StdUtils.t.sol | |
+9 −6 | test/Vm.t.sol |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import {Vm} from "forge-std/Vm.sol"; | ||
import {Utils} from "./Utils.sol"; | ||
|
||
/** | ||
* String finder functions using Forge's string cheatcodes. | ||
* For internal use only. | ||
*/ | ||
library StringFinder { | ||
/** | ||
* Returns whether the subject string contains the search string. | ||
*/ | ||
function contains(string memory subject, string memory search) internal returns (bool) { | ||
Vm vm = Vm(Utils.CHEATCODE_ADDRESS); | ||
return vm.contains(subject, search); | ||
} | ||
|
||
/** | ||
* Returns whether the subject string starts with the search string. | ||
*/ | ||
function startsWith(string memory subject, string memory search) internal pure returns (bool) { | ||
Vm vm = Vm(Utils.CHEATCODE_ADDRESS); | ||
uint256 index = vm.indexOf(subject, search); | ||
return index == 0; | ||
Comment on lines
+24
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could do without the Vm:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that it would be pure, without would allow all the previously view function to remain view There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't use |
||
} | ||
|
||
/** | ||
* Returns whether the subject string ends with the search string. | ||
*/ | ||
function endsWith(string memory subject, string memory search) internal pure returns (bool) { | ||
Vm vm = Vm(Utils.CHEATCODE_ADDRESS); | ||
string[] memory tokens = vm.split(subject, search); | ||
return tokens.length > 1 && bytes(tokens[tokens.length - 1]).length == 0; | ||
} | ||
|
||
/** | ||
* Returns the number of non-overlapping occurrences of the search string in the subject string. | ||
*/ | ||
function count(string memory subject, string memory search) internal pure returns (uint256) { | ||
Vm vm = Vm(Utils.CHEATCODE_ADDRESS); | ||
string[] memory tokens = vm.split(subject, search); | ||
return tokens.length - 1; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thing that can be defined only once as a library constant:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work on some older versions of Solidity 0.8.x which should be supported for previous versions of OpenZeppelin Contracts.