Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
std::vector<std::string> makewords(std::string&& s)
{
std::vector<std::string> temp;
std::string buffer;
for (char ch : s)
{
if (is_ascii_lower(ch) || is_ascii_upper(ch))
{
buffer += ch;
}
else if (!buffer.empty())
{
temp.emplace_back(std::move(buffer));
}
}
return std::move(temp);
}
std::vector<std::string> lowercase(std::vector<std::string>&& ss)
{
for (auto& s : ss)
{
for (char& ch : s)
{
if (is_ascii_upper(ch))
{
ch = ch - 'A' + 'a';
}
}
}
return std::move(ss);
}
std::vector<std::string> sort(std::vector<std::string>&& ss)
{
std::sort(ss.begin(), ss.end());
return std::move(ss);
}
std::vector<std::string> unique(std::vector<std::string>&& ss)
{
ss.resize(std::distance(ss.begin(),
std::unique(ss.begin(), ss.end())));
return std::move(ss);
}
std::vector<std::string> mismatch(const char* dic_path, std::vector<std::string>&& ss)
{
std::unordered_set<std::string> dic;
std::ifstream ifs;
ifs.open(dic_path, std::ifstream::in);
if (ifs.is_open())
{
std::string buffer;
while (std::getline(ifs, buffer))
{
dic.emplace(std::move(buffer));
}
}
if (!dic.empty())
{
auto erase_point = std::remove_if(ss.begin(), ss.end(),
[&dic](std::string& s){ return dic.find(s) != dic.end(); });
ss.erase(erase_point, ss.end());
}
return std::move(ss);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment