syncable_id.cc revision 72a454cd3513ac24fbdd0e0cb9ad70b86a99b801
1// Copyright (c) 2009 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/sync/syncable/syncable_id.h" 6 7#include <iosfwd> 8 9#include "base/string_util.h" 10 11using std::ostream; 12using std::string; 13 14namespace syncable { 15const Id kNullId; // Currently == root. 16 17ostream& operator<<(ostream& out, const Id& id) { 18 out << id.s_; 19 return out; 20} 21 22string Id::GetServerId() const { 23 // Currently root is the string "0". We need to decide on a true value. 24 // "" would be convenient here, as the IsRoot call would not be needed. 25 if (IsRoot()) 26 return "0"; 27 return s_.substr(1); 28} 29 30Id Id::CreateFromServerId(const string& server_id) { 31 Id id; 32 if (server_id == "0") 33 id.s_ = "r"; 34 else 35 id.s_ = string("s") + server_id; 36 return id; 37} 38 39Id Id::CreateFromClientString(const string& local_id) { 40 Id id; 41 if (local_id == "0") 42 id.s_ = "r"; 43 else 44 id.s_ = string("c") + local_id; 45 return id; 46} 47 48} // namespace syncable 49