Skip to content
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

WIP: add Path string type #1548

Closed
wants to merge 2 commits into from
Closed

WIP: add Path string type #1548

wants to merge 2 commits into from

Conversation

nolta
Copy link
Member

@nolta nolta commented Nov 14, 2012

This might be a little too cute, but i've been playing around w/ adding a Path string type:

julia> p = path("a", "b")
"a/b"

julia> typeof(p)
Path

julia> isa(p, String)
true

julia> q = p / "c"
"a/b/c"

julia> split(q)
3-element String Array:
 "a"
 "b"
 "c"

Inspired by https://github.com/jaraco/path.py

@StefanKarpinski
Copy link
Member

That is cute. I'll have to play with it once I'm back from Puerto Rico on Sunday. Let's see where it goes and how it feels. Might be rather nice for writing portable code more easily.

@staticfloat
Copy link
Member

Glad to see this is being made! Back in #1396 I suggested using abs_path in the String constructor of a class like this. In this case, it would be put in base/file.jl:42, such that if you were to do something like:

p = Path("/tmp/adir/") / ".." / "bdir/"

p would end up with /tmp/bdir/, not /tmp/adir//../bdir/. The nice thing about the way you've put this all together, is that any way a user combines String and Path objects will need to pass through that method, so the data inside the Path object can be "trusted" in a sense, that we know it has already been passed through abs_path and therefore is safe to pass to naive methods that don't want to worry about things like // and /../.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants