-
Notifications
You must be signed in to change notification settings - Fork 47
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 extension and stripExtension functions #246
Conversation
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 seems a bit odd to have this as a standalone function. This module seems to offer a few standalone functions that returns Path
, and the rest of the functionalities are wrapped in Path
. This one stands out as acting on a range of chars.
Edit: I missed the PR message. Still having them needing a file name is an odd requirement that might trip people up. And the interface of this module also becomes a bit more complicated.
source/vibe/core/path.d
Outdated
|
||
Note that `filename` must be a pure file name and not a full path. | ||
*/ | ||
auto extension(R)(R filename) |
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.
Use R
instead of auto
return type for better documentation
source/vibe/core/path.d
Outdated
@@ -189,6 +190,129 @@ string toNativeString(P)(P path) | |||
} | |||
|
|||
|
|||
/** Returns the file extension of a file, including the dot. | |||
|
|||
Note that `filename` must be a pure file name and not a full path. |
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 don't understand why this function is not just part of Path
?
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.
Because that would also mean in Segment2
and possibly Segment
, including duplicate documentation, and skipping the range based overload (which ideally should be adjusted in Phobos, but anyway).
There is also |
But they both return a
Yeah... The duplication here is really getting in the way. Is there any plan to unify those ? |
Missed this point. I agree that this inconsistency with Anyway, let's say that this possible pitfall (could at least be mitigated using an assertion that catches misuse), as well as the fact that this introduces an overload resolution conflict with Just to clarify where I stand w.r.t. the general issue of member functions - I agree with you that semantically member functions are usually preferable for anything that seems like it is a property or a direct action on an object. The fragmented API resulting from the UFCS approach makes it harder to follow the documentation and to get a grasp on the API as a whole. On the other hand (ignoring D's choice of Using only public APIs, these two functions fall into the latter category, but the fact that they look like properties (and are syntactically supposed to be used like such) puts them somewhere in-between. |
With this converted to methods, I'm really unhappy with the name |
fea837a
to
36e73dc
Compare
|
I was actually seriously reconsidering |
85dc133
to
4a42911
Compare
Also adds GenericPath.fileExtension as a shortcut for `path.head2.extension`.
4a42911
to
762abab
Compare
In contrast to
std.path
, these work with pure forward ranges and directly acceptGenericPath
andGenericPath.Segment(2)
.