Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

XmlRpc::XmlRpcUtil Class Reference

Utilities for XML parsing, encoding, and decoding and message handlers. More...

#include <XmlRpcUtil.h>

List of all members.

Static Public Member Functions

void error (const char *fmt,...)
 Dump error messages somewhere.
bool findTag (const char *tag, std::string const &xml, int *offset)
 Returns true if the tag is found and updates offset to the char after the tag.
std::string getNextTag (std::string const &xml, int *offset)
void log (int level, const char *fmt,...)
 Dump messages somewhere.
bool nextTagIs (const char *tag, std::string const &xml, int *offset)
std::string parseTag (const char *tag, std::string const &xml, int *offset)
 Returns contents between <tag> and </tag>, updates offset to char after </tag>.
std::string xmlDecode (const std::string &encoded)
 Convert encoded xml to raw text.
std::string xmlEncode (const std::string &raw)
 Convert raw text to encoded xml.


Detailed Description

Utilities for XML parsing, encoding, and decoding and message handlers.


Member Function Documentation

void XmlRpcUtil::error const char *  fmt,
  ...
[static]
 

Dump error messages somewhere.

00086 {
00087   va_list va;
00088   va_start(va, fmt);
00089   char buf[1024];
00090   vsnprintf(buf,sizeof(buf)-1,fmt,va);
00091   buf[sizeof(buf)-1] = 0;
00092   XmlRpcErrorHandler::getErrorHandler()->error(buf);
00093 }

bool XmlRpcUtil::findTag const char *  tag,
std::string const &  xml,
int *  offset
[static]
 

Returns true if the tag is found and updates offset to the char after the tag.

00117 {
00118   if (*offset >= int(xml.length())) return false;
00119   size_t istart = xml.find(tag, *offset);
00120   if (istart == std::string::npos)
00121     return false;
00122 
00123   *offset = int(istart + strlen(tag));
00124   return true;
00125 }

std::string XmlRpcUtil::getNextTag std::string const &  xml,
int *  offset
[static]
 

Returns the next tag and updates offset to the char after the tag, or empty string if the next non-whitespace character is not '<'

00153 {
00154   if (*offset >= int(xml.length())) return std::string();
00155 
00156   size_t pos = *offset;
00157   const char* cp = xml.c_str() + pos;
00158   while (*cp && isspace(*cp)) {
00159     ++cp;
00160     ++pos;
00161   }
00162 
00163   if (*cp != '<') return std::string();
00164 
00165   std::string s;
00166   do {
00167     s += *cp;
00168     ++pos;
00169   } while (*cp++ != '>' && *cp != 0);
00170 
00171   *offset = int(pos);
00172   return s;
00173 }

void XmlRpcUtil::log int  level,
const char *  fmt,
  ...
[static]
 

Dump messages somewhere.

00072 {
00073   if (level <= XmlRpcLogHandler::getVerbosity())
00074   {
00075     va_list va;
00076     char buf[1024];
00077     va_start( va, fmt);
00078     vsnprintf(buf,sizeof(buf)-1,fmt,va);
00079     buf[sizeof(buf)-1] = 0;
00080     XmlRpcLogHandler::getLogHandler()->log(level, buf);
00081   }
00082 }

bool XmlRpcUtil::nextTagIs const char *  tag,
std::string const &  xml,
int *  offset
[static]
 

Returns true if the tag is found at the specified offset (modulo any whitespace) and updates offset to the char after the tag

00132 {
00133   if (*offset >= int(xml.length())) return false;
00134   const char* cp = xml.c_str() + *offset;
00135   int nc = 0;
00136   while (*cp && isspace(*cp)) {
00137     ++cp;
00138     ++nc;
00139   }
00140 
00141   int len = int(strlen(tag));
00142   if  (*cp && (strncmp(cp, tag, len) == 0)) {
00143     *offset += nc + len;
00144     return true;
00145   }
00146   return false;
00147 }

std::string XmlRpcUtil::parseTag const char *  tag,
std::string const &  xml,
int *  offset
[static]
 

Returns contents between <tag> and </tag>, updates offset to char after </tag>.

00099 {
00100   if (*offset >= int(xml.length())) return std::string();
00101   size_t istart = xml.find(tag, *offset);
00102   if (istart == std::string::npos) return std::string();
00103   istart += strlen(tag);
00104   std::string etag = "</";
00105   etag += tag + 1;
00106   size_t iend = xml.find(etag, istart);
00107   if (iend == std::string::npos) return std::string();
00108 
00109   *offset = int(iend + etag.length());
00110   return xml.substr(istart, iend-istart);
00111 }

std::string XmlRpcUtil::xmlDecode const std::string &  encoded  )  [static]
 

Convert encoded xml to raw text.

00188 {
00189   std::string::size_type iAmp = encoded.find(AMP);
00190   if (iAmp == std::string::npos)
00191     return encoded;
00192 
00193   std::string decoded(encoded, 0, iAmp);
00194   std::string::size_type iSize = encoded.size();
00195   decoded.reserve(iSize);
00196 
00197   const char* ens = encoded.c_str();
00198   while (iAmp != iSize) {
00199     if (encoded[iAmp] == AMP && iAmp+1 < iSize) {
00200       int iEntity;
00201       for (iEntity=0; xmlEntity[iEntity] != 0; ++iEntity)
00202         //if (encoded.compare(iAmp+1, xmlEntLen[iEntity], xmlEntity[iEntity]) == 0)
00203         if (strncmp(ens+iAmp+1, xmlEntity[iEntity], xmlEntLen[iEntity]) == 0)
00204         {
00205           decoded += rawEntity[iEntity];
00206           iAmp += xmlEntLen[iEntity]+1;
00207           break;
00208         }
00209       if (xmlEntity[iEntity] == 0)    // unrecognized sequence
00210         decoded += encoded[iAmp++];
00211 
00212     } else {
00213       decoded += encoded[iAmp++];
00214     }
00215   }
00216     
00217   return decoded;
00218 }

std::string XmlRpcUtil::xmlEncode const std::string &  raw  )  [static]
 

Convert raw text to encoded xml.

00225 {
00226   std::string::size_type iRep = raw.find_first_of(rawEntity);
00227   if (iRep == std::string::npos)
00228     return raw;
00229 
00230   std::string encoded(raw, 0, iRep);
00231   std::string::size_type iSize = raw.size();
00232 
00233   while (iRep != iSize) {
00234     int iEntity;
00235     for (iEntity=0; rawEntity[iEntity] != 0; ++iEntity)
00236       if (raw[iRep] == rawEntity[iEntity])
00237       {
00238         encoded += AMP;
00239         encoded += xmlEntity[iEntity];
00240         break;
00241       }
00242     if (rawEntity[iEntity] == 0)
00243       encoded += raw[iRep];
00244     ++iRep;
00245   }
00246   return encoded;
00247 }


The documentation for this class was generated from the following files:
Generated on Wed Feb 2 19:25:38 2011 for BOSS6.5.5 by  doxygen 1.3.9.1