-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhelpers.cpp
More file actions
52 lines (46 loc) · 899 Bytes
/
helpers.cpp
File metadata and controls
52 lines (46 loc) · 899 Bytes
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
/*
* helpers.cpp
*
* Created on: May 4, 2012
* Author: randy
*/
#include "helpers.h"
#include <vector>
#include <boost/algorithm/string/trim.hpp>
#include <boost/lexical_cast.hpp>
using namespace std;
string int2str(int value){
char t[256];
sprintf(t, "%d", value);
string s = t;
return s;
}
int extractCode(char* buf){
string content = buf;
return extractCode(content);
}
int extractCode(string msg){
vector<int> code;
boost::trim(msg);
const char* m = msg.c_str();
for (unsigned int i = 0; i < msg.size(); i++){
if (m[i] <= 57 && m[i] >= 48){
code.push_back(m[i] - 48);
}else{
break;
}
}
int temp = 1;
int count = 0;
for (int i = code.size() - 1; i >= 0; i--){
count += temp * code[i];
temp *= 10;
}
return count;
}
extern string generateMsg(int code, string content)
{
string c= boost::lexical_cast<string>(code);
c = c + content;
return c;
}