Files Classes Functions Hierarchy
00001 #include <fstream> 00002 using namespace std; 00003 00004 #include <stringconvert.h> 00005 #include <stringserialization.h> 00006 00007 string htmlstring::lessthan = "<"; 00008 string htmlstring::greaterthan = ">"; 00009 string htmlstring::amp = "&"; 00010 string htmlstring::quot = """; 00011 00012 00013 boolc filestring::serializeInverse(stringc & filename, stringc & str) 00014 { 00015 return deserialize(filename,str); 00016 } 00017 00018 00019 00020 boolc filestring::serialize(string & str, stringc & filename) 00021 { 00022 str.clear(); 00023 ifstream file(filename.c_str()); 00024 if (!file) 00025 return false; 00026 00027 char c; 00028 while (file.get(c)) 00029 str.push_back(c); 00030 00031 //assert(str.empty()==false);// Make sure the file is not empty. This may be unreasonable. 00032 00033 return true; 00034 } 00035 00036 boolc filestring::deserialize 00037 ( 00038 stringc & filename, 00039 stringc & str 00040 ) 00041 { 00042 ofstream file(filename.c_str()); 00043 if (!file) 00044 return false; 00045 00046 file << str; 00047 00048 return true; 00049 } 00050 00051 00052 boolc htmlstring::serialize(string & str, stringc & html ) 00053 { 00054 str=html; 00055 string& s2(str); 00056 00057 stringconvert::findandreplace(s2,lessthan,"<"); 00058 stringconvert::findandreplace(s2,greaterthan,">"); 00059 stringconvert::findandreplace(s2,amp,"&"); 00060 stringconvert::findandreplace(s2,quot,"\""); 00061 00062 return true; 00063 } 00064 00065 boolc htmlstring::serializeInverse(string & html, stringc & str ) 00066 { 00067 html = str; 00068 stringconvert::findandreplace(html,"&",amp); 00069 stringconvert::findandreplace(html,"<",lessthan); 00070 stringconvert::findandreplace(html,">",greaterthan); 00071 stringconvert::findandreplace(html,"\"",quot); 00072 00073 return true; 00074 } 00075 00076 00077 boolc htmlstring::ishtml(stringc & str) 00078 { 00079 string s2(str); 00080 string find; 00081 00082 find=lessthan; 00083 00084 vector<string> vs; 00085 vs.push_back(lessthan); 00086 vs.push_back(greaterthan); 00087 vs.push_back(amp); 00088 vs.push_back(quot); 00089 00090 for (uint i=0; i<vs.size(); ++i) 00091 { 00092 find=vs[i]; 00093 if (s2.find(find) != string::npos) 00094 return true; 00095 } 00096 00097 return false; 00098 } 00099 00100
1.5.8