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