-
-
Notifications
You must be signed in to change notification settings - Fork 447
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
Algorithm to reverse a string should account for extended grapheme clusters #299
Comments
Try something like this:
|
@gardhr Thanks for the suggestion! Feel free to submit a PR along with tests. :) Not sure how well your proposal accounts for all graphemes, as it has been a while since I last looked into it. |
Sorry, I just don't have the time at the moment. It has worked well for me over the years, I would be rather surprised if it choked on anything at all. If it does however, just give me a set of failing samples and I'll be glad to fix it. Wish I could do more to help. Maybe once I get passed some of this backlog? var print = console.log;
var text =
"外国語の学習と教授Language Learning and TeachingИзучение и обучение иностранных языков語文教學・语文教学Enseñanza y estudio de idiomasИзучаване и Преподаване на Чужди Езициქართული ენის შესწავლა და სწავლება'læŋɡwidʒ 'lɘr:niŋ ænd 'ti:tʃiŋLus kawm thaib qhiaNgôn Ngữ, Sự học,말배우기와 가르치기Nauka języków obcychΓλωσσική Εκμὰθηση και Διδασκαλίαเรียนและสอนภาษา語文教學 😃, ქართული 😭, Εκμὰθηση 😈 иностранных𠀋𠀾𠁎𠁨☃★♲\u{2F804}";
var reversed = reverse(text);
print(text);
print();
print(reversed);
print();
print("Test:", reverse(reversed) == text ? "Pass" : "FAIL!"); Output:
|
@gardhr Thanks for the demo! |
Yep, you're welcome. |
This was resolved in #1082. |
Checklist
Description
Encountered an error when attempting to use
@stdlib/string/reverse
to reverse a string which includes extended grapheme clusters. While the implementation does account for Unicode surrogate pairs and combining marks, extended grapheme clusters do not appear supported.Addressing this issue may require using a Unicode segmentation algorithm, as discussed in the Unicode standard. One can find reference implementations in Rust and elsewhere.
Related Issues
Related issues #295.
Questions
No.
Other
N/A
Demo
N/A
Reproduction
In order to reproduce this bug, do the following:
Expected Results
The reversed string to account for extended grapheme clusters.
Actual Results
N/A
Environments
The following environments are affected:
The text was updated successfully, but these errors were encountered: