Maipa's Standard Library Extension 1.5.6
mstd
Loading...
Searching...
No Matches
strmods.hpp
1/*
2 * mstd - Maipa's Standard Library
3 *
4 * Licensed under the BSD 3-Clause License with Attribution Requirement.
5 * See the LICENSE file for details: https://github.com/MAIPA01/mstd/blob/main/LICENSE
6 *
7 * Copyright (c) 2025, Patryk Antosik (MAIPA01)
8 */
9
10#pragma once
11#ifndef _MSTD_STRMODS_HPP_
12 #define _MSTD_STRMODS_HPP_
13
14 #include <mstd/config.hpp>
15
17_MSTD_WARNING("this is only available for c++17 and greater!");
18 #else
19
20 #include <mstd/string_types.hpp>
21
22namespace mstd {
23 inline std::string trim(const std::string_view str) {
25 const std::string_view::const_iterator& start =
26 std::ranges::find_if_not(str, [](const unsigned char ch) { return std::isspace(ch); });
27
28 const std::string_view::const_iterator& end =
29 std::ranges::find_if_not(str.rbegin(), str.rend(), [](const unsigned char ch) { return std::isspace(ch); }).base();
30
31 #else
32 const std::string_view::const_iterator& start =
33 std::find_if_not(str.begin(), str.end(), [](const unsigned char ch) { return std::isspace(ch); });
34
35 const std::string_view::const_iterator& end =
36 std::find_if_not(str.rbegin(), str.rend(), [](const unsigned char ch) { return std::isspace(ch); }).base();
37 #endif
38
39 return (start < end) ? std::string(start, end) : std::string();
40 }
41} // namespace mstd
42
43 #endif
44#endif
#define _MSTD_HAS_CXX17
Definition config.hpp:45
#define _MSTD_HAS_CXX20
Definition config.hpp:52
Definition arithmetic_types.hpp:23
std::string trim(const std::string_view str)
Definition strmods.hpp:23