Add NetworkUIData::GetONCSourceAsString
[chromium-blink-merge.git] / sync / syncable / syncable_id.cc
blob614fd3e128a70355dc812f488c5a097d84c48c7a
1 // Copyright (c) 2012 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.
5 #include "sync/syncable/syncable_id.h"
7 #include <iosfwd>
9 #include "base/values.h"
11 using std::ostream;
12 using std::string;
14 namespace syncer {
15 namespace syncable {
17 ostream& operator<<(ostream& out, const Id& id) {
18 out << id.s_;
19 return out;
22 base::StringValue* Id::ToValue() const {
23 return new base::StringValue(s_);
26 string Id::GetServerId() const {
27 // Currently root is the string "0". We need to decide on a true value.
28 // "" would be convenient here, as the IsRoot call would not be needed.
29 if (IsRoot())
30 return "0";
31 return s_.substr(1);
34 Id Id::CreateFromServerId(const string& server_id) {
35 Id id;
36 if (server_id == "0")
37 id.s_ = "r";
38 else
39 id.s_ = string("s") + server_id;
40 return id;
43 Id Id::CreateFromClientString(const string& local_id) {
44 Id id;
45 if (local_id == "0")
46 id.s_ = "r";
47 else
48 id.s_ = string("c") + local_id;
49 return id;
52 Id Id::GetLexicographicSuccessor() const {
53 // The successor of a string is given by appending the least
54 // character in the alphabet.
55 Id id = *this;
56 id.s_.push_back(0);
57 return id;
60 // static
61 Id Id::GetLeastIdForLexicographicComparison() {
62 Id id;
63 id.s_.clear();
64 return id;
67 Id GetNullId() {
68 return Id(); // Currently == root.
71 } // namespace syncable
72 } // namespace syncer