void CPropertyXMLParser::onEndElement(const XML_Char* name) { vfs::String utf8_name(name); if(current_state == DO_ELEMENT_Key && vfs::StrCmp::Equal(utf8_name, _tagmap.key())) { _container.setStringProperty(current_section, current_key, vfs::trimString(sCharData,0,sCharData.length())); current_state = DO_ELEMENT_Section; } else if(current_state == DO_ELEMENT_Section && vfs::StrCmp::Equal(utf8_name, _tagmap.section())) { current_state = DO_ELEMENT_Container; } else if(current_state == DO_ELEMENT_Container && vfs::StrCmp::Equal(utf8_name, _tagmap.container())) { current_state = DO_ELEMENT_NONE; } }
void CPropertyXMLParser::onStartElement(const XML_Char *name, const XML_Char **atts) { vfs::String utf8_name(name); if(current_state == DO_ELEMENT_NONE && vfs::StrCmp::Equal(utf8_name,_tagmap.container())) { current_state = DO_ELEMENT_Container; } else if(current_state == DO_ELEMENT_Container && vfs::StrCmp::Equal(utf8_name, _tagmap.section())) { current_state = DO_ELEMENT_Section; current_section = this->getAttribute(_tagmap.sectionID().utf8().c_str(),atts); } else if(current_state == DO_ELEMENT_Section && vfs::StrCmp::Equal(utf8_name, _tagmap.key())) { current_state = DO_ELEMENT_Key; current_key = this->getAttribute(_tagmap.keyID().utf8().c_str(),atts); } sCharData = ""; }
static PyObject* Preprocessor_define(Preprocessor* self, PyObject *args) { PyObject *macro; PyObject *value = NULL; if (!PyArg_ParseTuple(args, "O|O:define", ¯o, &value)) return NULL; try { // First check if it's a string. If so, convert it to UTF-8 and define // an object-like macro. if (PyUnicode_Check(macro)) { ScopedPyObject utf8_name(PyUnicode_AsUTF8String(macro)); const char *macro_name; if (utf8_name && (macro_name = PyBytes_AsString(utf8_name))) { if (value) { if (PyUnicode_Check(value)) // define(name, value) { ScopedPyObject utf8_value( PyUnicode_AsUTF8String(value)); const char *macro_value; if (utf8_value && (macro_value = PyBytes_AsString(utf8_value))) { // Value specified: // "#define macro_name macro_value". self->preprocessor->define( macro_name, macro_value); } else { return NULL; } } else if (PyCallable_Check(value)) // define(name, callable) { boost::shared_ptr<cmonster::core::FunctionMacro> function(new cmonster::python::FunctionMacro( self, value)); self->preprocessor->define(macro_name, function); } else { PyErr_SetString(PyExc_TypeError, "expected string or callable for value argument"); return NULL; } } else { // No value specified: "#define macro_name". self->preprocessor->define(macro_name); } } else { return NULL; } } else if (PyCallable_Check(macro)) // define(callable) { // TODO ensure "value" was not specified. const char *name = PyEval_GetFuncName(macro); boost::shared_ptr<cmonster::core::FunctionMacro> function(new cmonster::python::FunctionMacro(self, macro)); self->preprocessor->define(name, function); } else { PyErr_SetString(PyExc_TypeError, "expected string or callable"); return NULL; } } catch (...) { set_python_exception(); return NULL; } Py_INCREF(Py_None); return Py_None; }