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_TERM_BREAK_ITERATOR_H_
6 #define UI_APP_LIST_SEARCH_TERM_BREAK_ITERATOR_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string16.h"
11 #include "ui/app_list/app_list_export.h"
15 class UTF16CharIterator
;
21 // TermBreakIterator breaks terms out of a word. Terms are broken on
22 // camel case boundaries and alpha/number boundaries. Numbers are defined
25 // CamelCase -> Camel, Case
26 // Python2.7 -> Python, 2.7
27 class APP_LIST_EXPORT TermBreakIterator
{
29 // Note that |word| must out live this iterator.
30 explicit TermBreakIterator(const base::string16
& word
);
33 // Advance to the next term. Returns false if at the end of the word.
36 // Returns the current term, which is the substr of |word_| in range
38 const base::string16
GetCurrentTerm() const;
40 size_t prev() const { return prev_
; }
41 size_t pos() const { return pos_
; }
43 static const size_t npos
= static_cast<size_t>(-1);
47 STATE_START
, // Initial state
48 STATE_NUMBER
, // Current char is a number [0-9\.,].
49 STATE_UPPER
, // Current char is upper case.
50 STATE_LOWER
, // Current char is lower case.
51 STATE_CHAR
, // Current char has no case, e.g. a cjk char.
55 // Returns new state for given |ch|.
56 State
GetNewState(base::char16 ch
);
58 const base::string16
& word_
;
62 scoped_ptr
<base::i18n::UTF16CharIterator
> iter_
;
65 DISALLOW_COPY_AND_ASSIGN(TermBreakIterator
);
68 } // namespace app_list
70 #endif // UI_APP_LIST_SEARCH_TERM_BREAK_ITERATOR_H_