-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmystring.h
More file actions
59 lines (45 loc) · 1.12 KB
/
mystring.h
File metadata and controls
59 lines (45 loc) · 1.12 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
//字符串操作
#if !defined(__H__MYSTRING__H__)
#define __H__MYSTRING__H__
#include <string>
#include <vector>
#include <sstream>
//将1个字符转为数字(16进制)
unsigned char atohex(char c);
//将1个字符转为数字(10进制)
unsigned char atodec(char c);
//将一个字节转为2个字符(16进制小写)
void hextoa(unsigned char h, char buf[2]);
//将一个字节转为2个字符(16进制大写)
void hextoA(unsigned char h, char buf[2]);
//分割字符串
void split(const std::string &s, const std::string &c, std::vector<std::string> &v);
//去除首尾空格
std::string &trim(std::string &s);
//URLEncode
std::string UrlEncode(const std::string &str);
//断言
void myasscrt(bool f, const char *msg = "asscrt wrong");
//校验和
uint16_t in_checksum(const void *buf, int len);
//字符串转换
template <typename S, typename D>
D mytrans(const S &s)
{
D d;
std::stringstream ss;
ss << s;
ss >> d;
return d;
}
//字符串转换
template <typename S, typename D>
D mytrans(S &&s)
{
D d;
std::stringstream ss;
ss << s;
ss >> d;
return d;
}
#endif // __H__MYSTRING__H__