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