Turi Create  4.0
string_util.hpp
1 /* Copyright © 2017 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5  */
6 
7 #ifndef TURI_STRING_UTIL_H_
8 #define TURI_STRING_UTIL_H_
9 
10 #include <string>
11 #include <sstream>
12 #include <vector>
13 
14 template<class T> std::vector<T> strip_seq_prefix(const std::vector<T>& v, const std::vector<T>& tok) {
15  std::vector<T> ret;
16  bool good = true;
17  int64_t tok_i = 0;
18  for (auto s : v) {
19  if (tok_i >= static_cast<int64_t>(tok.size())) {
20  good = false;
21  }
22  if (good) {
23  if (s != tok[tok_i]) {
24  good = false;
25  }
26  }
27  if (!good) {
28  ret.push_back(s);
29  }
30  ++tok_i;
31  }
32  return ret;
33 }
34 
35 bool starts_with(const std::string& x, const std::string& x_sub);
36 bool ends_with(const std::string& x, const std::string& x_sub);
37 bool contains(const std::string& x, const std::string& x_sub);
38 
39 bool starts_with(const std::vector<std::string>& x, const std::vector<std::string>& x_sub);
40 bool ends_with(const std::vector<std::string>& x, const std::vector<std::string>& x_sub);
41 
42 std::vector<std::string> split(const std::string& s, const std::string& tok);
43 std::string join(const std::vector<std::string>& v, const std::string& tok);
44 std::string lstrip_all(const std::string& s, const std::string& tok);
45 std::string rstrip_all(const std::string& s, const std::string& tok);
46 std::string strip_all(const std::string& s, const std::string& tok);
47 
48 #endif
void split(S &&input, T &&output1, T &&output2, FilterFn filterfn, size_t random_seed=std::time(NULL))
Definition: algorithm.hpp:293