codex
Loading...
Searching...
No Matches
string.hpp
Go to the documentation of this file.
1#ifndef CODEX_STRING_STRING_H
2#define CODEX_STRING_STRING_H
3
4#include <cstring>
5#include <string_view>
6
7namespace codex {
8
9inline std::string_view remove_prefix_tern(
10 std::string_view s, std::string_view p
11) {
12 return s.substr(s.starts_with(p) ? p.size() : 0);
13}
14
15inline std::string_view remove_prefix_mul(
16 std::string_view s, std::string_view p
17) {
18 return s.substr(s.starts_with(p) * p.size());
19}
20
21inline std::string_view remove_prefix_c(
22 std::string_view s, std::string_view p
23) {
24 return s.substr(
25 (!p.empty() && std::memcmp(s.data(), p.data(), p.size()) == 0)
26 ? p.size() : 0);
27}
28
29inline std::string_view remove_prefix_c_strncmp(
30 std::string_view s, std::string_view p
31) {
32 const char *const t = (std::strncmp(s.data(), p.data(), p.size()) == 0)
33 ? s.data() + p.size() : s.data();
34 return {t, &*end(s)};
35}
36
37}
38
39#endif
Definition rotate.hpp:6
std::string_view remove_prefix_tern(std::string_view s, std::string_view p)
Definition string.hpp:9
std::string_view remove_prefix_mul(std::string_view s, std::string_view p)
Definition string.hpp:15
std::string_view remove_prefix_c_strncmp(std::string_view s, std::string_view p)
Definition string.hpp:29
std::string_view remove_prefix_c(std::string_view s, std::string_view p)
Definition string.hpp:21
#define p()
Definition std2.c:11
#define t(a)
Definition std2.c:10
constexpr const char * data(void) const
Definition utils.hpp:18
constexpr std::size_t size(void) const
Definition utils.hpp:17
constexpr fixed_string s
Definition test.cpp:6