Fix string offset parameters to use character positions instead of byte offsets#31
Draft
Fix string offset parameters to use character positions instead of byte offsets#31
Conversation
- Modified Find(string, int) to convert character offset to byte offset using Encoding.UTF8.GetByteCount - Modified Captures(string, int) to convert character offset to byte offset - Updated XML documentation to clarify that string methods use character offsets, while byte methods use byte offsets - Added comprehensive tests for multi-byte UTF-8 characters (emojis and Asian characters) - All 71 tests passing (6 new tests added) Agent-Logs-Url: https://github.com/crispthinking/IronRe2/sessions/2d26941d-972d-4c97-a3ec-ad34e99c1ff3 Co-authored-by: corpo-iwillspeak <265613520+corpo-iwillspeak@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
Find(string, int)andCaptures(string, int)methods were treating the offset parameter as a byte position in the UTF-8 encoded string, causing incorrect behavior with multi-byte characters (emojis, CJK characters, etc.).Changes
Find(string haystack, int offset)andCaptures(string haystack, int offset): Convert character offset to byte offset usingEncoding.UTF8.GetByteCount(haystack.AsSpan(0, offset))before passing to the underlying byte-based methodsExample