fix(string) Trim error
Some checks failed
android / build (push) Waiting to run
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (Debug) (push) Waiting to run
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (Release) (push) Waiting to run
linux-arm-gcc / linux-gcc-arm (Debug) (push) Waiting to run
linux-arm-gcc / linux-gcc-arm (Release) (push) Waiting to run
linux-arm-gcc / linux-gcc-armhf (Debug) (push) Waiting to run
linux-arm-gcc / linux-gcc-armhf (Release) (push) Waiting to run
linux-mips-gcc / linux-gcc-mipsel (Debug) (push) Waiting to run
linux-mips-gcc / linux-gcc-mipsel (Release) (push) Waiting to run
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Waiting to run
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Waiting to run
linux-riscv64-gcc / linux-gcc-riscv64 (Debug) (push) Waiting to run
linux-riscv64-gcc / linux-gcc-riscv64 (Release) (push) Waiting to run
linux-x64-clang / linux-clang (Debug) (push) Waiting to run
linux-x64-clang / linux-clang (Release) (push) Waiting to run
linux-x64-gcc / linux-gcc (Debug) (push) Waiting to run
linux-x64-gcc / linux-gcc (Release) (push) Waiting to run
linux-x86-gcc / linux-gcc (Debug) (push) Waiting to run
linux-x86-gcc / linux-gcc (Release) (push) Waiting to run
android / build (pull_request) Failing after 5s
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (Debug) (pull_request) Failing after 4s
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (Release) (pull_request) Failing after 5s
linux-arm-gcc / linux-gcc-arm (Debug) (pull_request) Failing after 5s
linux-arm-gcc / linux-gcc-arm (Release) (pull_request) Failing after 4s
linux-arm-gcc / linux-gcc-armhf (Debug) (pull_request) Failing after 9s
linux-arm-gcc / linux-gcc-armhf (Release) (pull_request) Failing after 9s
linux-mips-gcc / linux-gcc-mipsel (Debug) (pull_request) Failing after 4s
linux-mips-gcc / linux-gcc-mipsel (Release) (pull_request) Failing after 5s
linux-mips64-gcc / linux-gcc-mips64el (Debug) (pull_request) Failing after 5s
linux-mips64-gcc / linux-gcc-mips64el (Release) (pull_request) Failing after 5s
linux-x64-clang / linux-clang (Debug) (pull_request) Failing after 11s
linux-x64-clang / linux-clang (Release) (pull_request) Failing after 7s
linux-x64-gcc / linux-gcc (Debug) (pull_request) Failing after 5s
linux-x64-gcc / linux-gcc (Release) (pull_request) Failing after 6s
linux-x86-gcc / linux-gcc (Debug) (pull_request) Failing after 5s
linux-riscv64-gcc / linux-gcc-riscv64 (Debug) (pull_request) Failing after 14m20s
linux-riscv64-gcc / linux-gcc-riscv64 (Release) (pull_request) Failing after 14m15s
linux-x86-gcc / linux-gcc (Release) (pull_request) Failing after 13m29s

This commit is contained in:
tqcq 2024-09-30 10:05:50 +08:00
parent eda5a20286
commit 729ee8b86c
3 changed files with 29 additions and 28 deletions

View File

@ -75,11 +75,11 @@ include(cmake/BuildInfo.cmake)
check_symbol_exists("getifaddrs" "ifaddrs.h" TILE_HAVE_GETIFADDRS) check_symbol_exists("getifaddrs" "ifaddrs.h" TILE_HAVE_GETIFADDRS)
check_symbol_exists("freeifaddrs" "ifaddrs.h" TILE_HAVE_FREEIFADDRS) check_symbol_exists("freeifaddrs" "ifaddrs.h" TILE_HAVE_FREEIFADDRS)
find_package(Git REQUIRED) # find_package(Git REQUIRED)
#
get_git_commit_hash(GIT_COMMIT_HASH) # get_git_commit_hash(GIT_COMMIT_HASH)
get_git_commit_date(GIT_COMMIT_DATE) # get_git_commit_date(GIT_COMMIT_DATE)
get_git_commit_subject(GIT_COMMIT_SUBJECT) # get_git_commit_subject(GIT_COMMIT_SUBJECT)
set(THIRD_PARTY_INCLUDE_DIRS set(THIRD_PARTY_INCLUDE_DIRS
# "third_party/json" "third_party/inja" # "third_party/json" "third_party/inja"

View File

@ -139,26 +139,6 @@ Trim(Slice s, Slice cutset)
return Trim(s, [&cutset](char c) { return cutset.find(Slice(&c, 1)) != Slice::npos; }); return Trim(s, [&cutset](char c) { return cutset.find(Slice(&c, 1)) != Slice::npos; });
} }
Slice
TrimLeft(Slice s, std::function<bool(char)> pred)
{
while (!s.empty() && pred(s[0])) { s.RemovePrefix(1); }
return s;
}
Slice
TrimRight(Slice s, std::function<bool(char)> pred)
{
while (!s.empty() && pred(s[s.size() - 1])) { s.RemoveSuffix(1); }
return s;
}
Slice
Trim(Slice s, std::function<bool(char)> pred)
{
return TrimRight(TrimLeft(s, pred), pred);
}
template<typename T> template<typename T>
void void
JoinImpl(const T &parts, Slice delim, std::string *result) JoinImpl(const T &parts, Slice delim, std::string *result)

View File

@ -8,6 +8,7 @@
#include "tile/base/optional.h" #include "tile/base/optional.h"
#include "tile/base/slice.h" #include "tile/base/slice.h"
#include <cctype>
#include <limits> #include <limits>
#include <string> #include <string>
#include <vector> #include <vector>
@ -41,9 +42,29 @@ std::string Replace(Slice str, Slice from, Slice to, std::size_t count = std::nu
Slice TrimLeft(Slice s, Slice cutset); Slice TrimLeft(Slice s, Slice cutset);
Slice TrimRight(Slice s, Slice cutset); Slice TrimRight(Slice s, Slice cutset);
Slice Trim(Slice s, Slice cutset); Slice Trim(Slice s, Slice cutset);
Slice TrimLeft(Slice s, std::function<bool(char)> pred = isspace);
Slice TrimRight(Slice s, std::function<bool(char)> pred = isspace); template<typename Pred = decltype(isspace)>
Slice Trim(Slice s, std::function<bool(char)> pred = isspace); Slice
TrimLeft(Slice s, Pred pred = isspace)
{
while (!s.empty() && pred(s[0])) { s.RemovePrefix(1); }
return s;
}
template<typename Pred = decltype(isspace)>
Slice
TrimRight(Slice s, Pred pred = isspace)
{
while (!s.empty() && pred(s[s.size() - 1])) { s.RemoveSuffix(1); }
return s;
}
template<typename Pred = decltype(isspace)>
Slice
Trim(Slice s, Pred pred = isspace)
{
return TrimRight(TrimLeft(s, pred), pred);
}
std::vector<Slice> Split(Slice s, std::vector<Slice> Split(Slice s,
char delim, char delim,