|
|
|
Created:
16 years ago by bsiegert Modified:
15 years, 12 months ago Reviewers:
CC:
r, rsc, peterGo, r2, brainman, golang-dev Visibility:
Public. |
Descriptionpath: Windows support for Split
Make Split work on backslashes as well as on slashes under Windows
and support the "C:filename" special case. Also add corresponding
tests.
Patch Set 1 #Patch Set 2 : code review 3008041: path: Windows support for Split #
Total comments: 2
Patch Set 3 : code review 3008041: path: Windows support for Split #
Total comments: 2
Patch Set 4 : code review 3008041: path: Windows support for Split #
Total comments: 10
Patch Set 5 : code review 3008041: path: Windows support for Split #
Total comments: 10
Patch Set 6 : code review 3008041: path: Windows support for Split #
Total comments: 1
MessagesTotal messages: 29
Hello r, rsc (cc: golang-dev@googlegroups.com), I'd like you to review this change.
Sign in to reply to this message.
http://codereview.appspot.com/3008041/diff/2001/src/pkg/path/path.go File src/pkg/path/path.go (right): http://codereview.appspot.com/3008041/diff/2001/src/pkg/path/path.go#newcode112 src/pkg/path/path.go:112: if path[i] == '/' || (runtime.GOOS == "windows" && path[i] == '\\') { these windows tests should be done once, in init(), and used to prepare simpler tests for these properties ideally the init and runtime tests wouldn't even be compiled unless the OS was windows. that's easy to do through the makefile and build system. it would be wrong to sprinkle if(windows) through the code.
Sign in to reply to this message.
Windows specific code can easily become a ball-and-chain for Go. This is a patch
for the OS portable implementation of path.Split that I use for Linux and
Windows.
diff --git a/src/pkg/os/Makefile b/src/pkg/os/Makefile
--- a/src/pkg/os/Makefile
+++ b/src/pkg/os/Makefile
@@ -21,26 +21,31 @@
GOFILES_freebsd=\
env_unix.go\
file_unix.go\
+ path_unix.go\
sys_bsd.go\
GOFILES_darwin=\
env_unix.go\
file_unix.go\
+ path_unix.go\
sys_bsd.go\
GOFILES_linux=\
env_unix.go\
file_unix.go\
+ path_unix.go\
sys_linux.go\
GOFILES_nacl=\
env_unix.go\
file_unix.go\
+ path_unix.go\
sys_nacl.go\
GOFILES_windows=\
env_windows.go\
file_windows.go\
+ path_windows.go\
sys_windows.go\
GOFILES+=$(GOFILES_$(GOOS))
diff --git a/src/pkg/os/path_unix.go b/src/pkg/os/path_unix.go
new file mode 100644
--- /dev/null
+++ b/src/pkg/os/path_unix.go
@@ -0,0 +1,14 @@
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Unix-like operating systems
+
+package os
+
+const (
+ DirSep = `/`
+ DirSeps = DirSep
+ VolSep = ``
+ PathSeps = VolSep + DirSeps
+)
diff --git a/src/pkg/os/path_windows.go b/src/pkg/os/path_windows.go
new file mode 100644
--- /dev/null
+++ b/src/pkg/os/path_windows.go
@@ -0,0 +1,14 @@
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Windows operating system
+
+package os
+
+const (
+ DirSep = `\`
+ DirSeps = DirSep + `/`
+ VolSep = `:`
+ PathSeps = VolSep + DirSeps
+)
diff --git a/src/pkg/path/path.go b/src/pkg/path/path.go
--- a/src/pkg/path/path.go
+++ b/src/pkg/path/path.go
@@ -108,8 +108,10 @@
// file set to path.
func Split(path string) (dir, file string) {
for i := len(path) - 1; i >= 0; i-- {
- if path[i] == '/' {
- return path[0 : i+1], path[i+1:]
+ for j := 0; j < len(os.PathSeps); j++ {
+ if path[i] == os.PathSeps[j] {
+ return path[0 : i+1], path[i+1:]
+ }
}
}
return "", path
Sign in to reply to this message.
On Wed, Nov 10, 2010 at 04:25, <go.peter.90@gmail.com> wrote: > Windows specific code can easily become a ball-and-chain for Go. This is > a patch for the OS portable implementation of path.Split that I use for > Linux and Windows. > +const ( > + DirSep = `\` > + DirSeps = DirSep + `/` > + VolSep = `:` > + PathSeps = VolSep + DirSeps > +) I would prefer for these constants to reside in package path, as they concern paths. What do you think? --Benny.
Sign in to reply to this message.
On Nov 10, 2010, at 1:40 AM, Benny Siegert wrote: > On Wed, Nov 10, 2010 at 04:25, <go.peter.90@gmail.com> wrote: >> Windows specific code can easily become a ball-and-chain for Go. This is >> a patch for the OS portable implementation of path.Split that I use for >> Linux and Windows. > >> +const ( >> + DirSep = `\` >> + DirSeps = DirSep + `/` >> + VolSep = `:` >> + PathSeps = VolSep + DirSeps >> +) > > I would prefer for these constants to reside in package path, as they > concern paths. What do you think? Of course. What makes you think otherwise? > --Benny.
Sign in to reply to this message.
On 2010/11/10 09:40:48, bsiegert wrote: > I would prefer for these constants to reside in package path, as they > concern paths. What do you think? Go was designed to be portable across operating/file systems (OS). The Go syscall package contains the raw calls to the OS kernel and API. To preserve OS portablity, Go programs should make calls to the Go os package, which provides OS independent functions via the syscall package; Go programs which call the syscall package directly are OS dependent. The Go program target OS is specified at compile time; OS dependencies should be resolved at compile time, not run time. The Go path package functions, methods and constants are dependent on the operating/file system (OS). It simplifies the OS portability layer to separate the file system path functions and methods from the os package and put them in the path package. Naturally, the os package imports the syscall package and the path package imports the os package (and also might import the syscall package). Circular import dependencies are not allowed. For the os package to reference any of the path related constants without circular dependencies, the path constants should be in the os package. Then, for example, we can change the os.TempDir function for Windows pathSep constant to to DirSep. Peter
Sign in to reply to this message.
On 2010/11/10 17:40:51, r2 wrote: > On Nov 10, 2010, at 1:40 AM, Benny Siegert wrote: > > >> +const ( > >> + DirSep = `\` > >> + DirSeps = DirSep + `/` > >> + VolSep = `:` > >> + PathSeps = VolSep + DirSeps > >> +) > > > > I would prefer for these constants to reside in package path, as they > > concern paths. What do you think? > > Of course. What makes you think otherwise? Since the constants are used in the path and os packages, that would change the constant declarations to: diff --git a/src/pkg/os/Makefile b/src/pkg/os/Makefile --- a/src/pkg/os/Makefile +++ b/src/pkg/os/Makefile @@ -21,26 +21,31 @@ GOFILES_freebsd=\ env_unix.go\ file_unix.go\ + path_unix.go\ sys_bsd.go\ GOFILES_darwin=\ env_unix.go\ file_unix.go\ + path_unix.go\ sys_bsd.go\ GOFILES_linux=\ env_unix.go\ file_unix.go\ + path_unix.go\ sys_linux.go\ GOFILES_nacl=\ env_unix.go\ file_unix.go\ + path_unix.go\ sys_nacl.go\ GOFILES_windows=\ env_windows.go\ file_windows.go\ + path_windows.go\ sys_windows.go\ GOFILES+=$(GOFILES_$(GOOS)) diff --git a/src/pkg/os/path_unix.go b/src/pkg/os/path_unix.go new file mode 100644 --- /dev/null +++ b/src/pkg/os/path_unix.go @@ -0,0 +1,14 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Unix-like operating systems + +package os + +const ( + DirSep = `/` + DirSeps = DirSep + VolSep = `` + PathSeps = VolSep + DirSeps +) diff --git a/src/pkg/os/path_windows.go b/src/pkg/os/path_windows.go new file mode 100644 --- /dev/null +++ b/src/pkg/os/path_windows.go @@ -0,0 +1,14 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Windows operating system + +package os + +const ( + DirSep = `\` + DirSeps = DirSep + `/` + VolSep = `:` + PathSeps = VolSep + DirSeps +) diff --git a/src/pkg/path/path.go b/src/pkg/path/path.go --- a/src/pkg/path/path.go +++ b/src/pkg/path/path.go @@ -102,6 +102,13 @@ return string(buf[0:w]) } +const ( + DirSep = os.DirSep + DirSeps = os.DirSeps + VolSep = os.VolSep + PathSeps = os.PathSeps +) + // Split splits path immediately following the final slash, // separating it into a directory and file name component. // If there is no slash in path, Split returns an empty dir and
Sign in to reply to this message.
On 2010/11/10 03:25:57, PeterGo wrote:
> Windows specific code can easily become a ball-and-chain for Go. This is a
patch
> ...
> --- a/src/pkg/path/path.go
> +++ b/src/pkg/path/path.go
> @@ -108,8 +108,10 @@
> // file set to path.
> func Split(path string) (dir, file string) {
> for i := len(path) - 1; i >= 0; i-- {
> - if path[i] == '/' {
> - return path[0 : i+1], path[i+1:]
> + for j := 0; j < len(os.PathSeps); j++ {
> + if path[i] == os.PathSeps[j] {
> + return path[0 : i+1], path[i+1:]
> + }
> }
> }
> return "", path
Good suggestion. But couldn't we just create an os.IsPathSeparator(ch int) or
something with similar name. I don't like to see that extra loop here. Also, I'm
not sure if anyone really interested to see these consts (DirSep, DirSeps,
VolSep, PathSeps) - they are windows specific, and until we need them, I'd
rather not see them.
Alex
PS: Why windows paths have to be so complicated <g>.
Sign in to reply to this message.
On 2010/11/11 02:01:25, brainman wrote:
> couldn't we just create an os.IsPathSeparator(ch int) or something with
similar name. I don't like to see that extra loop here.
As Wirth pointed out, programming is often a process of stepwise refinement
(Wirth, Program Development by Stepwise Refinement).
The nested loop was provided to illustrate a simple mechanism for a plausible
solution. After refinement, it's likely to be replaced by the missing
strings.LastIndexAny() function. Then, the new path.Split() function simplifies
to:
i := strings.LastIndexAny(path, os.PathSeps)
return path[0 : i+1], path[i+1:]
Nested loops are a natural and familiar idiom used to solve this problem, for
example, strings.IndexAny(); strings.LastIndexAny() will likely use a nested
loop too. I don't understand why you are uncomfortable with the nested loop.
While an os.IsPathSeparator() function may well be useful, it doesn't help with
assignments and other cases which need the constants.
> I'm not sure if anyone really interested to see these consts (DirSep, DirSeps,
VolSep, PathSeps) - they are windows specific, and until we need them, I'd
rather not see them.
We shouldn't stumble from special case to special case; if possible, we should
address the general case. We should at least review the rest of the path package
to see if further renovation to accomodate Windows and other OSs might be
necessary, like replacing "magic numbers" with abstractions like directory
separators.
Abstractions like directory and path separators for hierarchical file systems
are OS independent; they are not Windows specific (even ancient IBM mainframe
OSs have directory separators (a period)).
> Why windows paths have to be so complicated <g>.
That's why it's important to have a good path package, to insulate Go
programmers from the ugly details.
Here's a refined version of my patch to the path.Split() function.
Peter
diff --git a/src/pkg/os/Makefile b/src/pkg/os/Makefile
--- a/src/pkg/os/Makefile
+++ b/src/pkg/os/Makefile
@@ -21,26 +21,31 @@
GOFILES_freebsd=\
env_unix.go\
file_unix.go\
+ path_unix.go\
sys_bsd.go\
GOFILES_darwin=\
env_unix.go\
file_unix.go\
+ path_unix.go\
sys_bsd.go\
GOFILES_linux=\
env_unix.go\
file_unix.go\
+ path_unix.go\
sys_linux.go\
GOFILES_nacl=\
env_unix.go\
file_unix.go\
+ path_unix.go\
sys_nacl.go\
GOFILES_windows=\
env_windows.go\
file_windows.go\
+ path_windows.go\
sys_windows.go\
GOFILES+=$(GOFILES_$(GOOS))
diff --git a/src/pkg/os/path_unix.go b/src/pkg/os/path_unix.go
new file mode 100644
--- /dev/null
+++ b/src/pkg/os/path_unix.go
@@ -0,0 +1,14 @@
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Unix-like operating systems
+
+package os
+
+const (
+ DirSep = `/`
+ DirSeps = DirSep
+ VolSep = ``
+ PathSeps = VolSep + DirSeps
+)
diff --git a/src/pkg/os/path_windows.go b/src/pkg/os/path_windows.go
new file mode 100644
--- /dev/null
+++ b/src/pkg/os/path_windows.go
@@ -0,0 +1,14 @@
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Windows operating system
+
+package os
+
+const (
+ DirSep = `\`
+ DirSeps = DirSep + `/`
+ VolSep = `:`
+ PathSeps = VolSep + DirSeps
+)
diff --git a/src/pkg/path/path.go b/src/pkg/path/path.go
--- a/src/pkg/path/path.go
+++ b/src/pkg/path/path.go
@@ -102,17 +102,27 @@
return string(buf[0:w])
}
+func lastIndexAny(s, chars string) int {
+ // TODO: replace with missing strings.LastIndexAny() function
+ // Note: simple version for ascii 7-bit char set
+ for i := len(s) - 1; i >= 0; i-- {
+ c := s[i]
+ for j := 0; j < len(chars); j++ {
+ if c == chars[j] {
+ return i
+ }
+ }
+ }
+ return -1
+}
+
// Split splits path immediately following the final slash,
// separating it into a directory and file name component.
// If there is no slash in path, Split returns an empty dir and
// file set to path.
func Split(path string) (dir, file string) {
- for i := len(path) - 1; i >= 0; i-- {
- if path[i] == '/' {
- return path[0 : i+1], path[i+1:]
- }
- }
- return "", path
+ i := lastIndexAny(path, os.PathSeps)
+ return path[0 : i+1], path[i+1:]
}
// Join joins any number of path elements into a single path, adding a
Sign in to reply to this message.
Alex,
Here's the full path.Split() function patch, including the missing
strings.LastIndexAny() function, that I use for Linux and Windows.
diff --git a/src/pkg/os/Makefile b/src/pkg/os/Makefile
--- a/src/pkg/os/Makefile
+++ b/src/pkg/os/Makefile
@@ -21,26 +21,31 @@
GOFILES_freebsd=\
env_unix.go\
file_unix.go\
+ path_unix.go\
sys_bsd.go\
GOFILES_darwin=\
env_unix.go\
file_unix.go\
+ path_unix.go\
sys_bsd.go\
GOFILES_linux=\
env_unix.go\
file_unix.go\
+ path_unix.go\
sys_linux.go\
GOFILES_nacl=\
env_unix.go\
file_unix.go\
+ path_unix.go\
sys_nacl.go\
GOFILES_windows=\
env_windows.go\
file_windows.go\
+ path_windows.go\
sys_windows.go\
GOFILES+=$(GOFILES_$(GOOS))
diff --git a/src/pkg/os/path_unix.go b/src/pkg/os/path_unix.go
new file mode 100644
--- /dev/null
+++ b/src/pkg/os/path_unix.go
@@ -0,0 +1,14 @@
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Unix-like operating systems
+
+package os
+
+const (
+ DirSep = `/`
+ DirSeps = DirSep
+ VolSep = ``
+ PathSeps = VolSep + DirSeps
+)
diff --git a/src/pkg/os/path_windows.go b/src/pkg/os/path_windows.go
new file mode 100644
--- /dev/null
+++ b/src/pkg/os/path_windows.go
@@ -0,0 +1,14 @@
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Windows operating system
+
+package os
+
+const (
+ DirSep = `\`
+ DirSeps = DirSep + `/`
+ VolSep = `:`
+ PathSeps = VolSep + DirSeps
+)
diff --git a/src/pkg/path/path.go b/src/pkg/path/path.go
--- a/src/pkg/path/path.go
+++ b/src/pkg/path/path.go
@@ -107,12 +107,8 @@
// If there is no slash in path, Split returns an empty dir and
// file set to path.
func Split(path string) (dir, file string) {
- for i := len(path) - 1; i >= 0; i-- {
- if path[i] == '/' {
- return path[0 : i+1], path[i+1:]
- }
- }
- return "", path
+ i := strings.LastIndexAny(path, os.PathSeps)
+ return path[0 : i+1], path[i+1:]
}
// Join joins any number of path elements into a single path, adding a
diff --git a/src/pkg/strings/strings.go b/src/pkg/strings/strings.go
--- a/src/pkg/strings/strings.go
+++ b/src/pkg/strings/strings.go
@@ -142,6 +142,35 @@
return -1
}
+// LastIndexAny returns the index of the last instance of any Unicode code
point
+// from chars in s, or -1 if no Unicode code point from chars is present in s.
+func LastIndexAny(s, sep string) int {
+ for i, leni := len(s)-1, 0; i >= 0; i-- {
+ leni++
+ if s[i]&0xC0 != 0x80 {
+ for j, lenj := len(sep)-1, 0; j >= 0; j-- {
+ lenj++
+ if sep[j]&0xC0 != 0x80 {
+ if leni == lenj {
+ if leni == 1 {
+ if s[i] == sep[j] {
+ return i
+ }
+ } else {
+ if s[i:i+leni] == sep[j:j+lenj] {
+ return i
+ }
+ }
+ }
+ lenj = 0
+ }
+ }
+ leni = 0
+ }
+ }
+ return -1
+}
+
// Generic split: splits after each instance of sep,
// including sepSave bytes of sep in the subarrays.
func genSplit(s, sep string, sepSave, n int) []string {
Peter
Sign in to reply to this message.
On 2010/11/12 20:04:20, PeterGo wrote: > Here's the full path.Split() function patch, including the missing > strings.LastIndexAny() function, that I use for Linux and Windows. > I'm not fussy either way. Alex
Sign in to reply to this message.
Hello r, rsc, PeterGo, r2, brainman (cc: golang-dev@googlegroups.com), Please take another look.
Sign in to reply to this message.
http://codereview.appspot.com/3008041/diff/17001/src/pkg/path/path.go File src/pkg/path/path.go (right): http://codereview.appspot.com/3008041/diff/17001/src/pkg/path/path.go#newcode109 src/pkg/path/path.go:109: func Split(path string) (dir, file string) { The first thing I noticed is that your code for the path.Split() function seems to be too complicated. We are using the new strings.LastIndexAny() function. // LastIndexAny returns the index of the last instance of any Unicode code // point from chars in s, or -1 if no Unicode code point from chars is // present in s. func LastIndexAny(s, chars string) int The strings.LastIndexAny() function returns an integer in the range -1 to len(s)-1 inclusive. Doesn't the code in your function path.Split() simplify to the code in my patch: i := strings.LastIndexAny(path, PathSeps) return path[0 : i+1], path[i+1:] For i = -1, len(dir) = 0, len(file) = len(path): return path[0 : i+1], path[i+1:] => return path[0 : -1+1], path[-1+1:] => return path[0 : 0], path[0:len(path)] => return "", path For i = 0, len(dir) = 1, len(file) = len(path)-1: return path[0 : i+1], path[i+1:] => return path[0 : 0+1], path[0+1:] => return path[0 : 1], path[1:len(path)] For i = len(path)-1, len(dir) = len(path), len(file) = 0: return path[0 : i+1], path[i+1:] => return path[0 : len(path)-1+1], path[len(path)-1+1:] => return path[0 : len(path)], path[len(path):len(path)] => return path, "" Do you have a test where this code fails?
Sign in to reply to this message.
Hello r, rsc, PeterGo, r2, brainman (cc: golang-dev@googlegroups.com), Please take another look.
Sign in to reply to this message.
http://codereview.appspot.com/3008041/diff/17001/src/pkg/path/path.go File src/pkg/path/path.go (right): http://codereview.appspot.com/3008041/diff/17001/src/pkg/path/path.go#newcode109 src/pkg/path/path.go:109: func Split(path string) (dir, file string) { On 2010/11/13 22:23:36, PeterGo wrote: > The first thing I noticed is that your code for the path.Split() function seems > to be too complicated. Good catch. Fixed. > Do you have a test where this code fails? No.
Sign in to reply to this message.
http://codereview.appspot.com/3008041/diff/2001/src/pkg/path/path.go File src/pkg/path/path.go (right): http://codereview.appspot.com/3008041/diff/2001/src/pkg/path/path.go#newcode112 src/pkg/path/path.go:112: if path[i] == '/' || (runtime.GOOS == "windows" && path[i] == '\\') { On 2010/11/09 21:16:18, r wrote: > these windows tests should be done once, in init(), and used to prepare simpler > tests for these properties > > ideally the init and runtime tests wouldn't even be compiled unless the OS was > windows. that's easy to do through the makefile and build system. > > it would be wrong to sprinkle if(windows) through the code. Done.
Sign in to reply to this message.
http://codereview.appspot.com/3008041/diff/23001/src/pkg/path/path_test.go File src/pkg/path/path_test.go (right): http://codereview.appspot.com/3008041/diff/23001/src/pkg/path/path_test.go#ne... src/pkg/path/path_test.go:87: var winsplittests = []SplitTest{ Go has two forms of string literals: raw string literals and interpreted string literals. In interpreted string literals, backslash escapes have special meaning. On Windows, the backslash character is the preferred, and sometimes required, directory separator. If we use Go raw string literals for path string literals, WYSIWYG (What You See Is What You Get). For example, the legible {`\\?\c:\`, `\\?\c:\`, ``}, which matches the documentation, instead of {"\\\\?\\c:\\", "\\\\?\\c:\\", ""}. http://codereview.appspot.com/3008041/diff/23001/src/pkg/path/path_windows.go File src/pkg/path/path_windows.go (right): http://codereview.appspot.com/3008041/diff/23001/src/pkg/path/path_windows.go... src/pkg/path/path_windows.go:7: const ( The path.Split() function uses well-known short-form variable names for path components: path, dir, and file. I named the path related constants DirSeps, VolSep, and PathSeps. If a device separator is needed, I would name it DevSep (we already have a constant DevNull). The names follow the usual Unix-like short-form naming conventions. You named the path related constants DirSeps, VolumeSeps and PathSeps. Why is it DirSeps and not DirectorySeps, like the other long-form names? If a device separator is needed, would you name it DeviceSeps or DevSeps. What is your naming convention for path component constant and variable names?
Sign in to reply to this message.
http://codereview.appspot.com/3008041/diff/23001/src/pkg/path/path.go File src/pkg/path/path.go (right): http://codereview.appspot.com/3008041/diff/23001/src/pkg/path/path.go#newcode105 src/pkg/path/path.go:105: // Split splits path immediately following the final slash, godoc comments must be accurate. s/slash/path separator/ http://codereview.appspot.com/3008041/diff/23001/src/pkg/path/path.go#newcode107 src/pkg/path/path.go:107: // If there is no slash in path, Split returns an empty dir and ditto http://codereview.appspot.com/3008041/diff/23001/src/pkg/path/path_windows.go File src/pkg/path/path_windows.go (right): http://codereview.appspot.com/3008041/diff/23001/src/pkg/path/path_windows.go... src/pkg/path/path_windows.go:10: PathSeps = DirSeps + VolumeSeps // all path separators (directory + volume) A nit. In the code and godoc documentation, we see: DirSeps = `\/` // directory separators VolumeSeps = `:` // volume separators PathSeps = DirSeps + VolumeSeps // all path separators (directory + volume) s/ (directory + volume)// PathSeps = DirSeps + VolumeSeps // all path separators It's still obvious that all path separators = (directory + volume). If we add to or subtract from the collection of path separators, there are no changes to the comment. As we have seen elsewhere, it's easy to let comments get out of date.
Sign in to reply to this message.
Hello r, rsc, PeterGo, r2, brainman (cc: golang-dev@googlegroups.com), Please take another look.
Sign in to reply to this message.
http://codereview.appspot.com/3008041/diff/23001/src/pkg/path/path.go File src/pkg/path/path.go (right): http://codereview.appspot.com/3008041/diff/23001/src/pkg/path/path.go#newcode105 src/pkg/path/path.go:105: // Split splits path immediately following the final slash, On 2010/11/14 22:27:36, PeterGo wrote: > godoc comments must be accurate. s/slash/path separator/ Done. http://codereview.appspot.com/3008041/diff/23001/src/pkg/path/path.go#newcode107 src/pkg/path/path.go:107: // If there is no slash in path, Split returns an empty dir and On 2010/11/14 22:27:36, PeterGo wrote: > ditto Done. http://codereview.appspot.com/3008041/diff/23001/src/pkg/path/path_test.go File src/pkg/path/path_test.go (right): http://codereview.appspot.com/3008041/diff/23001/src/pkg/path/path_test.go#ne... src/pkg/path/path_test.go:87: var winsplittests = []SplitTest{ On 2010/11/14 16:24:59, PeterGo wrote: > Go has two forms of string literals: raw string literals and interpreted string > literals. In interpreted string literals, backslash escapes have special > meaning. > > On Windows, the backslash character is the preferred, and sometimes required, > directory separator. If we use Go raw string literals for path string literals, > WYSIWYG (What You See Is What You Get). For example, the legible {`\\?\c:\`, > `\\?\c:\`, ``}, which matches the documentation, instead of {"\\\\?\\c:\\", > "\\\\?\\c:\\", ""}. Done. http://codereview.appspot.com/3008041/diff/23001/src/pkg/path/path_windows.go File src/pkg/path/path_windows.go (right): http://codereview.appspot.com/3008041/diff/23001/src/pkg/path/path_windows.go... src/pkg/path/path_windows.go:7: const ( On 2010/11/14 16:24:59, PeterGo wrote: > You named the path related constants DirSeps, VolumeSeps and PathSeps. Why is it > DirSeps and not DirectorySeps, like the other long-form names? Not sure about this. Rob? http://codereview.appspot.com/3008041/diff/23001/src/pkg/path/path_windows.go... src/pkg/path/path_windows.go:10: PathSeps = DirSeps + VolumeSeps // all path separators (directory + volume) On 2010/11/14 22:27:36, PeterGo wrote: > A nit. In the code and godoc documentation, we see: > > DirSeps = `\/` // directory separators > VolumeSeps = `:` // volume separators > PathSeps = DirSeps + VolumeSeps // all path separators (directory + > volume) > > s/ (directory + volume)// > > PathSeps = DirSeps + VolumeSeps // all path separators > > It's still obvious that all path separators = (directory + volume). If we add to > or subtract from the collection of path separators, there are no changes to the > comment. As we have seen elsewhere, it's easy to let comments get out of date. Done.
Sign in to reply to this message.
http://codereview.appspot.com/3008041/diff/32002/src/pkg/path/path_test.go File src/pkg/path/path_test.go (right): http://codereview.appspot.com/3008041/diff/32002/src/pkg/path/path_test.go#ne... src/pkg/path/path_test.go:90: {`C:\Windows`, `C:\\`, `Windows`}, On Windows, "FAIL: path.TestSplit." s/`C:\\`/`C:\`/
Sign in to reply to this message.
http://codereview.appspot.com/3008041/diff/32002/src/pkg/path/path_unix.go File src/pkg/path/path_unix.go (right): http://codereview.appspot.com/3008041/diff/32002/src/pkg/path/path_unix.go#ne... src/pkg/path/path_unix.go:1: // Copyright 2009 The Go Authors. All rights reserved. s/2009/2010/ The copyright date is the file creation date; it's not updated for changes. http://codereview.appspot.com/3008041/diff/32002/src/pkg/path/path_unix.go#ne... src/pkg/path/path_unix.go:6: "Doc comments begin with complete sentences." Russ http://groups.google.com/group/golang-dev/msg/9823f3f1daec5dea Consider adding a godoc comment like this. // The file system path is punctuated by separator characters to separate // the path into its elements, such as directories and a file. http://codereview.appspot.com/3008041/diff/32002/src/pkg/path/path_windows.go File src/pkg/path/path_windows.go (right): http://codereview.appspot.com/3008041/diff/32002/src/pkg/path/path_windows.go... src/pkg/path/path_windows.go:1: // Copyright 2009 The Go Authors. All rights reserved. s/2009/2010/ http://codereview.appspot.com/3008041/diff/32002/src/pkg/path/path_windows.go... src/pkg/path/path_windows.go:6: // The file system path is punctuated by separator characters to separate // the path into its elements, such as directories and a file.
Sign in to reply to this message.
http://codereview.appspot.com/3008041/diff/32002/src/pkg/path/path_test.go File src/pkg/path/path_test.go (right): http://codereview.appspot.com/3008041/diff/32002/src/pkg/path/path_test.go#ne... src/pkg/path/path_test.go:90: {`C:\Windows`, `C:\\`, `Windows`}, On 2010/11/15 16:45:22, PeterGo wrote: > On Windows, "FAIL: path.TestSplit." s/`C:\\`/`C:\`/ Done. Thanks! http://codereview.appspot.com/3008041/diff/32002/src/pkg/path/path_unix.go File src/pkg/path/path_unix.go (right): http://codereview.appspot.com/3008041/diff/32002/src/pkg/path/path_unix.go#ne... src/pkg/path/path_unix.go:1: // Copyright 2009 The Go Authors. All rights reserved. On 2010/11/15 22:22:49, PeterGo wrote: > s/2009/2010/ The copyright date is the file creation date; it's not updated for > changes. Done. http://codereview.appspot.com/3008041/diff/32002/src/pkg/path/path_unix.go#ne... src/pkg/path/path_unix.go:6: On 2010/11/15 22:22:49, PeterGo wrote: > "Doc comments begin with complete sentences." Russ Not for constants. Look at the comments for the constants in the os package, for example: O_EXCL int = syscall.O_EXCL // used with O_CREAT, file must not exist http://codereview.appspot.com/3008041/diff/32002/src/pkg/path/path_windows.go File src/pkg/path/path_windows.go (right): http://codereview.appspot.com/3008041/diff/32002/src/pkg/path/path_windows.go... src/pkg/path/path_windows.go:1: // Copyright 2009 The Go Authors. All rights reserved. On 2010/11/15 22:22:49, PeterGo wrote: > s/2009/2010/ Done. http://codereview.appspot.com/3008041/diff/32002/src/pkg/path/path_windows.go... src/pkg/path/path_windows.go:6: On 2010/11/15 22:22:49, PeterGo wrote: > // The file system path is punctuated by separator characters to separate > // the path into its elements, such as directories and a file. Personally, I think this is unnecessary.
Sign in to reply to this message.
Hello r, rsc, PeterGo, r2, brainman (cc: golang-dev@googlegroups.com), Please take another look.
Sign in to reply to this message.
On Wed, Nov 17, 2010 at 01:30, <alex.brainman@gmail.com> wrote: > LGTM > > http://codereview.appspot.com/3008041/ Ping?
Sign in to reply to this message.
the code is fine. let me know if you want to change the Makefile. http://codereview.appspot.com/3008041/diff/35006/src/pkg/path/Makefile File src/pkg/path/Makefile (right): http://codereview.appspot.com/3008041/diff/35006/src/pkg/path/Makefile#newcode12 src/pkg/path/Makefile:12: GOFILES_freebsd=\ this works and is fine and is also what some other makefiles do, but you could write something like ifeq ($(GOOS),windows) GOFILES+=path_windows.go else GOFILES+=path_unix.go endif this has the advantage that it maintains itself if someone adds a unix port. but i leave it up to you.
Sign in to reply to this message.
On 2010/11/30 21:32:05, r wrote: > write something like > > ifeq ($(GOOS),windows) > GOFILES+=path_windows.go > else > GOFILES+=path_unix.go > endif > > this has the advantage that it maintains itself if someone adds a unix port. It would be nice. But then $GOROOT/src/pkg/deps.bash script will not work. Alex
Sign in to reply to this message.
*** Submitted as http://code.google.com/p/go/source/detail?r=d3e867d23e3e *** path: Windows support for Split Make Split work on backslashes as well as on slashes under Windows and support the "C:filename" special case. Also add corresponding tests. R=r, rsc, PeterGo, r2, brainman CC=golang-dev http://codereview.appspot.com/3008041 Committer: Rob Pike <r@golang.org>
Sign in to reply to this message.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
