forked from whitefield-framework/whitefield
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.cc
60 lines (51 loc) · 1.05 KB
/
common.cc
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
/*
* Copyright (C) 2017 Rahul Jadhav <[email protected]>
*
* This file is subject to the terms and conditions of the GNU
* General Public License v2. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup airline
* @{
*
* @file
* @brief Common/utility APIs for Airline
*
* @author Rahul Jadhav <[email protected]>
*
* @}
*/
#define _COMMON_CC_
#include <common.h>
// trim from left
string& ltrim(string& s, const char* t)
{
s.erase(0, s.find_first_not_of(t));
return s;
}
// trim from right
string& rtrim(string& s, const char* t)
{
s.erase(s.find_last_not_of(t) + 1);
return s;
}
// trim from left & right
string& trim(string& s, const char* t)
{
return ltrim(rtrim(s, t), t);
}
template<typename Out>
void split(const string &s, char delim, Out result) {
stringstream ss;
ss.str(s);
string item;
while (getline(ss, item, delim)) {
*(result++) = item;
}
}
vector<string> split(const string &s, char delim) {
vector<string> elems;
split(s, delim, back_inserter(elems));
return elems;
}