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

feat: range indexing on strings #845

Merged
merged 2 commits into from
Mar 19, 2024

Conversation

zitsen
Copy link
Contributor

@zitsen zitsen commented Mar 18, 2024

Now we support range indexing on strings, including ref/mut impls.

For example, you can use range indexing intead of sub_of_string() method like bellow:

let s1 = "abcde";
let s2 = s1[1..4]; // "bcd"
s1[1..4] = "f"; // s1: "afe", s2: "bcd"

Close #841

Now we support range indexing on strings, including ref/mut impls.

For example, you can use range indexing intead of sub_of_string() method
like bellow:

```rust
let s1 = "abcde";
let s2 = s1[1..4]; // "bcd"
s1[1..4] = "f"; // s1: "afe", s2: "bcd"
```

Close rhaiscript#841
@schungx
Copy link
Collaborator

schungx commented Mar 18, 2024

Wow, I'll look through that.

Probably needs some more tests just to make sure it doesn't muck up indexing a single character ...

Thanks!

@zitsen
Copy link
Contributor Author

zitsen commented Mar 18, 2024

I've test it with cargo test to confirm it wouldn't break anything. For char indexing, I've add a more complex test case to test both char-index and range-index on the same string.

@schungx
Copy link
Collaborator

schungx commented Mar 19, 2024

Anyway let's merge this and see how it goes.

@schungx schungx merged commit 6dc86bb into rhaiscript:main Mar 19, 2024
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.

Feature: syntax str[range] support like rust string indexing by range
2 participants