| 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 datastore | 5 package datastore | 
| 6 | 6 | 
| 7 import ( | 7 import ( | 
| 8         "errors" | 8         "errors" | 
| 9         "fmt" | 9         "fmt" | 
| 10         "math" | 10         "math" | 
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 407 } | 407 } | 
| 408 | 408 | 
| 409 // Save implements PropertyLoadSaver.Save by returning a copy of the | 409 // Save implements PropertyLoadSaver.Save by returning a copy of the | 
| 410 // current map data. | 410 // current map data. | 
| 411 func (pm PropertyMap) Save(withMeta bool) (PropertyMap, error) { | 411 func (pm PropertyMap) Save(withMeta bool) (PropertyMap, error) { | 
| 412         if len(pm) == 0 { | 412         if len(pm) == 0 { | 
| 413                 return PropertyMap{}, nil | 413                 return PropertyMap{}, nil | 
| 414         } | 414         } | 
| 415         ret := make(PropertyMap, len(pm)) | 415         ret := make(PropertyMap, len(pm)) | 
| 416         for k, v := range pm { | 416         for k, v := range pm { | 
| 417 »       »       if withMeta || len(k) == 0 || k[0] != '$' { | 417 »       »       if withMeta || !isMetaKey(k) { | 
| 418                         ret[k] = append(ret[k], v...) | 418                         ret[k] = append(ret[k], v...) | 
| 419                 } | 419                 } | 
| 420         } | 420         } | 
| 421         return ret, nil | 421         return ret, nil | 
| 422 } | 422 } | 
| 423 | 423 | 
| 424 // GetMeta implements PropertyLoadSaver.GetMeta, and returns the current value | 424 // GetMeta implements PropertyLoadSaver.GetMeta, and returns the current value | 
| 425 // associated with the metadata key. It may return ErrMetaFieldUnset if the | 425 // associated with the metadata key. It may return ErrMetaFieldUnset if the | 
| 426 // key doesn't exist. | 426 // key doesn't exist. | 
| 427 func (pm PropertyMap) GetMeta(key string) (interface{}, error) { | 427 func (pm PropertyMap) GetMeta(key string) (interface{}, error) { | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 443                 return err | 443                 return err | 
| 444         } | 444         } | 
| 445         pm["$"+key] = []Property{prop} | 445         pm["$"+key] = []Property{prop} | 
| 446         return nil | 446         return nil | 
| 447 } | 447 } | 
| 448 | 448 | 
| 449 // Problem implements PropertyLoadSaver.Problem. It ALWAYS returns nil. | 449 // Problem implements PropertyLoadSaver.Problem. It ALWAYS returns nil. | 
| 450 func (pm PropertyMap) Problem() error { | 450 func (pm PropertyMap) Problem() error { | 
| 451         return nil | 451         return nil | 
| 452 } | 452 } | 
|  | 453 | 
|  | 454 // DataLen returns the number of non-metadata rows in this PropertyMap. | 
|  | 455 func (pm PropertyMap) DataLen() int { | 
|  | 456         ret := 0 | 
|  | 457         for k := range pm { | 
|  | 458                 if isMetaKey(k) { | 
|  | 459                         continue | 
|  | 460                 } | 
|  | 461                 ret++ | 
|  | 462         } | 
|  | 463         return ret | 
|  | 464 } | 
|  | 465 | 
|  | 466 func isMetaKey(k string) bool { | 
|  | 467         // empty counts as a metakey since it's not a valid data key, but it's | 
|  | 468         // not really a valid metakey either. | 
|  | 469         return k == "" || k[0] == '$' | 
|  | 470 } | 
| OLD | NEW | 
|---|