-
Notifications
You must be signed in to change notification settings - Fork 6
/
utils.h
77 lines (60 loc) · 1.5 KB
/
utils.h
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
#ifndef __UTILS__
#define __UTILS__
#include <string>
using namespace std;
#include "headers.h"
void stop( const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
vprintf (fmt, args);
va_end(args);
exit(-1);
}
//void stop(char* msg)
//{
//}
void to_upper(string &str)
{
for(int i=0; i<str.size(); i++){
if(str[i]>='a' && str[i]<='z') str[i]+='A'-'a';
}
}
void to_upper(char* str, int len)
{
for(int i=0; i<len; i++){
if(str[i]>='a' && str[i]<='z') str[i]+='A'-'a';
}
}
int split_string(const string &str, vector<string> &vec_str, string separator)
{
if(str.empty()) return 0;
vec_str.clear();
int i=0;
bool look=false;
string str_buf;
string symbol_pool="`1234567890-=~!@#$%^&*()_+qwertyuiop[]\\asdfghjkl;'zxcvbnm,./QWERTYUIOP{}|ASDFGHJKL:\"ZXCVBNM<>? \t\n";
string::size_type pos;
for(i=0; i<separator.size(); i++){
pos=symbol_pool.find(separator[i]);
if( pos!=string::npos ) symbol_pool.erase(symbol_pool.begin()+pos);
}
for(i=0; i<str.size(); i++){
if( symbol_pool.find(str[i])!=string::npos )
{
if(!look) look=true;
str_buf += str[i];
}
else
{
if(look){
look=false;
vec_str.push_back(str_buf);
str_buf.erase(str_buf.begin(), str_buf.end());
}
}
}
if(look) vec_str.push_back(str_buf);
return (int)vec_str.size();
}
#endif //__UTILS__