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
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_CHROMEOS_DRIVE_SEARCH_METADATA_H_
6#define CHROME_BROWSER_CHROMEOS_DRIVE_SEARCH_METADATA_H_
7
8#include <string>
9
10#include "chrome/browser/chromeos/drive/file_system_interface.h"
11
12namespace base {
13namespace i18n {
14class FixedPatternStringSearchIgnoringCaseAndAccents;
15}  // namespace i18n
16}  // namespace base
17
18namespace drive {
19namespace internal {
20
21class ResourceMetadata;
22
23// Searches the local resource metadata, and returns the entries
24// |at_most_num_matches| that contain |query| in their base names. Search is
25// done in a case-insensitive fashion. The eligible entries are selected based
26// on the given |options|, which is a bit-wise OR of SearchMetadataOptions.
27// |callback| must not be null. Must be called on UI thread. Empty |query|
28// matches any base name. i.e. returns everything. |blocking_task_runner| must
29// be the same one as |resource_metadata| uses.
30void SearchMetadata(
31    scoped_refptr<base::SequencedTaskRunner> blocking_task_runner,
32    ResourceMetadata* resource_metadata,
33    const std::string& query,
34    int search_options,
35    int at_most_num_matches,
36    const SearchMetadataCallback& callback);
37
38// Finds |query| in |text| while ignoring cases or accents. Cases of non-ASCII
39// characters are also ignored; they are compared in the 'Primary Level' of
40// http://userguide.icu-project.org/collation/concepts.
41// Returns true if |query| is found. |highlighted_text| will have the original
42// text with matched portions highlighted with <b> tag (only the first match
43// is highlighted). Meta characters are escaped like &lt;. The original
44// contents of |highlighted_text| will be lost.
45bool FindAndHighlight(
46    const std::string& text,
47    base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents* query,
48    std::string* highlighted_text);
49
50}  // namespace internal
51}  // namespace drive
52
53#endif  // CHROME_BROWSER_CHROMEOS_DRIVE_SEARCH_METADATA_H_
54