Skip to content

Commit

Permalink
fable: Add ends_with and starts_with helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cassava committed Apr 22, 2024
1 parent df5f761 commit 5e95143
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fable/include/fable/utility/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,23 @@
* \see fable/utility/string.cpp
*/

#pragma once

#include <string> // for string
#include <string_view> // for string_view
#include <vector> // for vector<>

namespace fable {

inline bool starts_with(std::string_view s, std::string_view prefix) {
return s.size() >= prefix.size() && s.compare(0, prefix.size(), prefix) == 0;
}

inline bool ends_with(std::string_view s, std::string_view suffix) {
return s.size() >= suffix.size() &&
s.compare(s.size() - suffix.size(), std::string::npos, suffix) == 0;
}

std::string join_vector(const std::vector<std::string>& v, std::string_view sep);

/**
Expand Down

0 comments on commit 5e95143

Please sign in to comment.