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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
#include <gman/bug.h>
#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
#include <cstring>
//#include <stdio.h>
#include <ctime> // use this for C++ rather than <time.h>
using namespace std;
void strallcut(char *str)
{
bug_func();
int i, j = 0;
char sp[512];
for(i = 0; *(str + i) != '\0'; i++)
{
if(*(str + i) == ' ')
continue;
sp[j++] = *(str + i);
}
sp[j] = '\0';//0same?
strcpy(str, sp);
}
std::string& trim(std::string &s, const char* str)
{
bug_func();
if(s.empty())
return s;
s.erase(0, s.find_first_not_of(str));
s.erase(s.find_last_not_of(str) + 1);
//s.erase(47); // What is this for?
return s;
}
void purehex()
{
bug_func();
ifstream ifs("sft001.txt");
ofstream ofs("sft002.txt");
string strTmp,s;
while(getline(ifs, strTmp))
{
trim(strTmp, " ");
if(!strTmp.empty()&&'/'!= strTmp.at(0))
if(string::npos!=strTmp.find("Request")||string::npos!= strTmp.find("Answer")||string::npos!= strTmp.find("Port"))
continue;
strTmp += "\n";
s += strTmp;
}
s.erase(0, 1);
ofs << s;
ifs.close();
ofs.close();
}
void combin()
{
bug_func();
string s, strT;
ifstream ifs("sft002.txt");
ofstream ofs("sft003.txt");
char strline[256];
while(ifs.getline(strline, 256))
{
strallcut(strline);
if(strline[0] == '0' && strline[1] == '2' || strline[0] == '0'
&& strline[1] == '3')
{
s += "\n";
s += strline;
}
else
s += strline;
}
s.erase(0, 1);
ofs << s;
ifs.close();
ofs.close();
}
void delesc()
{
bug_func();
string s, str;
ifstream ifs("sft003.txt");
ofstream ofs("sft004.txt");
while(getline(ifs, str))
{
int k = 0, len = str.length() / 2;
for(int i = 0; i < len; i++)
{
if(str[i * 2] == '1' && str[2 * i + 1] == 'B')//delete 1B
{
str[2 * i] = str[2 * i + 2] - 4;
str[2 * i + 1] = str[2 * i + 3];
str.erase(2 * i + 2, 2);
}
}
s += str;
s += "\n";
}
ifs.close();
ofs << s;
ofs.close();
}
int main(int argc, char* argv[])
{
bug_func();
time_t time1, time2;
time(&time1);
purehex();
cout << "purehex finished" << endl;
combin();
cout << "combin finished" << endl;
delesc();
cout << "desc finished" << endl;
time(&time2);
cout << time2 - time1 << "total time" << endl;
system("pause");
return 0;
}
|