00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef XPATH_H
00013 #define XPATH_H
00014
00015 #include <string>
00016 #include <list>
00017
00022 typedef enum {
00023 XP_ELEMENT,
00024 XP_ATTR
00025 } XPType;
00026
00027 class XPathEntry {
00028 public:
00029 XPType type;
00030 std::string text;
00031 XPathEntry(std::string c, XPType tp = XP_ELEMENT): type(tp), text(c) {
00032 }
00033 };
00034
00035 class XPath: public std::list<XPathEntry> {
00036 public:
00042 inline static bool is_valid_path(const char* path) {
00043 return true;
00044 }
00045 XPath(const char* path) {
00046 const char* it = path;
00047 const char* it1 = path;
00048 is_valid_path(path);
00049 for(; *it != 0;it++) {
00050 if(*it == '/') {
00051 if(*it1 == '/')
00052 it1 = it + 1;
00053 else {
00054 push_back(std::string(it1, (int)(it - it1)));
00055 it1 = it + 1;
00056 }
00057 }
00058 }
00059 for(const char* i = it1; i != it; i++)
00060 if(*i == '@') {
00061 push_back(std::string(it1, (int)(i - it1)));
00062 it1 = i;
00063 }
00064 if(*it1 == '@') {
00065 it1++;
00066 XPathEntry pat(std::string(it1, (int)(it - it1)), XP_ATTR);
00067 push_back(pat);
00068 } else
00069 push_back(std::string(it1, (int)(it - it1)));
00070
00071 iterator i = begin();
00072 iterator ie = end();
00073
00074 for(;i != ie;) {
00075 if(i->text == ".")
00076 i = erase(i);
00077
00078
00079
00080
00081
00082
00083
00084 else if(i->text.empty())
00085 i = erase(i);
00086 else
00087 i++;
00088 }
00089 i = begin();
00090 }
00091 };
00092
00093 #endif