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 UI_APP_LIST_SEARCH_TOKENIZED_STRING_CHAR_ITERATOR_H_
6 #define UI_APP_LIST_SEARCH_TOKENIZED_STRING_CHAR_ITERATOR_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "ui/app_list/app_list_export.h"
11 #include "ui/app_list/search/tokenized_string.h"
15 class UTF16CharIterator
;
21 // An UTF16 char iterator for a TokenizedString.
22 class APP_LIST_EXPORT TokenizedStringCharIterator
{
26 State(size_t token_index
, int char_index
);
32 // Requires |tokenized| out-lives this iterator.
33 explicit TokenizedStringCharIterator(const TokenizedString
& tokenized
);
34 ~TokenizedStringCharIterator();
36 // Advances to the next char. Returns false if there is no next char.
39 // Advances to the first char of the next token. Returns false if there is
43 // Returns the current char if there is one. Otherwise, returns 0.
46 // Returns the array index in original text of the tokenized string that is
47 // passed in constructor.
48 int32
GetArrayPos() const;
50 // Returns the number of UTF16 code units for the current char.
51 size_t GetCharSize() const;
53 // Returns true if the current char is the first char of the current token.
54 bool IsFirstCharOfToken() const;
56 // Helpers to get and restore the iterator's state.
57 State
GetState() const;
58 void SetState(const State
& state
);
60 // Returns true if the iterator is at the end.
61 bool end() const { return !current_token_iter_
; }
64 void CreateTokenCharIterator();
66 const TokenizedString::Tokens
& tokens_
;
67 const TokenizedString::Mappings
& mappings_
;
69 size_t current_token_
;
70 scoped_ptr
<base::i18n::UTF16CharIterator
> current_token_iter_
;
72 DISALLOW_COPY_AND_ASSIGN(TokenizedStringCharIterator
);
75 } // namespace app_list
77 #endif // UI_APP_LIST_SEARCH_TOKENIZED_STRING_CHAR_ITERATOR_H_