00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _QNAMEH
00022 #define _QNAMEH
00023
00024 #include <string>
00025 #include <iostream>
00026 class Qname
00027 {
00028 public:
00029 Qname (const std::string & name);
00030 Qname (const Qname & qn);
00031 Qname ();
00032 std::string getLocalName (void)const;
00033 std::string getPrefix (void) const;
00034 std::string getNamespace (void)const;
00035 void setNamespace (std::string uri);
00036 bool operator== (const Qname & qn)const;
00037 void operator= (const std::string & name);
00038 friend std::ostream & operator<<(std::ostream & os,const Qname& qn);
00039 private:
00040 void parse (const std::string & name);
00041 std::string namespaceUri, localname, prefix;
00042 };
00043
00044 inline
00045 Qname::Qname (const std::string & name)
00046 {
00047 parse (name);
00048 }
00049
00050 inline
00051 Qname::Qname (const Qname & qn)
00052 {
00053 localname = qn.localname;
00054 prefix = qn.prefix;
00055 namespaceUri = qn.namespaceUri;
00056 }
00057
00058 inline
00059 Qname::Qname ()
00060 {
00061 }
00062
00063 inline
00064 void
00065 Qname::operator= (const std::string & name)
00066 {
00067 parse (name);
00068 }
00069
00070 inline
00071 std::string
00072 Qname::getLocalName (void)const
00073 {
00074 return localname;
00075 }
00076
00077 inline
00078 std::string
00079 Qname::getPrefix (void) const
00080 {
00081 return prefix;
00082 }
00083
00084 inline
00085 std::string
00086 Qname::getNamespace (void)const
00087 {
00088 return namespaceUri;
00089 }
00090
00091 inline
00092 void
00093 Qname::setNamespace (std::string uri)
00094 {
00095 namespaceUri = uri;
00096 }
00097
00098 inline
00099 bool
00100 Qname::operator== (const Qname & qn)const
00101 {
00102 if (qn.getNamespace () == namespaceUri && qn.getLocalName () == localname)
00103 return true;
00104 else
00105 return false;
00106 }
00107
00108 inline
00109 void
00110 Qname::parse (const std::string & name)
00111 {
00112 int cut = -1;
00113 if (name.empty ())
00114 return;
00115 cut = name.find (":");
00116 if (cut == -1 || cut == 0)
00117 localname = name;
00118
00119 else
00120
00121 {
00122 localname = name.substr (cut + 1);
00123 prefix = name.substr (0, cut);
00124 }
00125 cut = localname.find ("[]");
00126 if (cut > 0)
00127 localname = localname.substr (0, cut);
00128 }
00129
00130 inline
00131 std::ostream & operator<<(std::ostream & os,const Qname& qn)
00132 {
00133 os<<qn.getPrefix()<<"{"<<qn.getNamespace()<<"}:"<<qn.getLocalName();
00134 return os;
00135 }
00136 #endif