fix: ensure safe text slicing boundaries with multi-byte characters
This commit resolves a panic that occurs when the text_info function attempts to slice a string containing non-ASCII characters.
The fix addresses the issue reported in the Deno repository: https://github.com/denoland/deno/issues/23875
Use Case: The bug arises because the range_text method tries to slice a string using byte indices (start and end) that may not align with UTF-8 character boundaries. In Rust, attempting to slice a string at invalid UTF-8 boundaries results in a panic.
Solution: The solution involves modifying the range_text method to correctly handle non-ASCII characters. The method now uses char_indices() to collect character boundaries and maps the start and end byte indices to these boundaries. The resulting string slice is based on valid UTF-8 character boundaries, ensuring the operation is safe and the encoding remains intact.
@dsherret Could you please review this PR?
I think it would be really great if we could have a unit test for this :)