Skip to content
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

Merged
merged 18 commits into from
May 9, 2024
Merged

Conversation

damirka
Copy link
Contributor

@damirka damirka commented Apr 27, 2024

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:

  • updates std::type_name to use std::substring
  • removes use statements for implicit imports
  • renames constants from E_INDEX to conventional EIndexOutOfBounds

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.

  • Protocol: This change updates the ascii module 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()

Additional changes:

  • updates std::type_name to use std::substring
  • removes use statements for implicit imports
  • renames constants from E_INDEX to conventional EIndexOutOfBounds

Copy link

vercel bot commented Apr 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 9, 2024 1:00pm
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview May 9, 2024 1:00pm
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview May 9, 2024 1:00pm
sui-typescript-docs ⬜️ Ignored (Inspect) Visit Preview May 9, 2024 1:00pm

@damirka damirka changed the title [std] Better ASCII methods [std] Better ASCII methods + minor cleanup in std Apr 27, 2024
Copy link
Contributor

@leecchh leecchh left a 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is b"" alphanumeric?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be (vacuously) true.

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?

Copy link
Contributor

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!

Copy link
Contributor Author

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.

Copy link
Contributor Author

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!


/// 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);
Copy link
Contributor

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

Copy link
Contributor Author

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.

@damirka damirka requested a review from tnowacki May 7, 2024 18:23
@damirka
Copy link
Contributor Author

damirka commented May 7, 2024

@tnowacki @amnn I have updated the PR to add aliases + new functions without getting into Char territory.

Copy link
Contributor

@amnn amnn left a 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!

@damirka damirka merged commit ab2bc7c into main May 9, 2024
47 checks passed
@damirka damirka deleted the ds/better-ascii-methods branch May 9, 2024 13:24
patrickkuo added a commit that referenced this pull request May 9, 2024
patrickkuo added a commit that referenced this pull request May 9, 2024
…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:
@damirka damirka restored the ds/better-ascii-methods branch May 9, 2024 22:46
dariorussi added a commit that referenced this pull request May 10, 2024
dariorussi added a commit that referenced this pull request May 10, 2024
dariorussi added a commit that referenced this pull request May 14, 2024
dariorussi added a commit that referenced this pull request May 14, 2024
dariorussi added a commit that referenced this pull request May 15, 2024
dariorussi added a commit that referenced this pull request May 15, 2024
damirka added a commit that referenced this pull request Jun 29, 2024
## 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`
tx-tomcat pushed a commit to tx-tomcat/sui-network that referenced this pull request Jul 29, 2024
…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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants