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 3 // found in the LICENSE file. 4 5 #include "components/autofill/core/browser/autofill_scanner.h" 6 7 #include "base/logging.h" 8 #include "components/autofill/core/browser/autofill_field.h" 9 10 namespace autofill { 11 12 AutofillScanner::AutofillScanner(std::vector<AutofillField*>& fields) 13 : cursor_(fields.begin()), 14 saved_cursor_(fields.begin()), 15 begin_(fields.begin()), 16 end_(fields.end()) { 17 } 18 19 AutofillScanner::~AutofillScanner() { 20 } 21 22 void AutofillScanner::Advance() { 23 DCHECK(!IsEnd()); 24 ++cursor_; 25 } 26 27 AutofillField* AutofillScanner::Cursor() const { 28 if (IsEnd()) { 29 NOTREACHED(); 30 return NULL; 31 } 32 33 return *cursor_; 34 } 35 36 bool AutofillScanner::IsEnd() const { 37 return cursor_ == end_; 38 } 39 40 void AutofillScanner::Rewind() { 41 DCHECK(saved_cursor_ != end_); 42 cursor_ = saved_cursor_; 43 saved_cursor_ = end_; 44 } 45 46 void AutofillScanner::RewindTo(size_t index) { 47 DCHECK(index < static_cast<size_t>(end_ - begin_)); 48 cursor_ = begin_ + index; 49 saved_cursor_ = end_; 50 } 51 52 size_t AutofillScanner::SaveCursor() { 53 saved_cursor_ = cursor_; 54 return static_cast<size_t>(cursor_ - begin_); 55 } 56 57 } // namespace autofill 58