OLD | NEW |
1 // Copyright 2015 The LUCI Authors. | 1 // Copyright 2015 The LUCI Authors. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 for _, t := range k.toks { | 243 for _, t := range k.toks { |
244 if t.StringID != "" { | 244 if t.StringID != "" { |
245 fmt.Fprintf(b, "/%s,%q", t.Kind, t.StringID) | 245 fmt.Fprintf(b, "/%s,%q", t.Kind, t.StringID) |
246 } else { | 246 } else { |
247 fmt.Fprintf(b, "/%s,%d", t.Kind, t.IntID) | 247 fmt.Fprintf(b, "/%s,%d", t.Kind, t.IntID) |
248 } | 248 } |
249 } | 249 } |
250 return b.String() | 250 return b.String() |
251 } | 251 } |
252 | 252 |
253 // IsIncomplete returns true iff k doesn't have an id yet. | 253 // IsIncomplete returns true iff the last token of this Key doesn't define |
| 254 // either a StringID or an IntID. |
254 func (k *Key) IsIncomplete() bool { | 255 func (k *Key) IsIncomplete() bool { |
255 return k.LastTok().IsIncomplete() | 256 return k.LastTok().IsIncomplete() |
256 } | 257 } |
257 | 258 |
258 // Valid determines if a key is valid, according to a couple of rules: | 259 // Valid determines if a key is valid, according to a couple of rules: |
259 // - k is not nil | 260 // - k is not nil |
260 // - every token of k: | 261 // - every token of k: |
261 // - (if !allowSpecial) token's kind doesn't start with '__' | 262 // - (if !allowSpecial) token's kind doesn't start with '__' |
262 // - token's kind and appid are non-blank | 263 // - token's kind and appid are non-blank |
263 // - token is not incomplete | 264 // - token is not incomplete |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 for _, t := range k.toks { | 531 for _, t := range k.toks { |
531 ret += int64(len(t.Kind)) | 532 ret += int64(len(t.Kind)) |
532 if t.StringID != "" { | 533 if t.StringID != "" { |
533 ret += int64(len(t.StringID)) | 534 ret += int64(len(t.StringID)) |
534 } else { | 535 } else { |
535 ret += 8 | 536 ret += 8 |
536 } | 537 } |
537 } | 538 } |
538 return ret | 539 return ret |
539 } | 540 } |
OLD | NEW |