-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
proposal: path/filepath: add JoinList #25205
Comments
I swear this was discussed before. Did Rob think it was too trivial? Not at a desktop to search. |
Change https://golang.org/cl/110855 mentions this issue: |
@kardianos, ah, I had searched GitHub but nowhere else as I hadn't recalled this discussion before. But sure enough: https://codereview.appspot.com/7067049/ As @adg said there:
That's what happens to me. I always assume this exists until I find it's not there. And @davecheney in 2013: https://groups.google.com/d/msg/golang-nuts/PXCr10DsRb4/zchFpnB5gNwJ |
Nice find. |
Change https://golang.org/cl/110896 mentions this issue: |
CL 7067949 was making filepath.JoinList have special behavior around throwing away empty elements in lists, parsing and resplitting the entries. I suggested the 1-line implementation that CL 110896 has. Decisions about API that must be made:
I think these kinds of questions are why it hasn't been added. Any takers for attempting and explaining answers? |
I propose the following: func AppendList(list string, items ...string) (string, error) It may be used like:
On all platforms the list string would be treated mostly opaque, it would only be inspected to determine if a separator character must be appended on. The items will be quoted on windows if it contains a separator character. Empty strings in items would be ignored. On non-windows platforms, if an item string contained a list separator it will return an error. The two primary cases for this is to:
Unfortunately, this argument signature may be somewhat of a foot-gun (string, ...string), though it may be somewhat mitigated by using Append which behaves similarly to the builtin append function.
non-windows: filepath.AppendList("x:y", "z") returns "x:y:z"
filepath.AppendList(
filepath.AppendList(
non-windows: filepath.AppendList("", "x:y") returns error windows: filepath.AppendList("", "x;y") returns filepath.AppendList("", "x", "", "y") returns "x;y" or "x:y" |
+1 to @kardianos 's proposal, except for the following:
|
Shameless plug: in the meantime I recommend using gopkg.in/pathlist.v0 which I implemented with a similar API (except for no varargs support - yet - , and using a named type List to reduce the possibility of using a list as a filepath, or vice versa), based on the discussions in the above-mentioned go-nuts thread and my experience providing the correct filepath.SplitList implementation for Windows. |
This is getting very complicated. When do you need this functionality? Also note that on Unix there's no quoting, so either these functions have to return an error for the caller to check, or they have to accept only lists, never single elements. |
Given the lack of clear answers to the questions I posed earlier, closing this. Brad is fine with that. "Like many things I didn't know it was this complicated." |
We have
filepath.SplitList
but nofilepath.JoinList
.Proposal: add
filepath.JoinList
too.Current workaround is string concats with
filepath.ListSeparator
or usingstrings.Join
, which aren't terrible. I mostly missJoinList
out of lack of symmetry & consistency with other pairs of funcs. (We have strings.Join/strings.Split and filepath.Join/filepath.Split.)The text was updated successfully, but these errors were encountered: