Пример #1
0
void CategoryXmlHandler::characters(void* user_data, const xmlChar* ch, int len) {
    Stub_Categories* stub = static_cast<Stub_Categories*>(user_data);
    string value = (const char *)(xmlStrncatNew(BAD_CAST "", xmlStrsub(ch, 0, len), len));
    Category* category = stub->GetCategory();

    if (stub->GetCurrent() == "name") {
        category->SetName(category->GetName() + value);
    } else if (stub->GetCurrent() == "weight") {
        category->SetWeight(atof(value.c_str()));
    } else if (stub->GetCurrent() == "sample") {
        category->AddSample(value);
    }
}
Пример #2
0
static xmlChar* get_attribute(parse_context_t* context, int nb_attributes,	const xmlChar** attributes, const xmlChar* name) {

	xmlChar *value=NULL;

	int index;
	for(index=0; index<nb_attributes && value==NULL; index++) {
		int att_index = index * 5;

		const xmlChar *localname = attributes[att_index];
		if(xmlStrEqual(name, localname)) {

			//const xmlChar *prefix = attributes[att_index+1];
			//const xmlChar *nsURI = attributes[att_index+2];
			const xmlChar *valueBegin = attributes[att_index+3];
			const xmlChar *valueEnd = attributes[att_index+4];

			int value_size = valueEnd - valueBegin;
			value = xmlStrsub(valueBegin, 0, value_size);
		}

	}

	return value;
}
Пример #3
0
/**
 * exsltMathConstant
 * @name: string
 * @precision:  number
 *
 * Implements the EXSLT - Math constant function:
 *     number math:constant(string, number)
 *
 * Returns a number value of the given constant with the given precision or
 * xmlXPathNAN if name is unknown.
 * The constants are PI, E, SQRRT2, LN2, LN10, LOG2E, and SQRT1_2
 */
