-
Notifications
You must be signed in to change notification settings - Fork 93
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
add StringView
#1436
add StringView
#1436
Conversation
Here are three potential issues or observations from the provided
These issues should be reviewed and addressed to improve code clarity, performance, and maintainability. |
Pull Request Test Coverage Report for Build 4682Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try to move StringIndex/StringView into string package
9dc7f2a
to
01b0efd
Compare
Basic usage:
To create a
CharsView
from aString
, we need to use theCharOffset
as indices.CharOffset
is an opaque type that represents a position in the utf-16 String. It can be constructed viaCharOffset::offset_by(str: String, offset: int)
where the offset is the number of characters skipped between the start of the string and the returning position. It can also be constructed viaCharOffset::unsafe_from_int(index: Int)
.This is to avoid confusion with indexing
String
using indices, i.e. indices indicate utf-16 code unit offset when accessingString
whereas when viewingString
the indices represents offsets of characters.Once we hold a
CharsView
, we can use integers directly to access chars or create subviews, and here the index always represents the codepoint offset.Update:
renamed the types and methods:
CharsView
->StringView
CharOffset
->StringIndex
offset_by
->index_at