00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <iostream>
00027 #include <sstream>
00028 #include "helper.h"
00029
00030 using namespace std;
00031
00032 HexChar::HexChar(unsigned char x) { val=x; }
00033 HexShort::HexShort(unsigned short x) { val=x; }
00034 DecLong::DecLong(unsigned long x) { val=x; }
00035
00036 ostream &operator << (ostream &os, const HexChar &h) {
00037 os << "0x";
00038 os.width(2);
00039 os.fill('0');
00040 os << hex << (unsigned int) h.val << dec ;
00041 return os;
00042 }
00043
00044 ostream &operator << (ostream &os, const HexShort &h) {
00045 os << "0x" ;
00046 os.width(4);
00047 os.fill('0');
00048 os << hex << (unsigned int) h.val << dec ;
00049 return os;
00050 }
00051
00052 ostream &operator << (ostream &os, const DecLong &h) {
00053 os.width(9);
00054 os.fill(' ');
00055 os << dec << (unsigned long) h.val << dec ;
00056 return os;
00057 }
00058
00059 std::string int2str(int i) {
00060 stringstream s;
00061 s << i;
00062 return s.str();
00063 }
00064
00065 std::string int2hex(int i) {
00066 stringstream s;
00067 s << hex << i;
00068 return s.str();
00069 }
00070
00071 std::string readline(istream &is) {
00072 std::string out;
00073 char c=0;
00074 while (!is.eof() && c!='\n') {
00075 is.read(&c, 1);
00076 if (is.gcount())
00077 out+=c;
00078 }
00079 return out;
00080 }
00081
00082 vector<std::string> split(const std::string &inp, std::string splitc) {
00083 vector<std::string> out;
00084 std::string cur;
00085 for (size_t i=0; i < inp.size(); i++) {
00086 char c=inp[i];
00087 if (splitc.find(c)==splitc.npos)
00088 cur+=c;
00089 else {
00090 if (cur.size()) {
00091 out.push_back(cur);
00092 cur="";
00093 }
00094 }
00095 }
00096 if (cur.size())
00097 out.push_back(cur);
00098 return out;
00099 }