| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 #include "base/values.h" | |
| 11 | |
| 12 using std::ostream; | |
| 13 using std::string; | |
| 14 | |
| 15 namespace syncable { | |
| 16 | |
| 17 ostream& operator<<(ostream& out, const Id& id) { | |
| 18 out << id.s_; | |
| 19 return out; | |
| 20 } | |
| 21 | |
| 22 StringValue* Id::ToValue() const { | |
| 23 return Value::CreateStringValue(s_); | |
| 24 } | |
| 25 | |
| 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); | |
| 32 } | |
| 33 | |
| 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; | |
| 41 } | |
| 42 | |
| 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; | |
| 50 } | |
| 51 | |
| 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; | |
| 58 } | |
| 59 | |
| 60 bool Id::ContainsStringCaseInsensitive( | |
| 61 const std::string& lowercase_query) const { | |
| 62 DCHECK_EQ(StringToLowerASCII(lowercase_query), lowercase_query); | |
| 63 return StringToLowerASCII(s_).find(lowercase_query) != std::string::npos; | |
| 64 } | |
| 65 | |
| 66 // static | |
| 67 Id Id::GetLeastIdForLexicographicComparison() { | |
| 68 Id id; | |
| 69 id.s_.clear(); | |
| 70 return id; | |
| 71 } | |
| 72 | |
| 73 Id GetNullId() { | |
| 74 return Id(); // Currently == root. | |
| 75 } | |
| 76 | |
| 77 } // namespace syncable | |
| OLD | NEW |