Advertisement
giGii

проблем

Dec 21st, 2022 (edited)
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.01 KB | None | 0 0
  1. // вот поле стоп-слов
  2. const std::set<std::string_view> stop_words_; // все стоп-слова
  3.  
  4. // вот разбивающая функция
  5.  
  6. std::vector<std::string_view> SplitIntoWordsView(std::string_view str) {
  7.     std::vector<std::string_view> result;
  8.  
  9.     str.remove_prefix(std::min(str.find_first_not_of(' '), str.size()));
  10.     std::string_view word = str.substr(0, str.find_first_of(' '));
  11.  
  12.     while (word.size()) {
  13.         result.push_back(word);
  14.         str.remove_prefix(word.size());
  15.         str.remove_prefix(std::min(str.find_first_not_of(' '), str.size()));
  16.         word = str.substr(0, str.find_first_of(' '));
  17.     }
  18.  
  19.     return result;
  20. }
  21.  
  22. // вызывается конструктор на основе string_view
  23. SearchServer::SearchServer(std::string_view stop_words_text) : SearchServer(SplitIntoWordsView(stop_words_text)) {}
  24.  
  25. // он передаст контейнер vector<string_view> в своем списке инициализации в другой конструктор
  26. // этот другой конструктор на основе контейнера стоп-слов проинициализирует поле set<string_view> stop_words_
  27.  
  28. template<typename StringContainer>
  29. SearchServer::SearchServer(const StringContainer& stop_words) : stop_words_(MakeSetStopWords(stop_words)) {
  30.     for (const std::string_view word : stop_words_) {
  31.         ThrowSpecialSymbolInText(word);
  32.         // all_words_in_search_server_.push_back(std::static_cast<std::string>(word));
  33.     }
  34. }
  35.  
  36. // в функции MakeSetStopWords у меня проблема -- "invalid conversion from 'char' to 'const char*' [-fpermissive]"
  37. template <typename StringContainer>
  38. std::set<std::string_view> MakeSetStopWords(const StringContainer& strings) {
  39.     std::set<std::string_view> non_empty_strings;
  40.     for (std::string_view str : strings) {
  41.         if (!str.empty()) {
  42.             non_empty_strings.insert(str);
  43.         }
  44.     }
  45.    
  46.     return non_empty_strings;
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement