Dune Core Modules (2.3.1)

stringutility.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_COMMON_STRINGUTILITY_HH
4 #define DUNE_COMMON_STRINGUTILITY_HH
5 
10 #include <cstddef>
11 #include <cstring>
12 #include <algorithm>
13 
14 namespace Dune {
15 
26  template<typename C>
27  bool hasPrefix(const C& c, const char* prefix) {
28  std::size_t len = std::strlen(prefix);
29  return c.size() >= len &&
30  std::equal(prefix, prefix+len, c.begin());
31  }
32 
42  template<typename C>
43  bool hasSuffix(const C& c, const char* suffix) {
44  std::size_t len = std::strlen(suffix);
45  if(c.size() < len) return false;
46  typename C::const_iterator it = c.begin();
47  std::advance(it, c.size() - len);
48  return std::equal(suffix, suffix+len, it);
49  }
50 
53 }
54 
55 #endif // DUNE_COMMON_STRINGUTILITY_HH
bool hasSuffix(const C &c, const char *suffix)
Check whether a character container has a given suffix.
Definition: stringutility.hh:43
bool hasPrefix(const C &c, const char *prefix)
Check whether a character container has a given prefix.
Definition: stringutility.hh:27
Dune namespace.
Definition: alignment.hh:14
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 16, 22:29, 2024)