Chromium Code Reviews| Index: logdog/common/types/streamname.go |
| diff --git a/logdog/common/types/streamname.go b/logdog/common/types/streamname.go |
| index 7dd0365c84c4f6d96366cb5aef5e2a4d05bb1374..e91cce33426ed5cc857c2a1dd132d404b21ad827 100644 |
| --- a/logdog/common/types/streamname.go |
| +++ b/logdog/common/types/streamname.go |
| @@ -233,6 +233,28 @@ func (s StreamName) SegmentCount() int { |
| return segmentCount(string(s)) |
| } |
| +// Split splits a StreamName on its last path element, into a base (everything |
|
nodir
2017/02/18 05:01:51
"base" is somewhat confusing here. Term base is us
dnj
2017/02/18 06:09:31
Change to "prefix".
|
| +// before that element) and the last element. |
| +// |
| +// Split assumes that s is a valid stream name. |
| +// |
| +// If there is only one element in the stream name, base will be empty. |
| +// |
| +// For example: |
| +// |
| +// - Split("foo/bar/baz") ("foo/bar", "baz") |
| +// - Split("foo") ("", "foo") |
| +// - Split("") ("", "") |
| +func (s StreamName) Split() (base StreamName, last StreamName) { |
|
nodir
2017/02/18 05:01:51
(base, last StreamName)
dnj
2017/02/18 06:09:31
Done.
|
| + lidx := strings.LastIndex(string(s), StreamNameSepStr) |
| + if lidx < 0 { |
| + last = s |
| + return |
| + } |
| + base, last = s[:lidx], s[lidx+len(StreamNameSepStr):] |
| + return |
| +} |
| + |
| // UnmarshalJSON implements json.Unmarshaler. |
| func (s *StreamName) UnmarshalJSON(data []byte) error { |
| v := "" |