//: C01:SiteMapConvert.cpp // From Thinking in C++, 2nd Edition // Available at http://www.BruceEckel.com // (c) Bruce Eckel 2000 // Copyright notice in Copyright.txt // Using strings to create a custom conversion // program that generates HTML output #include "../require.h" #include #include #include #include using namespace std; class Item { string id, url; int depth; string removeBar(string s) { if(s[0] == '|') return s.substr(1); else return s; } public: Item(string in, int& index) : depth(0) { while(in[index] == '#' && index < in.size()){ depth++; index++; } // 0 means no '#' marks were found: if(depth == 0) depth = 1; while(in[index] != '%' && index < in.size()) id += in[index++]; id = removeBar(id); index++; // Move past '%' while(in[index] != '*' && index < in.size()) url += in[index++]; url = removeBar(url); index++; // To move past '*' } string identifier() { return id; } string path() { return url; } int level() { return depth; } }; int main(int argc, char* argv[]) { requireArgs(argc, 1, "usage: SiteMapConvert inputfilename"); ifstream in(argv[1]); assure(in, argv[1]); ofstream out("plainmap.html"); string line; while(getline(in, line)) { if(line.find("" + item.identifier() + "
"; out << startLevel << htmlLine << endLevel << endl; } break; // Out of while loop } } } ///:~