Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

LCD_DocumentUtil.cc

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 // $Id: LCD_DocumentUtil.cc,v 1.11 2004/02/02 22:12:48 uid561 Exp $
00003 // ----------------------------------------------------------------------------
00004 //
00005 // LCD_DocumentUtil.cxx
00006 //
00007 //  Implementation file for a class of static utilities needed
00008 //  by LCD_Doc.. family of classes
00009 
00010 #include <sstream>
00011 #include "LCD_DocumentUtil.hh"
00012 XERCES_CPP_NAMESPACE_USE
00013 
00014 const int LCD_DocumentUtil::m_MAX_STR_LEN = 256;
00015 
00016 // static methods from LCD_DocumentUtil class
00017 
00018 /*
00019  * Comment
00020  */
00021 bool LCD_DocumentUtil::convertValue(const DOMString& strVal, double *val)
00022 {
00023   char buf[m_MAX_STR_LEN];
00024   *val = 0.0;
00025   bool ok;
00026 
00027   if (!(squash(strVal, buf))) return false;
00028 
00029   std::istringstream ist(&buf[0]);
00030 
00031   ist >> *val;
00032 
00033   ok = !(ist.fail());
00034   return ok;
00035 
00036 }
00037 
00038 
00039 /*
00040  * Comment
00041  */
00042 bool LCD_DocumentUtil::convertValue(const DOMString& strVal, int *val)
00043 {
00044   char buf[m_MAX_STR_LEN];
00045   *val = 0;
00046   bool ok;
00047 
00048   if (!(squash(strVal, buf))) return false;
00049 
00050   std::istringstream ist(&buf[0]);
00051 
00052   ist >> *val;
00053 
00054   ok = !(ist.fail());
00055   return ok;
00056 
00057 }
00058 
00059 
00060 /*
00061  * Comment
00062  */
00063 bool LCD_DocumentUtil::convertValue(const DOMString& strVal, unsigned int *val)
00064 {
00065   char buf[m_MAX_STR_LEN];
00066   bool ok;
00067 
00068   if (!(squash(strVal, buf))) return false;
00069 
00070   std::istringstream ist(&buf[0]);
00071 
00072   ist >> *val;
00073 
00074   ok = !(ist.fail());
00075   return ok;
00076 
00077 }
00078 
00079 /*
00080  * Comment
00081  */
00082 bool LCD_DocumentUtil::convertValue(const DOMString& strVal, bool *val) {
00083   if ((strVal.equals("yes")) || (strVal.equals("true")) ) {
00084     *val = true;
00085   }
00086   else if ((strVal.equals("no")) || (strVal.equals("false")) ) {
00087     *val = false;
00088   }
00089   else return false;          // illegal value supplied
00090 
00091   return true;
00092 }
00093 
00094 // Given a DOMString, just cut off higher byte of raw unicode string
00095 // and copy to supplied buffer (which had better be big enough!)
00096 
00097 /*
00098  * Comment
00099  */
00100 bool LCD_DocumentUtil::squash(const DOMString& domstr, char *squashed,
00101                               int  bufLen) {
00102   int len = domstr.length();
00103   int ix;
00104   if (len >= bufLen) return false;
00105 
00106   for (ix = 0; ix < len; ix++) {
00107     squashed[ix] = (domstr.charAt(ix) & 0x00ff);
00108   }
00109 
00110 
00111   // Note:  following did not work since __wchar_t apparently translates
00112   // to long rather than short
00113   //  nSquashed = wcstombs(squashed, (__wchar_t *) domstr.rawBuffer(), bufLen);
00114 
00115   squashed[ix] = 0;
00116 
00117   return true;
00118 }
00119 
00120 
00121 /*
00122  * Comment
00123  */
00124 DOM_Element LCD_DocumentUtil::firstDesc(const DOM_Element ancestor,
00125                                         const DOMString& tagName)
00126 {
00127   DOM_NodeList list = ancestor.getElementsByTagName(tagName);
00128   if (list.getLength() == 0) return DOM_Element();
00129   DOM_Node node = list.item(0);
00130 
00131   DOM_Element retElt = (DOM_Element &) node;
00132   return retElt;
00133 }
00134 
00135 /*
00136  * Comment
00137  */
00138 DOM_Element LCD_DocumentUtil::firstDesc(const DOM_Element ancestor,
00139                                         const char* tagName)
00140 {
00141   DOM_NodeList list = ancestor.getElementsByTagName(DOMString(tagName));
00142   if (list.getLength() == 0) return DOM_Element();
00143 
00144   DOM_Node node = list.item(0);
00145   return (DOM_Element &) (node);
00146 }
00147 

Generated on Thu Oct 7 18:44:46 2004 for LCDG4 by doxygen 1.3.4