-
-
Notifications
You must be signed in to change notification settings - Fork 125
Enable clojure.string-test.reverse
#882
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
27a28e6
Enable `clojure.string-test.reverse`
djblue cd041cf
Update reverse to use range based for loop
djblue 07c682f
Fix CI errors
djblue 5511d81
Fix CI errors
djblue 98ec15e
Merge remote-tracking branch 'upstream/main' into reverse
djblue f21aa03
Address PR feedback
djblue 0b832db
Make utf8 iterator bidirectional
djblue 3b6ed41
Fix CI
djblue 07bfa38
Cleanup
djblue 867a6ce
Add `utf8_range`
djblue 4038c59
Bump `clojure-test-suite`
djblue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| #include <jtl/immutable_string.hpp> | ||
|
|
||
| namespace jtl | ||
| { | ||
| constexpr bool | ||
| is_continuation_byte(immutable_string const &s, immutable_string::size_type const i) | ||
| { | ||
| if(i == immutable_string::npos) | ||
| { | ||
| throw std::runtime_error{ "Invalid unicode string." }; | ||
|
djblue marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| return (s[i] & 0xC0) == 0x80; | ||
| } | ||
|
|
||
| struct utf8_reverse_range | ||
| { | ||
| utf8_reverse_range(immutable_string const &s) | ||
| : data{ s } | ||
| { | ||
| } | ||
|
djblue marked this conversation as resolved.
Outdated
|
||
|
|
||
| struct iterator | ||
| { | ||
| using iterator_category = std::input_iterator_tag; | ||
| using difference_type = std::ptrdiff_t; | ||
| using value_type = immutable_string; | ||
| using reference = value_type const &; | ||
|
|
||
| iterator() | ||
| : data{} | ||
| , i{} | ||
| , n{} | ||
| { | ||
| } | ||
|
djblue marked this conversation as resolved.
Outdated
|
||
|
|
||
| iterator(immutable_string const &s) | ||
| : data{ s } | ||
| , i{ s.size() } | ||
| , n{ prev_char_size() } | ||
| { | ||
| } | ||
|
|
||
| constexpr value_type::size_type prev_char_size() const | ||
|
djblue marked this conversation as resolved.
Outdated
|
||
| { | ||
| if(!is_continuation_byte(data, i - 1)) | ||
| { | ||
| return 1; | ||
| } | ||
| else if(!is_continuation_byte(data, i - 2)) | ||
| { | ||
| return 2; | ||
| } | ||
| else if(!is_continuation_byte(data, i - 3)) | ||
| { | ||
| return 3; | ||
| } | ||
| else if(!is_continuation_byte(data, i - 4)) | ||
| { | ||
| return 4; | ||
| } | ||
| else | ||
| { | ||
| throw std::runtime_error{ "Invalid unicode string." }; | ||
| } | ||
| } | ||
|
|
||
| value_type operator*() const | ||
| { | ||
| return data.substr(i - n, n); | ||
| } | ||
|
|
||
| iterator &operator++() | ||
| { | ||
| i -= n; | ||
| if(i > n) | ||
| { | ||
| n = prev_char_size(); | ||
| } | ||
|
djblue marked this conversation as resolved.
Outdated
|
||
| return *this; | ||
| } | ||
|
|
||
| bool operator==(iterator const &it) const | ||
| { | ||
| return i == it.i; | ||
|
djblue marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| value_type data; | ||
| value_type::size_type i; | ||
| value_type::size_type n; | ||
|
djblue marked this conversation as resolved.
Outdated
|
||
| }; | ||
|
|
||
| iterator begin() const | ||
| { | ||
| if(data.empty()) | ||
| { | ||
| return {}; | ||
| } | ||
|
|
||
| return { data }; | ||
| } | ||
|
|
||
| iterator end() const | ||
| { | ||
| return {}; | ||
| } | ||
|
|
||
| immutable_string data; | ||
| }; | ||
| } | ||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.