-
-
Notifications
You must be signed in to change notification settings - Fork 706
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
add std.uni.toCapitalized() #3167
Conversation
| // Accept range of dchar's | ||
| if (isInputRange!Range && | ||
| isSomeChar!(ElementEncodingType!Range) && | ||
| ElementEncodingType!Range.sizeof == dchar.sizeof) |
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.
this looks redundant. first you check if it is some char than you check if the size equals dchar. why not is(ElementEncodingType!Range == dchar)
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.
Done this way at Andrei's suggestion because it needs to allow enums whose base type is dchar, but not char or wchar which are implicitly convertible to dchar.
Note that the bulk of this code is copy/pasta from toCase.
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.
an string of enums?
if it copy/paste, shouldn't they be joined into a common base?
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 couldn't figure out a clean way to do it. If you can, a followon PR would be great.
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 will take a look, only currently I'm starting to work on an std.xml replacement and before that I want #2995 to get merged.
|
|
|
It won't work as an overload of capitalize(), because both accept strings. |
e8b2a2c to
93cced8
Compare
|
Fixed so it has 100% unittest coverage. |
|
We have |
| } | ||
|
|
||
| /// | ||
| @safe pure unittest |
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.
toCapitalize looks like it should also be @nogc if used with representation, byChar (or is it byCodeUnit? std.utf is a mess) or handle; the original capitalize can't be tested to be @nogc-ready because of its return value, but this algorithm definitely should be.
edit:
Not suggesting that the example test should be used to verify it, but it should be verified somewhere.
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.
the unit test allocates
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.
Yes, and we need to have one that doesn't.
|
Yeah, |
|
There is no consistency, and it's a little late to impute one. toCapitalize was named in the same spirit as its brethren toUpperCase and toLowerCase. |
Which were also names going against Phobos precedent. There is only a little consistency, but at least it is there - let's not create yet another naming convention just for the heck of it. |
|
Ah OK, |
|
I would have preferred |
|
toCapitalize doesn't make any sense. It's not proper English. You don't change a letter "to capitalize", you change it "to capital" or you "capitalize" it. |
|
toCapitalize is not a phrase and I think it needs to be changed before this gets pulled |
|
Bill wants to capitalize a sentence. |
|
Yeah "to" has many meanings which actually makes it a worse choice here - you want the preposition meaning transformation akin to "into", not the function word accompanying an infinitive. Good choices: toCapitals(), capitalizer(), toCapitalLetters() |
|
toUpperCase() - Bill wants to upper case a string. |
|
This also doesn't have a |
|
In |
I think you are wrong about the use of "to" here and in fact it's the first time I'm seeing this interpretation. It's: toUpperCase() - Convert this string to uppercase. |
|
Let's settle on |
93cced8 to
a6bce64
Compare
|
a6bce64 to
1b6b381
Compare
|
LGTM |
|
Auto-merge toggled on |
add std.uni.toCapitalized()
Replaces http://dlang.org/phobos-prerelease/std_string.html#.capitalize with a range version analogous to http://dlang.org/phobos-prerelease/std_uni.html#.toLowerCase