static double
exsltMathConstant (xmlChar *name, double precision) {
    xmlChar *str;

    if ((name == NULL) || (xmlXPathIsNaN(precision)) || (precision < 1.0)) {
        return xmlXPathNAN;
    }

    if (xmlStrEqual(name, BAD_CAST "PI")) {
        int len = xmlStrlen(EXSLT_PI);

        if (precision <= len)
            len = (int)precision;
        
        str = xmlStrsub(EXSLT_PI, 0, len);
        if (str == NULL)
            return xmlXPathNAN;

        return xmlXPathCastStringToNumber(str);

    } else if (xmlStrEqual(name, BAD_CAST "E")) {
        int len = xmlStrlen(EXSLT_E);

        if (precision <= len)
            len = (int)precision;
        
        str = xmlStrsub(EXSLT_E, 0, len);
        if (str == NULL)
            return xmlXPathNAN;

        return xmlXPathCastStringToNumber(str);

    } else if (xmlStrEqual(name, BAD_CAST "SQRRT2")) {
        int len = xmlStrlen(EXSLT_SQRRT2);

        if (precision <= len)
            len = (int)precision;
        
        str = xmlStrsub(EXSLT_SQRRT2, 0, len);
        if (str == NULL)
            return xmlXPathNAN;

        return xmlXPathCastStringToNumber(str);

    } else if (xmlStrEqual(name, BAD_CAST "LN2")) {
        int len = xmlStrlen(EXSLT_LN2);

        if (precision <= len)
            len = (int)precision;
        
        str = xmlStrsub(EXSLT_LN2, 0, len);
        if (str == NULL)
            return xmlXPathNAN;

        return xmlXPathCastStringToNumber(str);

    } else if (xmlStrEqual(name, BAD_CAST "LN10")) {
        int len = xmlStrlen(EXSLT_LN10);

        if (precision <= len)
            len = (int)precision;
        
        str = xmlStrsub(EXSLT_LN10, 0, len);
        if (str == NULL)
            return xmlXPathNAN;

        return xmlXPathCastStringToNumber(str);

    } else if (xmlStrEqual(name, BAD_CAST "LOG2E")) {
        int len = xmlStrlen(EXSLT_LOG2E);

        if (precision <= len)
            len = (int)precision;
        
        str = xmlStrsub(EXSLT_LOG2E, 0, len);
        if (str == NULL)
            return xmlXPathNAN;

        return xmlXPathCastStringToNumber(str);

    } else if (xmlStrEqual(name, BAD_CAST "SQRT1_2")) {
        int len = xmlStrlen(EXSLT_SQRT1_2);

        if (precision <= len)
            len = (int)precision;
        
        str = xmlStrsub(EXSLT_SQRT1_2, 0, len);
        if (str == NULL)
            return xmlXPathNAN;

        return xmlXPathCastStringToNumber(str);

    } else {
        return xmlXPathNAN;
    } 
}
Пример #4
0
static void
exsltRegexpMatchFunction (xmlXPathParserContextPtr ctxt, int nargs)
{
    xsltTransformContextPtr tctxt;
    xmlNodePtr node;
    xmlDocPtr container;
    xmlXPathObjectPtr ret = NULL;
    xmlChar *haystack, *regexp, *flagstr, *working, *match;
    int rc, x, flags, global, ovector[30];

    if ((nargs < 1) || (nargs > 3)) {
        xmlXPathSetArityError(ctxt);
        return;
    }


    if (nargs > 2) {
      flagstr = xmlXPathPopString(ctxt);
      if (xmlXPathCheckError(ctxt) || (flagstr == NULL)) {
          return;
      }
    } else {
     flagstr = xmlStrdup("");
    }
    
    regexp = xmlXPathPopString(ctxt);
    if (xmlXPathCheckError(ctxt) || (regexp == NULL)) {
        xmlFree(flagstr);
        return;
    }

    haystack = xmlXPathPopString(ctxt);
    if (xmlXPathCheckError(ctxt) || (haystack == NULL)) {
        xmlFree(regexp);
        xmlFree(flagstr);
        return;
    }

    /* Return a result tree fragment */
    tctxt = xsltXPathGetTransformContext(ctxt);
    if (tctxt == NULL) {
      xsltTransformError(xsltXPathGetTransformContext(ctxt), NULL, NULL,
                         "exslt:regexp : internal error tctxt == NULL\n");
      goto fail;
    }

    container = xsltCreateRVT(tctxt);
    if (container != NULL) {
      xsltRegisterTmpRVT(tctxt, container);
      ret = xmlXPathNewNodeSet(NULL);
      if (ret != NULL) {
        ret->boolval = 0; 

        exsltRegexpFlagsFromString(flagstr, &global, &flags);
        working = haystack;
        rc = exsltRegexpExecute(ctxt, working, regexp, flags, 
                                ovector, sizeof(ovector)/sizeof(int));

        while (rc > 0) {
          for(int group = 0; group < rc; group++) {
            match = xmlStrsub(working, ovector[group*2], ovector[group*2+1]-ovector[group*2]);
            if (NULL == match) goto fail;

            node = xmlNewDocRawNode(container, NULL, "match", match);
            xmlFree(match);

            xmlAddChild((xmlNodePtr) container, node);
            xmlXPathNodeSetAddUnique(ret->nodesetval, node);
          }
          if (!global) break;

          working = working + ovector[1];
          rc = exsltRegexpExecute(ctxt, working, regexp, flags, 
                                  ovector, sizeof(ovector)/sizeof(int));
        }
      }
    }
    
 fail:
    if (flagstr != NULL)
      xmlFree(flagstr);
    if (regexp != NULL)
      xmlFree(regexp);
    if (haystack != NULL)
      xmlFree(haystack);

    if (ret != NULL)
      valuePush(ctxt, ret);
    else
      valuePush(ctxt, xmlXPathNewNodeSet(NULL));
}
Пример #5
0
static void
exsltRegexpReplaceFunction (xmlXPathParserContextPtr ctxt, int nargs)
{
    xmlChar *haystack, *regexp, *flagstr, *replace, *tmp;
    xmlChar *result = NULL, *working, *end;
    int rc, x, flags, global, ovector[3];

    if ((nargs < 1) || (nargs > 4)) {
        xmlXPathSetArityError(ctxt);
        return;
    }

    replace = xmlXPathPopString(ctxt);
    if (xmlXPathCheckError(ctxt) || (replace == NULL)) {
        return;
    }

    flagstr = xmlXPathPopString(ctxt);
    if (xmlXPathCheckError(ctxt) || (flagstr == NULL)) {
        xmlFree(replace);
        return;
    }

    regexp = xmlXPathPopString(ctxt);
    if (xmlXPathCheckError(ctxt) || (regexp == NULL)) {
        xmlFree(flagstr);
        xmlFree(replace);
        return;
    }

    haystack = xmlXPathPopString(ctxt);
    if (xmlXPathCheckError(ctxt) || (haystack == NULL)) {
        xmlFree(regexp);
        xmlFree(flagstr);
        xmlFree(replace);
        return;
    }

    exsltRegexpFlagsFromString(flagstr, &global, &flags);

    working = haystack;
    rc = exsltRegexpExecute(ctxt, working, regexp, flags, 
                            ovector, sizeof(ovector)/sizeof(int));

    while (rc > 0 ) {
      if (0==ovector[0]) {
        if (NULL==result) result = xmlStrdup(replace);
        else result = xmlStrcat(result, replace);
      }
      else {
        tmp = xmlStrsub(working, 0, ovector[0]);
        if (NULL==result) result = tmp;
        else {
          result = xmlStrcat(result, tmp);
          xmlFree(tmp);
        }
        result = xmlStrcat(result, replace);
      }
      
      working = working + ovector[1];

      if (!global) break;
      rc = exsltRegexpExecute(ctxt, working, regexp, flags, 
                              ovector, sizeof(ovector)/sizeof(int));
    }

    end = haystack + xmlUTF8Strlen(haystack);
    if (working < end ) {
        if (NULL==result) result = xmlStrdup(working);
        else {
          result = xmlStrcat(result, working);
        }
    }

fail:
    if (replace != NULL)
            xmlFree(replace);
    if (flagstr != NULL)
            xmlFree(flagstr);
    if (regexp != NULL)
            xmlFree(regexp);
    if (haystack != NULL)
            xmlFree(haystack);

    xmlXPathReturnString(ctxt, result);
}
Пример #6
0
 SDOXMLString::SDOXMLString(const xmlChar* str, int start, int len)
 {
     xmlForm = xmlStrsub(str, start, len);
 }