OGLplus  (0.59.0) a C++ wrapper for rendering APIs

string_algo.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_STRING_ALGO_HPP
10 #define EAGINE_STRING_ALGO_HPP
11 
12 #include "string_span.hpp"
13 
14 namespace eagine {
15 //------------------------------------------------------------------------------
18 template <
19  typename C,
20  typename T,
21  typename A,
22  typename P1,
23  typename P2,
24  typename S1,
25  typename S2>
27  std::basic_string<C, T, A>& str,
29  memory::basic_span<const C, P2, S2> to) -> std::basic_string<C, T, A>& {
30  std::string::size_type index = 0;
31  while(true) {
32  index = str.find(from.data(), index, from.size());
33  if(index == std::string::npos) {
34  break;
35  }
36  str.replace(index, from.size(), to.data(), to.size());
37  index += to.size();
38  }
39  return str;
40 }
41 //------------------------------------------------------------------------------
44 template <
45  typename C,
46  typename T,
47  typename A,
48  typename P1,
49  typename P2,
50  typename S1,
51  typename S2>
53  std::basic_string<C, T, A>& str,
54  span<const std::tuple<
56  basic_string_span<const C, P2, S2>>> dict) -> std::basic_string<C, T, A>& {
57  for(auto& [from, to] : dict) {
58  string_replace(str, from, to);
59  }
60  return str;
61 }
62 //------------------------------------------------------------------------------
63 } // namespace eagine
64 
65 #endif // EAGINE_STRING_ALGO_HPP
Common code is placed in this namespace.
Definition: eagine.hpp:21
basic_span< T, T *, S > span
Default alias for basic memory spans with native pointer type.
Definition: span.hpp:415
Specialization of memory::basic_span for character string containers.
Definition: string_span.hpp:25
Non-owning view of a contiguous range of memory with ValueType elements.
Definition: flatten_fwd.hpp:16
auto string_replace(std::basic_string< C, T, A > &str, memory::basic_span< const C, P1, S1 > from, memory::basic_span< const C, P2, S2 > to) -> std::basic_string< C, T, A > &
Replaces all occurrences of from with to in the given string.
Definition: string_algo.hpp:26

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).