titled_url_match.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_BOOKMARKS_BROWSER_TITLED_URL_MATCH_H_
  5. #define COMPONENTS_BOOKMARKS_BROWSER_TITLED_URL_MATCH_H_
  6. #include <stddef.h>
  7. #include <utility>
  8. #include <vector>
  9. namespace bookmarks {
  10. class TitledUrlNode;
  11. struct TitledUrlMatch {
  12. // Each MatchPosition is the [begin, end) positions of a match within a
  13. // string.
  14. using MatchPosition = std::pair<size_t, size_t>;
  15. using MatchPositions = std::vector<MatchPosition>;
  16. TitledUrlMatch();
  17. TitledUrlMatch(const TitledUrlMatch& other);
  18. ~TitledUrlMatch();
  19. // Extracts and returns the offsets from |match_positions|.
  20. static std::vector<size_t> OffsetsFromMatchPositions(
  21. const MatchPositions& match_positions);
  22. // Replaces the offsets in |match_positions| with those given in |offsets|,
  23. // deleting any which are npos, and returns the updated list of match
  24. // positions.
  25. static MatchPositions ReplaceOffsetsInMatchPositions(
  26. const MatchPositions& match_positions,
  27. const std::vector<size_t>& offsets);
  28. // The matching node of a query.
  29. const TitledUrlNode* node;
  30. // Location of the matching words in the title of the node.
  31. MatchPositions title_match_positions;
  32. // Location of the matching words in the URL of the node.
  33. MatchPositions url_match_positions;
  34. // Whether there was at least 1 match in the titles of ancestors of the node.
  35. bool has_ancestor_match;
  36. };
  37. } // namespace bookmarks
  38. #endif // COMPONENTS_BOOKMARKS_BROWSER_TITLED_URL_MATCH_H_