1#pragma once
2
3#include <algorithm>
4#include <memory>
5#include <string>
6#include <vector>
7
8#include <c10/macros/Export.h>
9
10namespace caffe2 {
11
12TORCH_API std::vector<std::string>
13split(char separator, const std::string& string, bool ignore_empty = false);
14
15TORCH_API std::string trim(const std::string& str);
16
17TORCH_API size_t editDistance(
18 const std::string& s1,
19 const std::string& s2,
20 size_t max_distance = 0);
21
22TORCH_API inline bool StartsWith(
23 const std::string& str,
24 const std::string& prefix) {
25 return str.length() >= prefix.length() &&
26 std::mismatch(prefix.begin(), prefix.end(), str.begin()).first ==
27 prefix.end();
28}
29
30TORCH_API inline bool EndsWith(
31 const std::string& full,
32 const std::string& ending) {
33 if (full.length() >= ending.length()) {
34 return (
35 0 ==
36 full.compare(full.length() - ending.length(), ending.length(), ending));
37 } else {
38 return false;
39 }
40}
41
42TORCH_API int32_t editDistanceHelper(
43 const char* s1,
44 size_t s1_len,
45 const char* s2,
46 size_t s2_len,
47 std::vector<size_t>& current,
48 std::vector<size_t>& previous,
49 std::vector<size_t>& previous1,
50 size_t max_distance);
51} // namespace caffe2
52