OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/query_parser/snippet.h" | 5 #include "components/query_parser/snippet.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include <algorithm> | 9 #include <algorithm> |
8 | 10 |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
11 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
12 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
14 #include "third_party/icu/source/common/unicode/brkiter.h" | 16 #include "third_party/icu/source/common/unicode/brkiter.h" |
15 #include "third_party/icu/source/common/unicode/utext.h" | 17 #include "third_party/icu/source/common/unicode/utext.h" |
16 #include "third_party/icu/source/common/unicode/utf8.h" | 18 #include "third_party/icu/source/common/unicode/utf8.h" |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 // that it's within a window in terms of graphemes as well. | 148 // that it's within a window in terms of graphemes as well. |
147 if (next_match_start < previous_match_end + kSnippetContext) | 149 if (next_match_start < previous_match_end + kSnippetContext) |
148 return true; | 150 return true; |
149 bi->isBoundary(static_cast<int32_t>(previous_match_end)); | 151 bi->isBoundary(static_cast<int32_t>(previous_match_end)); |
150 // An alternative to this is to call |bi->next()| at most | 152 // An alternative to this is to call |bi->next()| at most |
151 // kSnippetContext times, compare |bi->current()| with |next_match_start| | 153 // kSnippetContext times, compare |bi->current()| with |next_match_start| |
152 // after each call and return early if possible. There are other | 154 // after each call and return early if possible. There are other |
153 // heuristics to speed things up if necessary, but it's not likely that | 155 // heuristics to speed things up if necessary, but it's not likely that |
154 // we need to bother. | 156 // we need to bother. |
155 bi->next(kSnippetContext); | 157 bi->next(kSnippetContext); |
156 int64 current = bi->current(); | 158 int64_t current = bi->current(); |
157 return (next_match_start < static_cast<uint64>(current) || | 159 return (next_match_start < static_cast<uint64_t>(current) || |
158 current == icu::BreakIterator::DONE); | 160 current == icu::BreakIterator::DONE); |
159 } | 161 } |
160 | 162 |
161 } // namespace | 163 } // namespace |
162 | 164 |
163 // static | 165 // static |
164 void Snippet::ExtractMatchPositions(const std::string& offsets_str, | 166 void Snippet::ExtractMatchPositions(const std::string& offsets_str, |
165 const std::string& column_num, | 167 const std::string& column_num, |
166 MatchPositions* match_positions) { | 168 MatchPositions* match_positions) { |
167 DCHECK(match_positions); | 169 DCHECK(match_positions); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 utext_close(document_utext); | 295 utext_close(document_utext); |
294 swap(text_, snippet); | 296 swap(text_, snippet); |
295 } | 297 } |
296 | 298 |
297 void Snippet::Swap(Snippet* other) { | 299 void Snippet::Swap(Snippet* other) { |
298 text_.swap(other->text_); | 300 text_.swap(other->text_); |
299 matches_.swap(other->matches_); | 301 matches_.swap(other->matches_); |
300 } | 302 } |
301 | 303 |
302 } // namespace query_parser | 304 } // namespace query_parser |
OLD | NEW |