00001
00002
00003
00004
00005
00006
00007
00008
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
00017
00018
00019
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
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
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
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;
00090
00091 return true;
00092 }
00093
00094
00095
00096
00097
00098
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
00112
00113
00114
00115 squashed[ix] = 0;
00116
00117 return true;
00118 }
00119
00120
00121
00122
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
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