Created
March 29, 2024 06:53
-
-
Save estein9825/95687a5cb6b75d7aaebe8719e550395f to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.20+commit.a1b79de6.js&optimize=false&runs=200&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.20; | |
// Courtesy of https://gist.github.com/ottodevs/c43d0a8b4b891ac2da675f825b1d1dbf?permalink_comment_id=4976821#gistcomment-4976821 | |
library StringToLower { | |
function copyBytes(bytes memory _bytes) private pure returns (bytes memory) { | |
bytes memory copy = new bytes(_bytes.length); | |
uint256 max = _bytes.length + 31; | |
for (uint256 i=32; i<=max; i+=32) | |
{ | |
assembly { mstore(add(copy, i), mload(add(_bytes, i))) } | |
} | |
return copy; | |
} | |
function _toLowercase(string memory inputNonModifiable) public pure returns (string memory) { | |
bytes memory bytesInput = copyBytes(bytes(inputNonModifiable)); | |
for (uint i = 0; i < bytesInput.length; i++) { | |
// checks for valid ascii characters // will allow unicode after building a string library | |
require (uint8(bytesInput[i]) > 31 && uint8(bytesInput[i]) < 127, "Only ASCII characters"); | |
// Uppercase character... | |
if (uint8(bytesInput[i]) > 64 && uint8(bytesInput[i]) < 91) { | |
// add 32 to make it lowercase | |
bytesInput[i] = bytes1(uint8(bytesInput[i]) + 32); | |
} | |
} | |
return string(bytesInput); | |
} | |
} | |
library CustomErrorChecks { | |
function assembly_notZero(address toCheck) | |
internal | |
pure | |
returns (bool success) | |
{ | |
assembly { | |
if iszero(toCheck) { | |
let ptr := mload(0x40) | |
mstore( | |
ptr, | |
0xd92e233d00000000000000000000000000000000000000000000000000000000 | |
) // selector for `ZeroAddress()` | |
revert(ptr, 0x4) | |
} | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment