lsst.gauss2d gbf99507273+b0138be388
 
Loading...
Searching...
No Matches
string_utils.h
1#ifndef LSST_GAUSS2D_STRING_UTILS_H
2#define LSST_GAUSS2D_STRING_UTILS_H
3
4#include <algorithm>
5#include <memory>
6#include <set>
7#include <sstream>
8#include <stdexcept>
9#include <string>
10#include <vector>
11
12namespace lsst::gauss2d {
13
22template <typename T, typename R>
23std::string replace_all(std::string target, T token, R replacement) {
24 auto pos = target.find(token, 0);
25 const auto n_token = token.size();
26 const auto n_replace = replacement.size();
27 while (pos != std::string::npos) {
28 target.replace(pos, n_token, replacement);
29 pos += n_replace;
30 pos = target.find(token, pos);
31 }
32 return target;
33}
34
42template <typename T>
43std::string replace_all_none(std::string target, T token) {
44 auto pos = target.find(token, 0);
45 const auto n_token = token.size();
46 while (pos != std::string::npos) {
47 target.replace(pos, n_token, "");
48 pos = target.find(token, pos);
49 }
50 return target;
51}
52
53template std::string replace_all<const std::string, const std::string>(std::string target,
54 const std::string token,
55 const std::string replacement);
56template std::string replace_all<std::string_view, const std::string>(std::string target,
57 std::string_view token,
58 const std::string replacement);
59template std::string replace_all<const std::string, std::string_view>(std::string target,
60 const std::string token,
61 std::string_view replacement);
62template std::string replace_all<std::string_view, std::string_view>(std::string target,
63 std::string_view token,
64 std::string_view replacement);
65
66template std::string replace_all_none<const std::string>(std::string target, const std::string token);
67template std::string replace_all_none<std::string_view>(std::string target, std::string_view token);
68} // namespace lsst::gauss2d
69
70#endif