autofill_scanner.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_SCANNER_H_
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_SCANNER_H_
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include <vector>
990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "base/basictypes.h"
11c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/strings/string16.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace autofill {
14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class AutofillField;
1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// A helper class for parsing a stream of |AutofillField|'s with lookahead.
18b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)class AutofillScanner {
19b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) public:
20b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  explicit AutofillScanner(const std::vector<const AutofillField*>& fields);
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ~AutofillScanner();
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
23b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // Advances the cursor by one step, if possible.
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void Advance();
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns the current field in the stream, or |NULL| if there are no more
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // fields in the stream.
28eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  const AutofillField* Cursor() const;
29eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
30eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Returns |true| if the cursor has reached the end of the stream.
31eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  bool IsEnd() const;
32eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
33eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Restores the most recently saved cursor. See also |SaveCursor()|.
34eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  void Rewind();
35eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
36eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Repositions the cursor to the specified |index|. See also |SaveCursor()|.
37eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  void RewindTo(size_t index);
38eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
39eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Saves and returns the current cursor position. See also |Rewind()| and
40eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // |RewindTo()|.
41eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  size_t SaveCursor();
42eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
43eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch private:
44eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Indicates the current position in the stream, represented as a vector.
4590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  std::vector<const AutofillField*>::const_iterator cursor_;
4690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
4790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // The most recently saved cursor.
4890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  std::vector<const AutofillField*>::const_iterator saved_cursor_;
4990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
5090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // The beginning pointer for the stream.
5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  const std::vector<const AutofillField*>::const_iterator begin_;
5290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
5390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // The past-the-end pointer for the stream.
5490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  const std::vector<const AutofillField*>::const_iterator end_;
5590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
5690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(AutofillScanner);
5790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)};
5890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
5990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}  // namespace autofill
60eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
6190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif  // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_SCANNER_H_
62eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch