-
Notifications
You must be signed in to change notification settings - Fork 323
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
Text.take and Text.drop #3287
Text.take and Text.drop #3287
Conversation
distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text/Extensions.enso
Outdated
Show resolved
Hide resolved
340fc72
to
bd8e72a
Compare
Fix Range First n vaguely works
Some expansion to Text_Utils
Hiding the utility function inside
Starting on take function
Adding drop support
Some completed tests
Out of range tests Starting on accents
b7b844f
to
bc7ed35
Compare
Adjust index_of to use StringSearcher Fix for failing While
Still to fix not found scenarios in drop
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.
Looks good, but I would suggest a few minor changes.
distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text/Extensions.enso
Outdated
Show resolved
Hide resolved
distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text/Extensions.enso
Outdated
Show resolved
Hide resolved
distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text/Text_Sub_Range.enso
Show resolved
Hide resolved
distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text/Text_Sub_Range.enso
Outdated
Show resolved
Hide resolved
distribution/lib/Standard/Base/0.0.0-dev/src/Data/Text/Text_Sub_Range.enso
Outdated
Show resolved
Hide resolved
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.
Looks good now, although I'd consider also using the breakIterator.next count
trick for First
and Last
on to_char_range
.
first_count = text.length - count | ||
indices = find_sub_range_end text (index->_->_-> index+1 == first_count) | ||
if indices.first == -1 then (Range 0 indices.second) else | ||
(Range indices.second (Text_Utils.char_length text)) | ||
iterator = BreakIterator.getCharacterInstance | ||
iterator.setText text | ||
start_index = iterator.next first_count | ||
Range (if start_index == -1 then 0 else start_index) (Text_Utils.char_length text) |
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.
Here technically it may be faster to do:
iterator.last
start_index = iterator.next -count
iterator.last
is an O(1) operation so it will be faster than our .length
. But it's a minor detail.
Pull Request Description
Implementation of the Text take and drop APIs
Range.contains
functionText_Sub_Range
typeText_Utils.index_of
andText_Utils.last_index_of
based on ICU StringSearcherChecklist
Please include the following checklist in your PR:
./run dist
and./run watch
.