| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/core/browser/autofill_scanner.h" | 5 #include "components/autofill/core/browser/autofill_scanner.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "components/autofill/core/browser/autofill_field.h" | 8 #include "components/autofill/core/browser/autofill_field.h" |
| 9 | 9 |
| 10 namespace autofill { | 10 namespace autofill { |
| 11 | 11 |
| 12 AutofillScanner::AutofillScanner(const std::vector<AutofillField*>& fields) | 12 AutofillScanner::AutofillScanner(const std::vector<AutofillField*>& fields) { |
| 13 : cursor_(fields.begin()), | 13 Init(fields); |
| 14 saved_cursor_(fields.begin()), | 14 } |
| 15 begin_(fields.begin()), | 15 |
| 16 end_(fields.end()) { | 16 AutofillScanner::AutofillScanner( |
| 17 const std::vector<std::unique_ptr<AutofillField>>& fields) { |
| 18 for (const auto& field : fields) |
| 19 non_owning_.push_back(field.get()); |
| 20 |
| 21 Init(non_owning_); |
| 17 } | 22 } |
| 18 | 23 |
| 19 AutofillScanner::~AutofillScanner() { | 24 AutofillScanner::~AutofillScanner() { |
| 20 } | 25 } |
| 21 | 26 |
| 22 void AutofillScanner::Advance() { | 27 void AutofillScanner::Advance() { |
| 23 DCHECK(!IsEnd()); | 28 DCHECK(!IsEnd()); |
| 24 ++cursor_; | 29 ++cursor_; |
| 25 } | 30 } |
| 26 | 31 |
| 27 AutofillField* AutofillScanner::Cursor() const { | 32 AutofillField* AutofillScanner::Cursor() const { |
| 28 if (IsEnd()) { | 33 if (IsEnd()) { |
| 29 NOTREACHED(); | 34 NOTREACHED(); |
| 30 return NULL; | 35 return nullptr; |
| 31 } | 36 } |
| 32 | 37 |
| 33 return *cursor_; | 38 return *cursor_; |
| 34 } | 39 } |
| 35 | 40 |
| 36 bool AutofillScanner::IsEnd() const { | 41 bool AutofillScanner::IsEnd() const { |
| 37 return cursor_ == end_; | 42 return cursor_ == end_; |
| 38 } | 43 } |
| 39 | 44 |
| 40 void AutofillScanner::Rewind() { | 45 void AutofillScanner::Rewind() { |
| 41 DCHECK(saved_cursor_ != end_); | 46 DCHECK(saved_cursor_ != end_); |
| 42 cursor_ = saved_cursor_; | 47 cursor_ = saved_cursor_; |
| 43 saved_cursor_ = end_; | 48 saved_cursor_ = end_; |
| 44 } | 49 } |
| 45 | 50 |
| 46 void AutofillScanner::RewindTo(size_t index) { | 51 void AutofillScanner::RewindTo(size_t index) { |
| 47 DCHECK(index < static_cast<size_t>(end_ - begin_)); | 52 DCHECK(index < static_cast<size_t>(end_ - begin_)); |
| 48 cursor_ = begin_ + index; | 53 cursor_ = begin_ + index; |
| 49 saved_cursor_ = end_; | 54 saved_cursor_ = end_; |
| 50 } | 55 } |
| 51 | 56 |
| 52 size_t AutofillScanner::SaveCursor() { | 57 size_t AutofillScanner::SaveCursor() { |
| 53 saved_cursor_ = cursor_; | 58 saved_cursor_ = cursor_; |
| 54 return static_cast<size_t>(cursor_ - begin_); | 59 return static_cast<size_t>(cursor_ - begin_); |
| 55 } | 60 } |
| 56 | 61 |
| 62 void AutofillScanner::Init(const std::vector<AutofillField*>& fields) { |
| 63 cursor_ = fields.begin(); |
| 64 saved_cursor_ = fields.begin(); |
| 65 begin_ = fields.begin(); |
| 66 end_ = fields.end(); |
| 67 } |
| 68 |
| 57 } // namespace autofill | 69 } // namespace autofill |
| OLD | NEW |