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.
5 #ifndef CHROME_BROWSER_UI_APP_LIST_SEARCH_TOKENIZED_STRING_CHAR_ITERATOR_H_
6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_TOKENIZED_STRING_CHAR_ITERATOR_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/ui/app_list/search/tokenized_string.h"
14 class UTF16CharIterator;
20 // An UTF16 char iterator for a TokenizedString.
21 class TokenizedStringCharIterator {
25 State(size_t token_index, int char_index);
31 // Requires |tokenized| out-lives this iterator.
32 explicit TokenizedStringCharIterator(const TokenizedString& tokenized);
33 ~TokenizedStringCharIterator();
35 // Advances to the next char. Returns false if there is no next char.
38 // Advances to the first char of the next token. Returns false if there is
42 // Returns the current char if there is one. Otherwise, returns 0.
45 // Returns the array index in original text of the tokenized string that is
46 // passed in constructor.
47 int32 GetArrayPos() const;
49 // Returns the number of UTF16 code units for the current char.
50 size_t GetCharSize() const;
52 // Returns true if the current char is the first char of the current token.
53 bool IsFirstCharOfToken() const;
55 // Helpers to get and restore the iterator's state.
56 State GetState() const;
57 void SetState(const State& state);
59 // Returns true if the iterator is at the end.
60 bool end() const { return !current_token_iter_; }
63 void CreateTokenCharIterator();
65 const TokenizedString::Tokens& tokens_;
66 const TokenizedString::Mappings& mappings_;
68 size_t current_token_;
69 scoped_ptr<base::i18n::UTF16CharIterator> current_token_iter_;
71 DISALLOW_COPY_AND_ASSIGN(TokenizedStringCharIterator);
74 } // namespace app_list
76 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_TOKENIZED_STRING_CHAR_ITERATOR_H_