Opera 12.15 Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WordHighlighter.h 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* -*- Mode: c++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
  2. **
  3. ** Copyright (C) 1995-2011 Opera Software ASA. All rights reserved.
  4. **
  5. ** This file is part of the Opera web browser.
  6. ** It may not be distributed under any circumstances.
  7. */
  8. #ifndef WORDHIGHLIGHTER_H
  9. #define WORDHIGHLIGHTER_H
  10. #include "modules/search_engine/Vector.h"
  11. #include "modules/search_engine/PhraseSearch.h"
  12. /**
  13. * @brief Highlight a searched phrase in a plaintext excerpt
  14. * @author Pavel Studeny <pavels@opera.com>
  15. *
  16. * Call Init with the search phrase and then AppendHighlight for each result.
  17. */
  18. class WordHighlighter : public PhraseMatcher
  19. {
  20. public:
  21. /**
  22. * initialize with a search query
  23. * @param query the same query used for searching
  24. * @param phrase_flags flags built up from PhraseFlags, controlling which phrases are matched.
  25. * Since it is meant for word highlighting, the flag FullSearch is automatically added
  26. * @return OK if there were no errors
  27. */
  28. CHECK_RESULT(OP_STATUS Init(const uni_char *query, int phrase_flags = NoPhrases | PrefixSearch))
  29. {
  30. return PhraseMatcher::Init(query, phrase_flags | FullSearch);
  31. }
  32. /**
  33. * Search the haystack for the all the words in the query
  34. * @param haystack to search
  35. * @return true if all the words are present in the haystack
  36. */
  37. BOOL ContainsWords(OpStringC& haystack) const
  38. {
  39. return Matches(haystack.CStr());
  40. }
  41. };
  42. #endif // WORDHIGHLIGHTER_H