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

Make RA behave as expected for multiple, size-changing replacements #12

Open
dloscutoff opened this issue May 18, 2021 · 0 comments
Open
Labels
minor-bug Not ideal behavior, but doesn't break anything.

Comments

@dloscutoff
Copy link
Owner

When RA is given a List of indices as its second argument, it performs a replacement at each index. However, this can be problematic if a replacement is a different length from what it replaces.

Example: First, consider z RA [3 7] '_. This replaces the characters at indices 3 and 7 in the lowercase alphabet (d and h) with underscores. The result is abc_efg_ijklmnopqrstuvwxyz. But now, consider z RA [3 7] "___". This should replace the same two characters (d and h) with three underscores each; however, the replacement of d changes the length of the string, and now index 7 is no longer h but f: abc___e___ghijklmnopqrstuvwxyz. Similarly, z RA [3 7] "" should delete d and h but instead deletes i: abcefghjklmnopqrstuvwxyz.

The best solution is to sort the list of indices in descending order. By doing the rightmost replacements first, we can preserve the correct indices for characters to the left until we are ready to perform those replacements. Caveat: we'll need to handle indices that are Ranges, too, and I think it will be impossible to handle these perfectly because of the possibility of overlapping indices. TBD exactly how to sort when Ranges are involved.

@dloscutoff dloscutoff added the bug label May 18, 2021
@dloscutoff dloscutoff added enhancement and removed bug labels Jul 3, 2021
@dloscutoff dloscutoff added minor-bug Not ideal behavior, but doesn't break anything. and removed enhancement labels Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor-bug Not ideal behavior, but doesn't break anything.
Projects
None yet
Development

No branches or pull requests

1 participant