diff options
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/autofill/autofill_scanner.cc | 19 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_scanner.h | 18 | ||||
-rw-r--r-- | chrome/browser/autofill/credit_card_field.cc | 6 | ||||
-rw-r--r-- | chrome/browser/autofill/phone_field.cc | 3 |
4 files changed, 31 insertions, 15 deletions
diff --git a/chrome/browser/autofill/autofill_scanner.cc b/chrome/browser/autofill/autofill_scanner.cc index 1fd8a7e..41aadc8 100644 --- a/chrome/browser/autofill/autofill_scanner.cc +++ b/chrome/browser/autofill/autofill_scanner.cc @@ -10,6 +10,8 @@ AutofillScanner::AutofillScanner( const std::vector<const AutofillField*>& fields) : cursor_(fields.begin()), + saved_cursor_(fields.begin()), + begin_(fields.begin()), end_(fields.end()) { } @@ -35,11 +37,18 @@ bool AutofillScanner::IsEnd() const { } void AutofillScanner::Rewind() { - DCHECK(!saved_cursors_.empty()); - cursor_ = saved_cursors_.back(); - saved_cursors_.pop_back(); + DCHECK(saved_cursor_ != end_); + cursor_ = saved_cursor_; + saved_cursor_ = end_; } -void AutofillScanner::SaveCursor() { - saved_cursors_.push_back(cursor_); +void AutofillScanner::RewindTo(size_t index) { + DCHECK(index < static_cast<size_t>(end_ - begin_)); + cursor_ = begin_ + index; + saved_cursor_ = end_; +} + +size_t AutofillScanner::SaveCursor() { + saved_cursor_ = cursor_; + return static_cast<size_t>(cursor_ - begin_); } diff --git a/chrome/browser/autofill/autofill_scanner.h b/chrome/browser/autofill/autofill_scanner.h index 789889b..562bab8 100644 --- a/chrome/browser/autofill/autofill_scanner.h +++ b/chrome/browser/autofill/autofill_scanner.h @@ -29,19 +29,25 @@ class AutofillScanner { // Returns |true| if the cursor has reached the end of the stream. bool IsEnd() const; - // Returns the most recently saved cursor -- see also |SaveCursor()|. + // Restores the most recently saved cursor. See also |SaveCursor()|. void Rewind(); - // Saves the current cursor position. Multiple cursor positions can be saved, - // with stack ordering semantics. See also |Rewind()|. - void SaveCursor(); + // Repositions the cursor to the specified |index|. See also |SaveCursor()|. + void RewindTo(size_t index); + + // Saves and returns the current cursor position. See also |Rewind()| and + // |RewindTo()|. + size_t SaveCursor(); private: // Indicates the current position in the stream, represented as a vector. std::vector<const AutofillField*>::const_iterator cursor_; - // A stack of saved positions in the stream. - std::vector<std::vector<const AutofillField*>::const_iterator> saved_cursors_; + // The most recently saved cursor. + std::vector<const AutofillField*>::const_iterator saved_cursor_; + + // The beginning pointer for the stream. + const std::vector<const AutofillField*>::const_iterator begin_; // The past-the-end pointer for the stream. const std::vector<const AutofillField*>::const_iterator end_; diff --git a/chrome/browser/autofill/credit_card_field.cc b/chrome/browser/autofill/credit_card_field.cc index 13f5a89..8d504f4 100644 --- a/chrome/browser/autofill/credit_card_field.cc +++ b/chrome/browser/autofill/credit_card_field.cc @@ -27,7 +27,7 @@ FormField* CreditCardField::Parse(AutofillScanner* scanner, return NULL; scoped_ptr<CreditCardField> credit_card_field(new CreditCardField); - scanner->SaveCursor(); + size_t saved_cursor = scanner->SaveCursor(); // Credit card fields can appear in many different orders. // We loop until no more credit card related fields are found, see |break| at @@ -131,7 +131,7 @@ FormField* CreditCardField::Parse(AutofillScanner* scanner, if (!ParseFieldSpecifics(scanner, pattern, MATCH_DEFAULT | MATCH_SELECT, &credit_card_field->expiration_year_)) { - scanner->Rewind(); + scanner->RewindTo(saved_cursor); return NULL; } continue; @@ -179,7 +179,7 @@ FormField* CreditCardField::Parse(AutofillScanner* scanner, return credit_card_field.release(); } - scanner->Rewind(); + scanner->RewindTo(saved_cursor); return NULL; } diff --git a/chrome/browser/autofill/phone_field.cc b/chrome/browser/autofill/phone_field.cc index 58a7fc8..064dfc6 100644 --- a/chrome/browser/autofill/phone_field.cc +++ b/chrome/browser/autofill/phone_field.cc @@ -263,7 +263,6 @@ bool PhoneField::ParseInternal(PhoneField *phone_field, for (size_t i = 0; i < arraysize(phone_field_grammars_); ++i) { memset(parsed_fields, 0, sizeof(parsed_fields)); - scanner->Rewind(); scanner->SaveCursor(); // Attempt to parse according to the next grammar. @@ -300,6 +299,8 @@ bool PhoneField::ParseInternal(PhoneField *phone_field, scanner->Rewind(); return false; // Tried through all the possibilities - did not match. } + + scanner->Rewind(); } if (!parsed_fields[FIELD_PHONE]) { |