-
Notifications
You must be signed in to change notification settings - Fork 342
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
✨ Add is7BitASCII(s, allowed)
to LibString
#963
Conversation
isAlphanumeric
and isAlphanumericChar()
in LibString.sol
isAlphanumeric
and isAlphanumericChar
in LibString
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.
very nice, thank you
src/utils/LibString.sol
Outdated
@@ -406,6 +406,36 @@ library LibString { | |||
} | |||
} | |||
|
|||
/// @dev Returns if this string is a alphanumeric character including space. |
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.
For clarity, I would rewrite the NatSpec to:
/// @dev Returns true if the string contains only alphanumeric characters and spaces.
src/utils/LibString.sol
Outdated
} | ||
} | ||
|
||
/// @dev Returns if this character is a alphanumeric including space. |
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.
For clarity, I would rewrite the NatSpec to:
/// @dev Returns true if the character is an alphanumeric character or a space.
Left a more detailed comment on the issue: #962 (comment), but I think it would be surprising for spaces to be considered "alphanumeric". |
isAlphanumeric
and isAlphanumericChar
in LibStringis7BitASCII(s, allowed)
to LibString
Refactored to make it more general. Will merge in 24 hours if no hard objections. For compile time evalaution: function is7BitASCIIAlphaNumericWithSpace(string memory s) internal pure returns (bool result) {
return LibString.is7BitASCII(
s,
LibString.ALPHANUMERIC_7_BIT_ASCII | uint128(1 << uint256(uint8(bytes1(" "))))
);
} Btw, we have a |
@Vectorized In the current implementation of the For instance: Python isalnum In these implementations, the function typically returns false for an empty string. To align with these standards and ensure consistent behavior, I propose the following adjustments:
Everyone is open to give your valuable suggestions. |
Let's deviate away from the popular languages. For this example, it is logically closer to: Pythonall(c in "0123456789" for c in "") # True Rustfn is_alphanumeric(s: &str) -> bool {
s.chars().all(|c| c.is_alphanumeric())
} Note that Rust's Rust's philosophy is to provide the most fundamental building blocks which can be composed together via terse syntax. Due to limited space in Solady, it would be better to lean towards Rust's philosophy. Also, to keep consistency with Python's
|
Description
closing #962
Checklist
Ensure you completed all of the steps below before submitting your pull request:
forge fmt
?forge snapshot
?forge test
?Pull requests with an incomplete checklist will be thrown out.