| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package gs | 5 package gs |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "strings" | 8 "strings" |
| 9 ) | 9 ) |
| 10 | 10 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 return | 64 return |
| 65 } | 65 } |
| 66 | 66 |
| 67 bucket = v[:sidx] | 67 bucket = v[:sidx] |
| 68 v = v[sidx+1:] | 68 v = v[sidx+1:] |
| 69 } | 69 } |
| 70 filename = v | 70 filename = v |
| 71 return | 71 return |
| 72 } | 72 } |
| 73 | 73 |
| 74 // IsFullPath returns true if the Path contains both a bucket and file name. |
| 75 func (p Path) IsFullPath() bool { |
| 76 bucket, filename := p.Split() |
| 77 return (bucket != "" && filename != "") |
| 78 } |
| 79 |
| 74 // Concat concatenates a filename component to the end of Path. | 80 // Concat concatenates a filename component to the end of Path. |
| 75 // | 81 // |
| 76 // Multiple components may be specified. In this case, each will be added as a | 82 // Multiple components may be specified. In this case, each will be added as a |
| 77 // "/"-delimited component, and will have any present trailing slashes stripped. | 83 // "/"-delimited component, and will have any present trailing slashes stripped. |
| 78 func (p Path) Concat(v string, parts ...string) Path { | 84 func (p Path) Concat(v string, parts ...string) Path { |
| 79 comps := make([]string, 0, len(parts)+2) | 85 comps := make([]string, 0, len(parts)+2) |
| 80 add := func(v string) { | 86 add := func(v string) { |
| 81 v = stripTrailingSlashes(v) | 87 v = stripTrailingSlashes(v) |
| 82 if len(v) > 0 { | 88 if len(v) > 0 { |
| 83 comps = append(comps, v) | 89 comps = append(comps, v) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 97 func trimPrefix(s, prefix string) (string, bool) { | 103 func trimPrefix(s, prefix string) (string, bool) { |
| 98 if strings.HasPrefix(s, prefix) { | 104 if strings.HasPrefix(s, prefix) { |
| 99 return s[len(prefix):], true | 105 return s[len(prefix):], true |
| 100 } | 106 } |
| 101 return s, false | 107 return s, false |
| 102 } | 108 } |
| 103 | 109 |
| 104 func stripTrailingSlashes(v string) string { | 110 func stripTrailingSlashes(v string) string { |
| 105 return strings.TrimRight(v, "/") | 111 return strings.TrimRight(v, "/") |
| 106 } | 112 } |
| OLD | NEW |