Skip to content

Commit

Permalink
Merge pull request #1134 from angriman/use-string-view
Browse files Browse the repository at this point in the history
Use string_view instead of const string&.
  • Loading branch information
angriman committed Oct 15, 2023
2 parents 4e0573f + 7bd245c commit 07d02ea
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions include/networkit/auxiliary/StringTools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <algorithm>
#include <string>
#include <string_view>
#include <vector>

namespace Aux {
Expand Down Expand Up @@ -51,22 +52,22 @@ std::vector<std::string> split(Iterator begin, Iterator end, Character delim = C
/**
* Split a string at delimiter and return vector of parts.
*/
inline std::vector<std::string> split(const std::string &s, char delim = ' ') {
inline std::vector<std::string> split(std::string_view s, char delim = ' ') {
return split(s.begin(), s.end(), delim);
}

/**
* Determines whether @a str ends with @a suffix.
*/
inline bool ends_with(const std::string &str, const std::string &suffix) {
inline bool ends_with(std::string_view str, std::string_view suffix) {
return str.size() >= suffix.size()
&& str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
}

/**
* Determines whether @a str starts with @a prefix.
*/
inline bool starts_with(const std::string &str, const std::string &prefix) {
inline bool starts_with(std::string_view str, std::string_view prefix) {
return str.size() >= prefix.size() && str.compare(0, prefix.size(), prefix) == 0;
}

Expand Down

0 comments on commit 07d02ea

Please sign in to comment.