Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(305)

Unified Diff: logdog/common/types/streamname.go

Issue 2699943004: LogDog: Implement StreamName.Split. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | logdog/common/types/streamname_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 := ""
« no previous file with comments | « no previous file | logdog/common/types/streamname_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698