| 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 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_SCANNER_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_SCANNER_H_ |
| 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_SCANNER_H_ | 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_SCANNER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 | 12 |
| 13 namespace autofill { | 13 namespace autofill { |
| 14 | 14 |
| 15 class AutofillField; | 15 class AutofillField; |
| 16 | 16 |
| 17 // A helper class for parsing a stream of |AutofillField|'s with lookahead. | 17 // A helper class for parsing a stream of |AutofillField|'s with lookahead. |
| 18 class AutofillScanner { | 18 class AutofillScanner { |
| 19 public: | 19 public: |
| 20 explicit AutofillScanner(const std::vector<const AutofillField*>& fields); | 20 explicit AutofillScanner(std::vector<AutofillField*>& fields); |
| 21 ~AutofillScanner(); | 21 ~AutofillScanner(); |
| 22 | 22 |
| 23 // Advances the cursor by one step, if possible. | 23 // Advances the cursor by one step, if possible. |
| 24 void Advance(); | 24 void Advance(); |
| 25 | 25 |
| 26 // Returns the current field in the stream, or |NULL| if there are no more | 26 // Returns the current field in the stream, or |NULL| if there are no more |
| 27 // fields in the stream. | 27 // fields in the stream. |
| 28 const AutofillField* Cursor() const; | 28 AutofillField* Cursor() const; |
| 29 | 29 |
| 30 // Returns |true| if the cursor has reached the end of the stream. | 30 // Returns |true| if the cursor has reached the end of the stream. |
| 31 bool IsEnd() const; | 31 bool IsEnd() const; |
| 32 | 32 |
| 33 // Restores the most recently saved cursor. See also |SaveCursor()|. | 33 // Restores the most recently saved cursor. See also |SaveCursor()|. |
| 34 void Rewind(); | 34 void Rewind(); |
| 35 | 35 |
| 36 // Repositions the cursor to the specified |index|. See also |SaveCursor()|. | 36 // Repositions the cursor to the specified |index|. See also |SaveCursor()|. |
| 37 void RewindTo(size_t index); | 37 void RewindTo(size_t index); |
| 38 | 38 |
| 39 // Saves and returns the current cursor position. See also |Rewind()| and | 39 // Saves and returns the current cursor position. See also |Rewind()| and |
| 40 // |RewindTo()|. | 40 // |RewindTo()|. |
| 41 size_t SaveCursor(); | 41 size_t SaveCursor(); |
| 42 | 42 |
| 43 private: | 43 private: |
| 44 // Indicates the current position in the stream, represented as a vector. | 44 // Indicates the current position in the stream, represented as a vector. |
| 45 std::vector<const AutofillField*>::const_iterator cursor_; | 45 std::vector<AutofillField*>::const_iterator cursor_; |
| 46 | 46 |
| 47 // The most recently saved cursor. | 47 // The most recently saved cursor. |
| 48 std::vector<const AutofillField*>::const_iterator saved_cursor_; | 48 std::vector<AutofillField*>::const_iterator saved_cursor_; |
| 49 | 49 |
| 50 // The beginning pointer for the stream. | 50 // The beginning pointer for the stream. |
| 51 const std::vector<const AutofillField*>::const_iterator begin_; | 51 const std::vector<AutofillField*>::iterator begin_; |
| 52 | 52 |
| 53 // The past-the-end pointer for the stream. | 53 // The past-the-end pointer for the stream. |
| 54 const std::vector<const AutofillField*>::const_iterator end_; | 54 const std::vector<AutofillField*>::iterator end_; |
| 55 | 55 |
| 56 DISALLOW_COPY_AND_ASSIGN(AutofillScanner); | 56 DISALLOW_COPY_AND_ASSIGN(AutofillScanner); |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 } // namespace autofill | 59 } // namespace autofill |
| 60 | 60 |
| 61 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_SCANNER_H_ | 61 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_SCANNER_H_ |
| OLD | NEW |