-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[std] Better ASCII methods + minor cleanup in std #17380
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
3 Ignored Deployments
|
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.
Lgtm will be quite useful
assert!(b"AHELLOZ".to_ascii_string().is_alphanumeric(), 3); | ||
assert!(b"0123".to_ascii_string().is_alphanumeric(), 4); | ||
assert!(!b"!".to_ascii_string().is_alphanumeric(), 2); | ||
assert!(!b" ".to_ascii_string().is_alphanumeric(), 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.
is b""
alphanumeric?
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.
Should be (vacuously) true.
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.
Do we provide an into_bytes(string: String): vector<u8>
to string
as the ascii
?
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.
We do not, we only have std::string::bytes(string: &String): &vector<u8>
, seems reasonable to have an into_bytes
as well though!
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.
There is an into_bytes
method in std::ascii
already.
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.
Oh, my bad. You mean the std::string
module. I'll add as a part of this PR!
fa645d2
to
c638357
Compare
|
||
/// Copy the slice of the `string` from `i` to `j` into a new `String`. | ||
public fun sub_string(string: &String, mut i: u64, j: u64): String { | ||
assert!(i <= j && j <= string.length(), EInvalidIndex); |
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.
maybe split over multiple asserts for better line numbers with #[error]
in the future
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 will do once we get to better error handling. I'd like to change the codes as well, so it's better done in a separate PR.
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.
Thanks for the quick turnaround!
This reverts commit ab2bc7c.
…17613) This reverts commit ab2bc7c. ## Description Describe the changes or additions included in this PR. ## Test plan How did you test the new or updated feature? --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK:
## Description This PR rolls #17380 (successfully merged once) yet again. ## Test plan Features tests. ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [x] Protocol: This change updates the [ascii module](https://docs.sui.io/references/framework/move-stdlib/ascii) in the following ways: Adds new methods to `std::ascii`: - `ascii::append(&mut String, String)` - `ascii::is_empty(): bool` - `ascii::substring(&String, i, j): String` - `ascii::index_of(&String, &String): u64` - `ascii::to_uppercase(&String): String` - `ascii::to_lowercase(&String): String` These additions make the ASCII interface more similar to the UTF8 one. Renames: - `string::bytes() to string::as_bytes()` - `string::sub_string() to string::substring()` Deprecates: - `string::sub_string` in favour of `string::substring` - `string::bytes` in favour of `string::as_bytes` Additional changes: - updates `std::type_name` to use `std::substring` - removes use statements for implicit imports - renames constants from `E_INDEX` to conventional `EIndexOutOfBounds`
…s#18462) ## Description This PR rolls MystenLabs#17380 (successfully merged once) yet again. ## Test plan Features tests. ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [x] Protocol: This change updates the [ascii module](https://docs.sui.io/references/framework/move-stdlib/ascii) in the following ways: Adds new methods to `std::ascii`: - `ascii::append(&mut String, String)` - `ascii::is_empty(): bool` - `ascii::substring(&String, i, j): String` - `ascii::index_of(&String, &String): u64` - `ascii::to_uppercase(&String): String` - `ascii::to_lowercase(&String): String` These additions make the ASCII interface more similar to the UTF8 one. Renames: - `string::bytes() to string::as_bytes()` - `string::sub_string() to string::substring()` Deprecates: - `string::sub_string` in favour of `string::substring` - `string::bytes` in favour of `string::as_bytes` Additional changes: - updates `std::type_name` to use `std::substring` - removes use statements for implicit imports - renames constants from `E_INDEX` to conventional `EIndexOutOfBounds`
Description
Adds new methods to
std::ascii
:ascii::append(&mut String, String)
ascii::is_empty(): bool
ascii::substring(&String, i, j): String
ascii::index_of(&String, &String): u64
ascii::to_uppercase(&String): String
ascii::to_lowercase(&String): String
So ASCII interface is similar to the one in UTF8
Renames:
string::bytes() -> string::as_bytes()
string::sub_string() -> string::substring()
Additionally:
std::type_name
to usestd::substring
E_INDEX
to conventionalEIndexOutOfBounds
Test plan
Features tests
Release notes
Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.
For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.
Adds new methods to
std::ascii
:ascii::append(&mut String, String)
ascii::is_empty(): bool
ascii::substring(&String, i, j): String
ascii::index_of(&String, &String): u64
ascii::to_uppercase(&String): String
ascii::to_lowercase(&String): String
These additions make the ASCII interface more similar to the UTF8 one.
Renames:
string::bytes() to string::as_bytes()
string::sub_string() to string::substring()
Additional changes:
std::type_name
to usestd::substring
E_INDEX
to conventionalEIndexOutOfBounds