Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
extract_between.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/string/extract_between.cpp
3  *
4  * Part of tlx - http://panthema.net/tlx
5  *
6  * Copyright (C) 2016-2017 Timo Bingmann <[email protected]>
7  *
8  * All rights reserved. Published under the Boost Software License, Version 1.0
9  ******************************************************************************/
10 
12 
13 #include <cstring>
14 
15 namespace tlx {
16 
17 template <typename Separator1, typename Separator2>
18 static inline
20  const std::string& str, const Separator1& sep1, size_t sep1_size,
21  const Separator2& sep2) {
22 
23  std::string::size_type start = str.find(sep1);
24  if (start == std::string::npos)
25  return std::string();
26 
27  start += sep1_size;
28 
29  std::string::size_type limit = str.find(sep2, start);
30 
31  if (limit == std::string::npos)
32  return std::string();
33 
34  return str.substr(start, limit - start);
35 }
36 
37 std::string extract_between(const std::string& str, const char* sep1,
38  const char* sep2) {
39  return extract_between_template(str, sep1, strlen(sep1), sep2);
40 }
41 
42 std::string extract_between(const std::string& str, const char* sep1,
43  const std::string& sep2) {
44  return extract_between_template(str, sep1, strlen(sep1), sep2);
45 }
46 
48  const char* sep2) {
49  return extract_between_template(str, sep1, sep1.size(), sep2);
50 }
51 
53  const std::string& sep2) {
54  return extract_between_template(str, sep1, sep1.size(), sep2);
55 }
56 
57 } // namespace tlx
58 
59 /******************************************************************************/
std::string extract_between(const std::string &str, const char *sep1, const char *sep2)
Search the string for given start and end separators and extract all characters between the both...
static std::string extract_between_template(const std::string &str, const Separator1 &sep1, size_t sep1_size, const Separator2 &sep2)
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
Definition: allocator.hpp:220