OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/browser/chromeos/drive/search_metadata.h" | 5 #include "chrome/browser/chromeos/drive/search_metadata.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <queue> | 8 #include <queue> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 } | 311 } |
312 | 312 |
313 bool FindAndHighlight( | 313 bool FindAndHighlight( |
314 const std::string& text, | 314 const std::string& text, |
315 base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents* query, | 315 base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents* query, |
316 std::string* highlighted_text) { | 316 std::string* highlighted_text) { |
317 DCHECK(query); | 317 DCHECK(query); |
318 DCHECK(highlighted_text); | 318 DCHECK(highlighted_text); |
319 highlighted_text->clear(); | 319 highlighted_text->clear(); |
320 | 320 |
321 string16 text16 = base::UTF8ToUTF16(text); | 321 base::string16 text16 = base::UTF8ToUTF16(text); |
322 size_t match_start = 0; | 322 size_t match_start = 0; |
323 size_t match_length = 0; | 323 size_t match_length = 0; |
324 if (!query->Search(text16, &match_start, &match_length)) | 324 if (!query->Search(text16, &match_start, &match_length)) |
325 return false; | 325 return false; |
326 | 326 |
327 string16 pre = text16.substr(0, match_start); | 327 base::string16 pre = text16.substr(0, match_start); |
328 string16 match = text16.substr(match_start, match_length); | 328 base::string16 match = text16.substr(match_start, match_length); |
329 string16 post = text16.substr(match_start + match_length); | 329 base::string16 post = text16.substr(match_start + match_length); |
330 highlighted_text->append(net::EscapeForHTML(base::UTF16ToUTF8(pre))); | 330 highlighted_text->append(net::EscapeForHTML(base::UTF16ToUTF8(pre))); |
331 highlighted_text->append("<b>"); | 331 highlighted_text->append("<b>"); |
332 highlighted_text->append(net::EscapeForHTML(base::UTF16ToUTF8(match))); | 332 highlighted_text->append(net::EscapeForHTML(base::UTF16ToUTF8(match))); |
333 highlighted_text->append("</b>"); | 333 highlighted_text->append("</b>"); |
334 highlighted_text->append(net::EscapeForHTML(base::UTF16ToUTF8(post))); | 334 highlighted_text->append(net::EscapeForHTML(base::UTF16ToUTF8(post))); |
335 return true; | 335 return true; |
336 } | 336 } |
337 | 337 |
338 } // namespace internal | 338 } // namespace internal |
339 } // namespace drive | 339 } // namespace drive |
OLD | NEW |