| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #include <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "chrome/browser/autofill/form_group.h" | 7 #include "chrome/browser/autofill/form_group.h" |
| 8 | 8 |
| 9 #include <iterator> | 9 #include <iterator> |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 string16 FormGroup::GetCanonicalizedInfo(AutofillFieldType type) const { | 40 string16 FormGroup::GetCanonicalizedInfo(AutofillFieldType type) const { |
| 41 return GetInfo(type); | 41 return GetInfo(type); |
| 42 } | 42 } |
| 43 | 43 |
| 44 bool FormGroup::SetCanonicalizedInfo(AutofillFieldType type, | 44 bool FormGroup::SetCanonicalizedInfo(AutofillFieldType type, |
| 45 const string16& value) { | 45 const string16& value) { |
| 46 SetInfo(type, value); | 46 SetInfo(type, value); |
| 47 return true; | 47 return true; |
| 48 } | 48 } |
| 49 | |
| 50 const string16 FormGroup::Label() const { return string16(); } | |
| 51 | |
| 52 bool FormGroup::operator!=(const FormGroup& form_group) const { | |
| 53 FieldTypeSet a, b, symmetric_difference; | |
| 54 GetNonEmptyTypes(&a); | |
| 55 form_group.GetNonEmptyTypes(&b); | |
| 56 std::set_symmetric_difference( | |
| 57 a.begin(), a.end(), | |
| 58 b.begin(), b.end(), | |
| 59 std::inserter(symmetric_difference, symmetric_difference.begin())); | |
| 60 | |
| 61 if (!symmetric_difference.empty()) | |
| 62 return true; | |
| 63 | |
| 64 return (!IntersectionOfTypesHasEqualValues(form_group)); | |
| 65 } | |
| 66 | |
| 67 bool FormGroup::IsSubsetOf(const FormGroup& form_group) const { | |
| 68 FieldTypeSet types; | |
| 69 GetNonEmptyTypes(&types); | |
| 70 | |
| 71 for (FieldTypeSet::const_iterator iter = types.begin(); iter != types.end(); | |
| 72 ++iter) { | |
| 73 if (StringToLowerASCII(GetInfo(*iter)) != | |
| 74 StringToLowerASCII(form_group.GetInfo(*iter))) | |
| 75 return false; | |
| 76 } | |
| 77 | |
| 78 return true; | |
| 79 } | |
| 80 | |
| 81 bool FormGroup::IntersectionOfTypesHasEqualValues( | |
| 82 const FormGroup& form_group) const { | |
| 83 FieldTypeSet a, b, intersection; | |
| 84 GetNonEmptyTypes(&a); | |
| 85 form_group.GetNonEmptyTypes(&b); | |
| 86 std::set_intersection(a.begin(), a.end(), | |
| 87 b.begin(), b.end(), | |
| 88 std::inserter(intersection, intersection.begin())); | |
| 89 | |
| 90 // An empty intersection can't have equal values. | |
| 91 if (intersection.empty()) | |
| 92 return false; | |
| 93 | |
| 94 for (FieldTypeSet::const_iterator iter = intersection.begin(); | |
| 95 iter != intersection.end(); ++iter) { | |
| 96 if (StringToLowerASCII(GetInfo(*iter)) != | |
| 97 StringToLowerASCII(form_group.GetInfo(*iter))) | |
| 98 return false; | |
| 99 } | |
| 100 | |
| 101 return true; | |
| 102 } | |
| 103 | |
| 104 void FormGroup::MergeWith(const FormGroup& form_group) { | |
| 105 FieldTypeSet a, b, difference; | |
| 106 GetNonEmptyTypes(&a); | |
| 107 form_group.GetNonEmptyTypes(&b); | |
| 108 std::set_difference(b.begin(), b.end(), | |
| 109 a.begin(), a.end(), | |
| 110 std::inserter(difference, difference.begin())); | |
| 111 | |
| 112 for (FieldTypeSet::const_iterator iter = difference.begin(); | |
| 113 iter != difference.end(); ++iter) { | |
| 114 SetInfo(*iter, form_group.GetInfo(*iter)); | |
| 115 } | |
| 116 } | |
| OLD | NEW |