AlexSSH

Untitled

Feb 17th, 2023
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. [[nodiscard]] SearchServer::Query SearchServer::ParseQuery(string_view text) const {
  2.     Query query;
  3.     for (const auto &word: SplitIntoWords(text)) {
  4.         const auto query_word = ParseQueryWord(string(word));
  5.         if (!query_word.is_stop) {
  6.             if (query_word.is_minus) {
  7.                 query.minus_words.insert(query_word.data);
  8.             } else {
  9.                 query.plus_words.insert(query_word.data);
  10.             }
  11.         }
  12.     }
  13.     return query;
  14. }
  15.  
  16.  
  17.  
  18. [[nodiscard]] SearchServer::QueryWord SearchServer::ParseQueryWord(string_view word) const {
  19.     bool is_minus = false;
  20.     // Word shouldn't be empty
  21.     if (word[0] == '-') {
  22.         is_minus = true;
  23.         word = word.substr(1);
  24.     }
  25.     if (word.empty() || !IsValidWord(word)) {
  26.         throw invalid_argument("Query has incorrect symbols in " + string(word) + ".");
  27.     }
  28.     if (is_minus && word[0] == '-') {
  29.         throw invalid_argument("Query has incorrect minus-words:" + string(word) + ".");
  30.     }
  31.     return {word, is_minus, IsStopWord(word)};
  32. }
Advertisement
Add Comment
Please, Sign In to add comment