Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions lib/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,15 @@ std::string replaceEscapeSequences(const std::string &source) {
}


std::vector<std::string> splitString(const std::string& str, char sep)
std::vector<std::string> splitString(std::string_view str, char sep)
{
std::vector<std::string> l;

std::string::size_type pos1 = 0;
std::string::size_type pos2;
std::string_view::size_type pos1 = 0;
std::string_view::size_type pos2 = std::string_view::npos;
while (true) {
pos2 = str.find(sep, pos1);
l.push_back(str.substr(pos1, pos2 - pos1));
if (pos2 == std::string::npos)
l.emplace_back(str.substr(pos1, pos2 - pos1));
if (pos2 == std::string_view::npos)
break;
pos1 = pos2 + 1;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <type_traits>
#include <utility>
#include <vector>
#include<string_view>

struct SelectMapKeys {
template<class Pair>
Expand Down Expand Up @@ -428,7 +429,7 @@ static inline T* empty_if_null(T* p)
* @param sep The separator
* @return The list of separate strings (including empty ones). The whole input string if no separator found.
*/
CPPCHECKLIB std::vector<std::string> splitString(const std::string& str, char sep);
CPPCHECKLIB std::vector<std::string> splitString(std::string_view str, char sep);

namespace utils {
/**
Expand Down