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. 4 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_ 7 8#include "base/basictypes.h" 9#include "base/memory/scoped_ptr.h" 10#include "chrome/browser/ui/app_list/search/tokenized_string.h" 11 12namespace base { 13namespace i18n { 14class UTF16CharIterator; 15} 16} 17 18namespace app_list { 19 20// An UTF16 char iterator for a TokenizedString. 21class TokenizedStringCharIterator { 22 public: 23 // Requires |tokenized| out-lives this iterator. 24 explicit TokenizedStringCharIterator(const TokenizedString& tokenized); 25 ~TokenizedStringCharIterator(); 26 27 // Advances to the next char. Returns false if there is no next char. 28 bool NextChar(); 29 30 // Advances to the first char of the next token. Returns false if there is 31 // no next token. 32 bool NextToken(); 33 34 // Returns the current char if there is one. Otherwise, returns 0. 35 int32 Get() const; 36 37 // Returns the array index in original text of the tokenized string that is 38 // passed in constructor. 39 int32 GetArrayPos() const; 40 41 // Returns the number of UTF16 code units for the current char. 42 size_t GetCharSize() const; 43 44 // Returns true if the current char is the first char of the current token. 45 bool IsFirstCharOfToken() const; 46 47 // Returns true if the iterator is at the end. 48 bool end() const { return !current_token_iter_; } 49 50 private: 51 void CreateTokenCharIterator(); 52 53 const TokenizedString::Tokens& tokens_; 54 const TokenizedString::Mappings& mappings_; 55 56 size_t current_token_; 57 scoped_ptr<base::i18n::UTF16CharIterator> current_token_iter_; 58 59 DISALLOW_COPY_AND_ASSIGN(TokenizedStringCharIterator); 60}; 61 62} // namespace app_list 63 64#endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_TOKENIZED_STRING_CHAR_ITERATOR_H_ 65