ft_irc/srcs/commands/cmd_utils.cpp
2023-03-13 16:44:47 +01:00

42 lines
1.6 KiB
C++

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cmd_utils.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/10 15:46:10 by apommier #+# #+# */
/* Updated: 2023/03/13 16:38:37 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/ft_irc.hpp"
void split(std::string const &str, const char delim, std::vector<std::string> &out)
{
size_t start;
size_t end = 0;
while ((start = str.find_first_not_of(delim, end)) != std::string::npos)
{
end = str.find(delim, start);
out.push_back(str.substr(start, end - start));
}
}
void split_but_keep(std::string const &str, const char delim, std::vector<std::string> &out)
{
size_t start;
size_t end = 0;
if (str.find_first_of(delim, end) == std::string::npos)
{
out.push_back(str);
return ;
}
while ((start = str.find_first_not_of(delim, end)) != std::string::npos)
{
end = str.find(delim, start);
out.push_back(str.substr(start, end + 1 - start));
}
}