-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextHelper.cpp
More file actions
99 lines (76 loc) · 2.43 KB
/
Copy pathTextHelper.cpp
File metadata and controls
99 lines (76 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "TextHelper.h"
#include <algorithm>
#include <iostream>
#include <sstream>
namespace TextHelper{
std::vector<std::string> get_lines(const std::string& str){
return split(str, '\n');
}
bool does_contain(const std::string& str, const std::string& p){
return str.find(p) != std::string::npos ;
}
bool does_contain(const std::vector<std::string>& lines, const std::string& p){
for(auto& line : lines){
if(does_contain(line, p))
return true;
}
return false;
}
std::string get_tag(const std::string& str){
auto semi = str.find(':');
if(semi != std::string::npos)
return std::string(str.begin(), str.begin() + semi);
return std::string();
}
std::vector<std::string> get_tags(const std::vector<std::string>& lines){
std::vector<std::string> tags;
for(auto& line : lines){
auto tag = get_tag(line);
if(tag != std::string(""))
tags.push_back(tag);
}
return tags;
}
std::string get_tag_value(const std::string& str, const std::string& tag){
auto pos = str.find(tag);
if(pos != std::string::npos){
auto semi = str.find(':', pos);
if(semi != std::string::npos)
return std::string(str.begin() + semi + 1, str.end());
}
return std::string();
}
std::string get_tag_value(const std::vector<std::string>& lines, const std::string& tag){
std::string value;
for(auto& line : lines){
value = get_tag_value(line, tag);
if(value != std::string(""))
return value;
}
return std::string();
}
std::vector<std::string> split(const std::string& s, char delimiter)
{
std::vector<std::string> tokens;
std::string token;
std::istringstream tokenStream(s);
while (std::getline(tokenStream, token, delimiter)){
tokens.push_back(token);
}
return tokens;
}
std::string merge(const std::vector<std::string>& strs){
std::string str;
for(auto& s : strs){
str += s;
}
return str;
}
std::string merge_newline(const std::vector<std::string>& strs){
std::string str;
for(auto& s : strs){
str += s + std::string("\n");
}
return str;
}
}