RegexValidator::RegexValidator(xmlNodePtr node) : Validator(node), re_(NULL), pcre_options_(PCRE_UTF8) { // Fetch mandatory pattern xmlAttrPtr pattern_attr = xmlHasProp(node, (const xmlChar*)"pattern"); if (!pattern_attr) throw std::runtime_error("Pattern not provided"); std::string pattern = XmlUtils::value(pattern_attr); xmlRemoveProp(pattern_attr); // libxml will free memory // Sanity check: pattern shouldn't be empty if (pattern.empty()) throw std::runtime_error("Empty pattern in regex validator"); // Check supported options. xmlAttrPtr options_attr = xmlHasProp(node, (const xmlChar*)"options"); if (options_attr) { std::string options = XmlUtils::value(options_attr); xmlRemoveProp(options_attr); const char* c = options.c_str(); while (*c) { switch (*c) { case 'i': pcre_options_ |= PCRE_CASELESS; break; default: throw std::runtime_error(std::string("Unknown regex option: ") + *c + " for pattern " + pattern); } ++c; } } // Time to compile regex const char* compile_error; int error_offset; re_ = pcre_compile(pattern.c_str(), pcre_options_, &compile_error, &error_offset, NULL); if (re_ == NULL) throw std::runtime_error( std::string("Regex '") + pattern + "' compilation failed: " + compile_error + " at " + boost::lexical_cast<std::string>(error_offset)); bzero((void*)&re_extra_, sizeof(re_extra_)); }
static HRESULT WINAPI xmlelem_removeAttribute(IXMLElement *iface, BSTR strPropertyName) { xmlelem *This = impl_from_IXMLElement(iface); xmlChar *name; xmlAttrPtr attr; int res; HRESULT hr = S_FALSE; TRACE("(%p, %s)\n", iface, debugstr_w(strPropertyName)); if (!strPropertyName) return E_INVALIDARG; name = xmlChar_from_wchar(strPropertyName); attr = xmlHasProp(This->node, name); if (!attr) goto done; res = xmlRemoveProp(attr); if (res == 0) hr = S_OK; done: HeapFree(GetProcessHeap(), 0, name); return hr; }
void osync_xml_node_remove_unknown_mark(xmlNode *node) { xmlAttr *attr = xmlHasProp(node, (xmlChar*)"Type"); if (!attr) return; xmlRemoveProp(attr); }
/* * call-seq: * remove_attribute(property) * * remove the property +property+ */ static VALUE remove_prop(VALUE self, VALUE property) { xmlNodePtr node; xmlAttrPtr attr ; Data_Get_Struct(self, xmlNode, node); attr = xmlHasProp(node, (xmlChar *)StringValuePtr(property)); if (attr) { xmlRemoveProp(attr); } return Qnil; }
static HRESULT WINAPI xmlnodemap_removeQualifiedItem( IXMLDOMNamedNodeMap *iface, BSTR baseName, BSTR namespaceURI, IXMLDOMNode** qualifiedItem) { xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface ); xmlAttrPtr attr; xmlChar *name; xmlChar *href; TRACE("(%p)->(%s %s %p)\n", This, debugstr_w(baseName), debugstr_w(namespaceURI), qualifiedItem); if (!baseName) return E_INVALIDARG; if (namespaceURI && *namespaceURI) { href = xmlchar_from_wchar(namespaceURI); if (!href) return E_OUTOFMEMORY; } else href = NULL; name = xmlchar_from_wchar(baseName); if (!name) { heap_free(href); return E_OUTOFMEMORY; } attr = xmlHasNsProp( This->node, name, href ); heap_free(name); heap_free(href); if ( !attr ) { if (qualifiedItem) *qualifiedItem = NULL; return S_FALSE; } if ( qualifiedItem ) { xmlUnlinkNode( (xmlNodePtr) attr ); xmldoc_add_orphan( attr->doc, (xmlNodePtr) attr ); *qualifiedItem = create_node( (xmlNodePtr) attr ); } else { if (xmlRemoveProp(attr) == -1) ERR("xmlRemoveProp failed\n"); } return S_OK; }
/* * call-seq: * node.remove! -> nil * * Removes this attribute from it's parent. */ static VALUE rxml_attr_remove_ex(VALUE self) { xmlAttrPtr xattr; Data_Get_Struct(self, xmlAttr, xattr); if (xattr->_private == NULL) xmlRemoveProp(xattr); else xmlUnlinkNode((xmlNodePtr) xattr); return Qnil;; }
/* * call-seq: * attr.remove! -> nil * * Removes this attribute from it's parent. Note * the attribute and its content is freed and can * no longer be used. If you try to use it you * will get a segmentation fault. */ static VALUE rxml_attr_remove_ex(VALUE self) { xmlAttrPtr xattr; Data_Get_Struct(self, xmlAttr, xattr); xmlRemoveProp(xattr); RDATA(self)->data = NULL; RDATA(self)->dfree = NULL; RDATA(self)->dmark = NULL; return Qnil; }
// Inherits XMLSpy generation source function. void CNode::InternalRemoveAt(ENodeType eNodeType, const tstring& sNamespaceURI, const tstring& sName, int nIndex) { xmlNodePtr pNode = InternalGetAt(eNodeType, sNamespaceURI, sName, nIndex); if (eNodeType == Element) { xmlUnlinkNode(pNode); xmlFreeNode(pNode); } else { xmlRemoveProp((xmlAttrPtr)pNode); xmlFreeProp((xmlAttrPtr)pNode); } }
int CXML::DelAttr(const char *a_chPath, const char *a_chAttrName, int nIndex) { int nRet = XML_OK; int i = 0; xmlAttrPtr pAttr = NULL; xmlAttrPtr pFindAttr = NULL; xmlNodePtr pNode = NULL; nRet = GetAttrPtr(a_chPath, a_chAttrName, nIndex, &pAttr); if(nRet != XML_OK){ XML_LOG(XML_ERR,"Attribute not exist(ret=%d)\n",nRet); return nRet; } xmlRemoveProp(pAttr); return XML_OK; }
/* * Class: org_xmlsoft_Node * Method: removePropImpl * Signature: (Ljava/lang/String;)Z */ JNIEXPORT jboolean JNICALL Java_org_xmlsoft_Node_removePropImpl (JNIEnv *env, jobject obj, jstring jname) { xmlNode *node = findNode(env, obj); const xmlChar *name = (xmlChar*)(*env)->GetStringUTFChars(env, jname, NULL); jboolean deleted = JNI_FALSE; xmlAttr *attr = node->properties; while(attr!=NULL) { if(xmlStrcmp(attr->name, name)==0) { xmlRemoveProp(attr); deleted = JNI_TRUE; } attr = attr->next; } (*env)->ReleaseStringUTFChars(env, jname, (const char*)name); return deleted; }
std::auto_ptr<Validator> ValidatorFactory::createValidator(xmlNodePtr node) const { xmlAttrPtr attr = xmlHasProp(node, (const xmlChar*)"validator"); // If validator absent for param return null. if (!attr) return std::auto_ptr<Validator>(); std::string type = XmlUtils::value(attr); // Remove used prop, otherwise Param::parse will throw exception. // libxml will free memory xmlRemoveProp(attr); ValidatorMap::const_iterator i = validator_creators_.find(type); if (i == validator_creators_.end()) throw std::runtime_error("Unknown validator type: " + type); return std::auto_ptr<Validator>(i->second(node)); }
void XMLNode::Destroy(void) { if (node_ == NULL) return; if (is_owner_) { xmlFreeDoc(node_->doc); node_ = NULL; is_owner_ = false; return; } if (node_->type == XML_ELEMENT_NODE) { xmlNodePtr p = node_->prev; if(p && (p->type == XML_TEXT_NODE)) { xmlChar *buf = xmlNodeGetContent(p); if (buf) { while(*buf) { if(!isspace(*buf)) { p = NULL; break; } ++buf; } } } else { p = NULL; } xmlUnlinkNode(node_); xmlFreeNode(node_); node_ = NULL; // Remove beautyfication text too. if(p) { xmlUnlinkNode(p); xmlFreeNode(p); } return; } if (node_->type == XML_ATTRIBUTE_NODE) { xmlRemoveProp((xmlAttrPtr)node_); node_ = NULL; return; } }
xupl* xupl_parse(xupl *xup) { xupl_*_ = (xupl_*) xup; FILE* in = _->in; off_t buffsize = _->buffsize; unsigned short bit = 0x0001; unsigned short WHITESPACE = bit; unsigned short DOUBLE_STRING = (bit <<= 1); unsigned short SINGLE_STRING = (bit <<= 1); unsigned short STRING = DOUBLE_STRING | SINGLE_STRING; unsigned short LINE_COMMENT = (bit <<= 1); unsigned short MULTI_COMMENT = (bit <<= 1); unsigned short COMMENT = LINE_COMMENT | MULTI_COMMENT; unsigned short _state = 0; const int default_tksize = 12; int tksize = default_tksize + 1; unsigned char *tk = NULL; int tkndx = 0; int chars_read; char* buf = malloc(buffsize + 1); xmlNodePtr xroot = NULL; xmlNodePtr xc = NULL; xmlAttrPtr xprop = NULL; const xmlChar* xuplAttr = (const xmlChar*) "data-xupl"; const xmlChar* xuplClosed = (const xmlChar*) "closed"; xmlDocPtr xdoc = xmlNewDoc((const unsigned char*) "1.1"); //xmlNsPtr xuplNs = xmlNewGlobalNs(xdoc,"http://ns.xupl.org/1.1","xupl"); while ((chars_read = fread(buf, 1, buffsize, in)) > 0) { for (int i = 0; i < chars_read; i++) { const char c = buf[i]; switch (c) { case '\'': case '"': IF(COMMENT) break; IF(STR(c)) { DISABLE(STR(c)); } else if (NOT(STRING)) { ALLOW(STR(c)); break; } case '{': case '}': case ' ': case '\n': case '\r': case '\t': case '\f': case '\v': case ',': case '=': // Comment characters case '*': case '/': case '#': case '!': IF(STRING) break; switch (c) { case ',': case '{': xprop = NULL; } if (tk) { tk[tkndx] = 0; char p = 0; if (tkndx >= 1) p = tk[tkndx - 1]; unsigned char* m = NULL; unsigned int tklen = tkndx + 1; unsigned char* t = tk; IF(COMMENT) { if ('\n' == c && IS(LINE_COMMENT)) { if (tkndx + 1 < tksize) { tk[tkndx++] = ' '; tk[tkndx] = 0; } } else if ('*' == p && '/' == c && IS(MULTI_COMMENT)) { tk[tkndx - 1] = 0; } else break; DISABLE(COMMENT); m = tk + 2; } else if ('/' == p && '*' == c) { ALLOW(MULTI_COMMENT); break; // Single-line comments can be #! #* #/ ## } else if ('#' == p && ('!' == c || '*' == c || '/' == c || '#' == c)) { ALLOW(LINE_COMMENT); break; // If these characters were in the token and not part of a comment, // then continue as if they are normal characters of a token. } else if ('!' == c || '/' == c || '*' == c || '#' == c) break; if (!xc) { if (m) { xroot = xmlNewDocComment(xdoc, m); xmlDocSetRootElement(xdoc, xroot); } else { xc = xmlNewNode(NULL, tk); xmlDocSetRootElement(xdoc, xc); if (!xroot) xroot = xc; } } else if (m) { xmlAddChild(xc, xmlNewComment(m)); } else { char *attr = NULL; xmlAttrPtr closed = xmlHasProp(xc, xuplAttr); switch (tk[0]) { case '\'': case '"': t += 1; xmlAddChild(xc, xmlNewText(t)); break; // TODO make this parameterized, characters and names. case '.': attr = "class"; break; case '#': attr = "id"; break; case '@': attr = "project"; break; case '/': attr = "href"; break; case '[': attr = "data"; break; case '~': attr = "duration"; break; case '=': attr = "location"; break; case '^': attr = "at"; break; case ':': attr = "type"; break; case '!': attr = "priority"; break; default: { regmatch_t pmatch[1]; unsigned int isword = 0 == regexec(&re_word, (char*) tk, 1, pmatch, 0); if (closed) { if (isword) { xc = xmlNewChild(xc, NULL, tk, NULL); } else { xmlAddChild(xc, xmlNewText(tk)); } } else { if (xprop) { xmlNewProp(xc, xprop->name, tk); xmlRemoveProp(xprop); xprop = NULL; } else if (isword) { xprop = xmlNewProp(xc, tk, (unsigned char*) "True"); } else { xprop = xmlNewProp(xc, (unsigned char*) ".fake", tk); } switch (c) { case ',': case '{': xprop = NULL; } } } break; } if (attr) { if (closed) { xmlAddChild(xc, xmlNewText(t)); } else { xmlNewProp(xc, (xmlChar*) attr, t); } } } free(tk); tk = NULL; if (tksize > default_tksize && tkndx < default_tksize) { tksize /= 2; } tkndx = 0; if (m) continue; } default: break; } switch (c) { case '{': xmlNewProp(xc, xuplAttr, xuplClosed); continue; case '}': if (xc) { xmlAttrPtr data = xmlHasProp(xc, xuplAttr); if (data) xmlRemoveProp(data); xc = xc->parent; } continue; default: break; } // Accumulate the tk. if (!tk || tkndx >= tksize) { // If the tk buffer is too small, double it. tk = realloc(tk, tksize *= 2); } tk[tkndx++] = c; }