Dune Core Modules (unstable)

string.hh
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3
4#ifndef DUNE_GRID_IO_FILE_GMSH_UTILITY_STRING_HH
5#define DUNE_GRID_IO_FILE_GMSH_UTILITY_STRING_HH
6
7#include <algorithm>
8#include <cctype>
9#include <locale>
10#include <sstream>
11#include <string>
12
13namespace Dune::Impl::Gmsh
14{
16 inline std::string& ltrim(std::string& str)
17 {
18 auto it = std::find_if(str.begin(), str.end(), [](char ch)
19 {
20 return !std::isspace<char>(ch, std::locale::classic());
21 });
22 str.erase(str.begin() , it);
23 return str;
24 }
25
27 inline std::string& rtrim(std::string& str)
28 {
29 auto it = std::find_if(str.rbegin(), str.rend(), [](char ch)
30 {
31 return !std::isspace<char>(ch, std::locale::classic());
32 });
33 str.erase(it.base(), str.end());
34 return str;
35 }
36
38 inline std::string& trim(std::string& str)
39 {
40 return ltrim(rtrim(str));
41 }
42
43 template <class InputIter, class T, class Func>
44 void split(InputIter first, InputIter end, T const& t, Func f)
45 {
46 if (first == end)
47 return;
48
49 while (true) {
50 InputIter found = std::find(first, end, t);
51 f(first, found);
52 if (found == end)
53 break;
54 first = ++found;
55 }
56 }
57
58} // end namespace Dune::Impl::Gmsh
59
60#endif
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Nov 3, 23:36, 2025)