-
-
Notifications
You must be signed in to change notification settings - Fork 705
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
fix issue 23361 - std.uni.normalize made pure #8763
Conversation
|
Thanks for your pull request and interest in making D better, @dukc! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + phobos#8763" |
| // check example | ||
|
|
||
| // any encoding works | ||
| wstring greet = "Hello world"; | ||
| // test with dstring | ||
| dstring greet = "Hello world"; | ||
| assert(normalize(greet) is greet); // the same exact slice | ||
|
|
||
| // An example of a character with all 4 forms being different: | ||
| // Greek upsilon with acute and hook symbol (code point 0x03D3) | ||
| assert(normalize!NFC("ϓ") == "\u03D3"); | ||
| assert(normalize!NFD("ϓ") == "\u03D2\u0301"); | ||
| assert(normalize!NFKC("ϓ") == "\u038E"); | ||
| assert(normalize!NFKD("ϓ") == "\u03A5\u0301"); |
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.
I removed these while here because they are duplicating the documentation unittest for no reason.
| // cast. It isn't pure in the sense that the elements after | ||
| // the array in question are affected, but we don't use those | ||
| // making the call pure for our purposes. | ||
| (cast(void delegate() pure nothrow) {decomposed.assumeSafeAppend();})(); |
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.
assumeSafeAppend is already nothrow so there's no need to also cast it to it.
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.
It is, but a cast needs to designate the new type as whole, including those attributes the original lambda had.
I could avoid this by using std.traits.SetFunctionAttributes instead but using it would be uglier IMO, besides being a needless dependency.
EDIT: I could also just leave the function throwing, since I didn't actually make normalize nothrow... but at least it's one step less for someone else.
| // cast. It isn't pure in the sense that the elements after | ||
| // the array in question are affected, but we don't use those | ||
| // making the call pure for our purposes. | ||
| (cast(void delegate() pure nothrow) {decomposed.assumeSafeAppend();})(); |
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.
| (cast(void delegate() pure nothrow) {decomposed.assumeSafeAppend();})(); | |
| (cast(void delegate() pure) { decomposed.assumeSafeAppend(); })(); |
| ccc.length = 0; | ||
| ccc.assumeSafeAppend(); | ||
| (cast(void delegate() pure nothrow) {ccc.assumeSafeAppend();})(); |
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.
ditto.
No description provided.