|
Boost : |
From: Vladimir Prus (ghost_at_[hidden])
Date: 2002-09-18 03:07:18
Beman Dawes wrote:
> At 10:26 AM 9/17/2002, Volodya wrote:
>
> >This works nice here, but in a more complex example:
> >
> > path base("/home/ghost", system_specific);
> > path p("a/b/c/d", system_specific);
> >
> >How do I join base with p?
>
> I'm not sure what you mean by "join". If the result you want is
> "/home/ghost/a/b/c/d", then base<<p will do it. If you want
> "/home/a/b/c/d", then use base.branch()<<p.
>
> If the result you want is something else, let me know.
>
> Do I need to manually split p in components?
> >
> > path base("/home/ghost", system_specific);
> > path p("/a/b/c/d", system_specific);
> >
> >Here, even if I manage to split 'p' into components, what will they be?
> >I guess, "", "a", "b", "c", "d".
>
> You can use path::begin() and path::end() to get iterators for the
> sequence. Iteration would return std::strings "/", "a", "b", "c", "d".
>
> But that is only provided as a fall back to meet unusual needs. I don't
> think you should need to do that for join(). But you need to give me
> examples of what you expect the join() output to be. Is it just
> concatenation or does it drop, merge, or otherwise modify some elements?
Speaking terms of posix paths, I want
join("/home/ghost", "a/b") = "/home/ghost/a/b"
join("/home/ghost", "/a/b") = "/a/b"
Without this functionality, I see no way to handle both relative and
absolute paths in user input.
If I modify the program I recently posted to use 'system_specific' as it
should:
int main()
{
fs::path p1("/home/ghost", fs::system_specific),
p2("/a/b/c", fs::system_specific);
cout << (p1 << p2).file_path() << "\n";
}
It outputs "/home/ghost/a/b/c" --- the leading slash in p2 has no effect
on output.
- Volodya
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk