Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(592)

Delta Between Two Patch Sets: names/unit.go

Issue 12473043: names: add ParseTag
Left Patch Set: Created 10 years, 7 months ago
Right Patch Set: names: add ParseTag Created 10 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « names/tag_test.go ('k') | names/unit_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2013 Canonical Ltd. 1 // Copyright 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package names 4 package names
5 5
6 import ( 6 import (
7 "fmt" 7 "fmt"
8 "regexp" 8 "regexp"
9 "strings" 9 "strings"
10 ) 10 )
(...skipping 10 matching lines...) Expand all
21 } 21 }
22 unitName = unitName[:i] + "-" + unitName[i+1:] 22 unitName = unitName[:i] + "-" + unitName[i+1:]
23 return makeTag(UnitTagKind, unitName) 23 return makeTag(UnitTagKind, unitName)
24 } 24 }
25 25
26 // IsUnit returns whether name is a valid unit name. 26 // IsUnit returns whether name is a valid unit name.
27 func IsUnit(name string) bool { 27 func IsUnit(name string) bool {
28 return validUnit.MatchString(name) 28 return validUnit.MatchString(name)
29 } 29 }
30 30
31 func unitFromTagName(name string) string { 31 func unitTagSuffixToId(s string) string {
32 // Replace only the last "-" with "/", as it is valid for service 32 // Replace only the last "-" with "/", as it is valid for service
33 // names to contain hyphens. 33 // names to contain hyphens.
34 » if i := strings.LastIndex(name, "-"); i > 0 { 34 » if i := strings.LastIndex(s, "-"); i > 0 {
35 » » name = name[:i] + "/" + name[i+1:] 35 » » s = s[:i] + "/" + s[i+1:]
36 } 36 }
37 » return name 37 » return s
38 } 38 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b