Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // вот поле стоп-слов
- const std::set<std::string_view> stop_words_; // все стоп-слова
- // вот разбивающая функция
- std::vector<std::string_view> SplitIntoWordsView(std::string_view str) {
- std::vector<std::string_view> result;
- str.remove_prefix(std::min(str.find_first_not_of(' '), str.size()));
- std::string_view word = str.substr(0, str.find_first_of(' '));
- while (word.size()) {
- result.push_back(word);
- str.remove_prefix(word.size());
- str.remove_prefix(std::min(str.find_first_not_of(' '), str.size()));
- word = str.substr(0, str.find_first_of(' '));
- }
- return result;
- }
- // вызывается конструктор на основе string_view
- SearchServer::SearchServer(std::string_view stop_words_text) : SearchServer(SplitIntoWordsView(stop_words_text)) {}
- // он передаст контейнер vector<string_view> в своем списке инициализации в другой конструктор
- // этот другой конструктор на основе контейнера стоп-слов проинициализирует поле set<string_view> stop_words_
- template<typename StringContainer>
- SearchServer::SearchServer(const StringContainer& stop_words) : stop_words_(MakeSetStopWords(stop_words)) {
- for (const std::string_view word : stop_words_) {
- ThrowSpecialSymbolInText(word);
- // all_words_in_search_server_.push_back(std::static_cast<std::string>(word));
- }
- }
- // в функции MakeSetStopWords у меня проблема -- "invalid conversion from 'char' to 'const char*' [-fpermissive]"
- template <typename StringContainer>
- std::set<std::string_view> MakeSetStopWords(const StringContainer& strings) {
- std::set<std::string_view> non_empty_strings;
- for (std::string_view str : strings) {
- if (!str.empty()) {
- non_empty_strings.insert(str);
- }
- }
- return non_empty_strings;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement