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

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

Issue 2699943004: LogDog: Implement StreamName.Split. (Closed)
Patch Set: comments 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..fd3f8642edc17e28af3f2c4eb10fa58c3573c7b9 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 prefix (everything
+// 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, prefix will be empty.
+//
+// For example:
+//
+// - Split("foo/bar/baz") ("foo/bar", "baz")
+// - Split("foo") ("", "foo")
+// - Split("") ("", "")
+func (s StreamName) Split() (prefix, last StreamName) {
+ lidx := strings.LastIndex(string(s), StreamNameSepStr)
+ if lidx < 0 {
+ last = s
+ return
+ }
+ prefix, 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