Skip to content

Commit

Permalink
chore: refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
tringuyenskymavis committed Aug 27, 2024
1 parent d613a81 commit e7d15f0
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions script/libraries/LibInitializeGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -334,20 +334,12 @@ library LibInitializeGuard {
}

function _getContractNameFromAbsolutePath(string memory path) internal pure returns (string memory contractName) {
bytes memory pathBytes = bytes(path);
uint256 length = pathBytes.length;
bytes memory contractNameBytes = new bytes(length - 4);

if (
length > 4 && pathBytes[length - 4] == "." && pathBytes[length - 3] == "s" && pathBytes[length - 2] == "o"
&& pathBytes[length - 1] == "l"
) {
// Create a new bytes array without the ".sol" extension
for (uint256 i = 0; i < length - 4; i++) {
contractNameBytes[i] = pathBytes[i];
}
uint256 length = bytes(path).length;
// Remove ".sol"
if (path.endsWith(".sol")) {
contractName = path.slice(0, length - 4);
}
return string(contractNameBytes);
return string(contractName);
}

/**
Expand Down

0 comments on commit e7d15f0

Please sign in to comment.