浏览代码

Add C string variants of starts_with() and ends_with().

wip/core-clipp
Sam Hocevar 4 年前
父节点
当前提交
e6472db0b5
共有 1 个文件被更改,包括 14 次插入1 次删除
  1. +14
    -1
      include/lol/base/private/string.h

+ 14
- 1
include/lol/base/private/string.h 查看文件

@@ -74,7 +74,7 @@ std::vector<std::basic_string<T>> split(std::basic_string<T> const &s,
return split(s, std::basic_string<T>(seps));
}

// Check whether a string starts or ends with a given substring
// Check whether a string starts with a given substring
template<typename T>
bool starts_with(std::basic_string<T> const &s,
std::basic_string<T> const &prefix)
@@ -89,6 +89,13 @@ bool starts_with(std::basic_string<T> const &s, T const *prefix)
return starts_with(s, std::basic_string<T>(prefix));
}

template<typename T>
bool starts_with(T const *s, T const *suffix)
{
return starts_with(std::basic_string<T>(s), std::basic_string<T>(suffix));
}

// Check whether a string ends with a given substring
template<typename T>
bool ends_with(std::basic_string<T> const &s,
std::basic_string<T> const &suffix)
@@ -103,6 +110,12 @@ bool ends_with(std::basic_string<T> const &s, T const *suffix)
return ends_with(s, std::basic_string<T>(suffix));
}

template<typename T>
bool ends_with(T const *s, T const *suffix)
{
return ends_with(std::basic_string<T>(s), std::basic_string<T>(suffix));
}

// Convert a string to lowercase or uppercase
template<typename T>
std::basic_string<T> tolower(std::basic_string<T> const &s)


正在加载...
取消
保存