forked from wumuzhou/FootballBettingAna
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.h
More file actions
104 lines (93 loc) · 2.61 KB
/
utils.h
File metadata and controls
104 lines (93 loc) · 2.61 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
100
101
102
103
104
//
// Created by wmz on 9/5/18.
//
#ifndef TEMP3_CPP_FOR_REDIS_THUTILS_H
#define TEMP3_CPP_FOR_REDIS_THUTILS_H
#include <algorithm>
#include <exception>
#include <fstream>
#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <boost/algorithm/string.hpp>
#include <boost/regex.hpp>
#include "boost/lexical_cast.hpp"
#include <boost/uuid/uuid.hpp> // uuid class
#include <boost/uuid/uuid_generators.hpp> // generators
#include <boost/uuid/uuid_io.hpp> // streaming operators etc.
using namespace std;
using boost::lexical_cast;
using boost::bad_lexical_cast;
namespace Common {
static inline int str2int(std::string des) {
int i = 0;
try {
i = lexical_cast<int>(des);
}
catch (bad_lexical_cast &)
{
i = 0;
}
return i;
}
static inline double str2double(std::string des) {
double i = 0;
try {
boost::algorithm::replace_all(des, "\r", "");
i = lexical_cast<double>(des);
}
catch (bad_lexical_cast &)
{
i = 0.0;
cout<<"bad_lexical_cast Error===>"<<des<<endl;
throw ;
}
return i;
}
static inline string GetUuid() {
boost::uuids::uuid uuid = boost::uuids::random_generator()();
std::string UuidStr = boost::uuids::to_string(uuid);
return UuidStr;
}
static inline void
SplitString(const std::string &str, const std::string &delimiter, std::vector<std::string> &GetVec) {
boost::algorithm::split(GetVec, str, boost::algorithm::is_any_of(delimiter));
}
// static inline std::string int2str(int v) {
// std::stringstream ss;
// ss << v;
// return ss.str();
// }
static inline string doubleToString_2_decimal(double num) {
char str[256];
// sprintf(str, "%lf", num);
sprintf(str, "%.2f", num);
string result = str;
return result;
}
static inline string doubleTostr(double des) {
string res;
try {
res = lexical_cast<string>(des);
}
catch (bad_lexical_cast &)
{
res = "";
}
return res;
}
static inline std::string intTostr(int des) {
std::string res;
try {
res = lexical_cast<std::string>(des);
}
catch (bad_lexical_cast &)
{
res = "";
}
return res;
}
}
#endif //TEMP3_CPP_FOR_REDIS_THUTILS_H