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

Text.take and Text.drop #3287

Merged
merged 32 commits into from
Feb 22, 2022
Merged

Text.take and Text.drop #3287

merged 32 commits into from
Feb 22, 2022

Conversation

jdunkerley
Copy link
Member

@jdunkerley jdunkerley commented Feb 18, 2022

Pull Request Description

Implementation of the Text take and drop APIs

  • Added Range.contains function
  • Added Text_Sub_Range type
  • Added Text_Utils.index_of and Text_Utils.last_index_of based on ICU StringSearcher

Checklist

Please include the following checklist in your PR:

  • The documentation has been updated if necessary.
  • All code conforms to the Scala, Java, and Rust style guides.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed: Enso GUI was tested when built using BOTH ./run dist and ./run watch.

@jdunkerley jdunkerley force-pushed the wip/jd/text-take-drop-181265131 branch from 340fc72 to bd8e72a Compare February 21, 2022 10:51
Fix Range
First n vaguely works
Some expansion to Text_Utils
Hiding the utility function inside
Starting on take function
Some completed tests
Out of range tests
Starting on accents
@jdunkerley jdunkerley force-pushed the wip/jd/text-take-drop-181265131 branch from b7b844f to bc7ed35 Compare February 21, 2022 16:44
jdunkerley and others added 5 commits February 21, 2022 17:38
Adjust index_of to use StringSearcher
Fix for failing While
Still to fix not found scenarios in drop
@jdunkerley jdunkerley marked this pull request as ready for review February 21, 2022 19:21
@jdunkerley jdunkerley requested a review from 4e6 as a code owner February 21, 2022 19:21
Copy link
Member

@radeusgd radeusgd left a 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.

Copy link
Member

@radeusgd radeusgd left a 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.

@jdunkerley jdunkerley added the CI: Ready to merge This PR is eligible for automatic merge label Feb 22, 2022
Comment on lines 75 to 79
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)
Copy link
Member

@radeusgd radeusgd Feb 22, 2022

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.

@mergify mergify bot merged commit 2e2c556 into develop Feb 22, 2022
@mergify mergify bot deleted the wip/jd/text-take-drop-181265131 branch February 22, 2022 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants