-
-
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 all 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
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,37 @@ | ||
| #include <jtl/immutable_string.hpp> | ||
|
|
||
| namespace jtl | ||
| { | ||
| struct utf8_iterator | ||
| { | ||
| using iterator_category = std::bidirectional_iterator_tag; | ||
| using difference_type = std::ptrdiff_t; | ||
| using value_type = immutable_string; | ||
| using reference = value_type const &; | ||
|
|
||
| utf8_iterator() = default; | ||
| utf8_iterator(immutable_string const &s); | ||
| utf8_iterator(immutable_string const &s, value_type::size_type const position); | ||
|
|
||
| value_type operator*() const; | ||
| utf8_iterator &operator++(); | ||
| utf8_iterator operator++(int); | ||
| utf8_iterator &operator--(); | ||
| utf8_iterator operator--(int); | ||
| bool operator==(utf8_iterator const &it) const; | ||
|
|
||
| value_type data; | ||
| value_type::size_type i{}; | ||
| value_type::size_type n{}; | ||
| }; | ||
|
|
||
| struct utf8_range | ||
| { | ||
| utf8_range(immutable_string const &s); | ||
|
|
||
| utf8_iterator begin() const; | ||
| utf8_iterator end() const; | ||
|
|
||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| #include <jtl/utf8.hpp> | ||
|
|
||
| namespace jtl | ||
| { | ||
| using value_type = utf8_iterator::value_type; | ||
| using size_type = value_type::size_type; | ||
|
|
||
| static size_type next_char_size(immutable_string const &s, size_type const i) | ||
| { | ||
| auto const c(s[i]); | ||
| if(c <= 0x7f) | ||
| { | ||
| return 1; | ||
| } | ||
| else if((c & 0xE0) == 0xC0) | ||
| { | ||
| return 2; | ||
| } | ||
| else if((c & 0xF0) == 0xE0) | ||
| { | ||
| return 3; | ||
| } | ||
| else if((c & 0xF8) == 0xF0) | ||
| { | ||
| return 4; | ||
| } | ||
| else | ||
| { | ||
| throw std::runtime_error{ "Invalid UTF-8 string." }; | ||
| } | ||
| } | ||
|
|
||
| static bool is_continuation_byte(immutable_string const &s, size_type const i) | ||
| { | ||
| if(i == immutable_string::npos) | ||
| { | ||
| throw std::runtime_error{ "Invalid UTF-8 string." }; | ||
| } | ||
|
|
||
| return (s[i] & 0xC0) == 0x80; | ||
| } | ||
|
|
||
| static size_type prev_char_size(immutable_string const &data, size_type const i) | ||
| { | ||
| 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 UTF-8 string." }; | ||
| } | ||
| } | ||
|
|
||
| utf8_iterator::utf8_iterator(immutable_string const &s) | ||
| : data{ s } | ||
| , i{ s.empty() ? value_type::npos : 0 } | ||
| , n{ i == value_type::npos ? 0 : next_char_size(s, i) } | ||
| { | ||
| } | ||
|
|
||
| utf8_iterator::utf8_iterator(immutable_string const &s, value_type::size_type const position) | ||
| : data{ s } | ||
| , i{ s.empty() ? value_type::npos : position } | ||
| , n{ i == value_type::npos ? 0 : next_char_size(s, i) } | ||
| { | ||
| } | ||
|
|
||
| value_type utf8_iterator::operator*() const | ||
| { | ||
| return data.substr(i, n); | ||
| } | ||
|
|
||
| utf8_iterator &utf8_iterator::operator++() | ||
| { | ||
| if(i == value_type::npos) | ||
| { | ||
| i = 0; | ||
| n = next_char_size(data, i); | ||
| } | ||
| else | ||
| { | ||
| i += n; | ||
| if(i >= data.size()) | ||
| { | ||
| i = value_type::npos; | ||
| n = 0; | ||
| } | ||
| else | ||
| { | ||
| n = next_char_size(data, i); | ||
| } | ||
| } | ||
|
|
||
| return *this; | ||
| } | ||
|
|
||
| utf8_iterator utf8_iterator::operator++(int) | ||
| { | ||
| auto tmp{ *this }; | ||
| ++*this; | ||
| return tmp; | ||
| } | ||
|
|
||
| utf8_iterator &utf8_iterator::operator--() | ||
| { | ||
| if(i == 0) | ||
| { | ||
| i = value_type::npos; | ||
| n = 0; | ||
| } | ||
| else if(i == value_type::npos) | ||
| { | ||
| auto const size(data.size()); | ||
| n = prev_char_size(data, size); | ||
| i = size - n; | ||
| } | ||
| else | ||
| { | ||
| n = prev_char_size(data, i); | ||
| i -= n; | ||
| } | ||
| return *this; | ||
| } | ||
|
|
||
| utf8_iterator utf8_iterator::operator--(int) | ||
| { | ||
| auto tmp{ *this }; | ||
| --*this; | ||
| return tmp; | ||
| } | ||
|
|
||
| bool utf8_iterator::operator==(utf8_iterator const &it) const | ||
| { | ||
| return i == it.i && (data.data() == it.data.data() || data == it.data); | ||
| } | ||
|
|
||
| utf8_range::utf8_range(immutable_string const &s) | ||
| : data{ s } | ||
| { | ||
| } | ||
|
|
||
| utf8_iterator utf8_range::begin() const | ||
| { | ||
| return { data, 0 }; | ||
| } | ||
|
|
||
| utf8_iterator utf8_range::end() const | ||
| { | ||
| return { data, value_type::npos }; | ||
| } | ||
| } |
2 changes: 1 addition & 1 deletion
2
compiler+runtime/test/bash/clojure-test-suite/clojure-test-suite
Submodule clojure-test-suite
updated
8 files
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.