//this should be optimized by compiler to make toReturn in the calling function's memory rather than copying the object
	std::vector< std::string > splitString( std::string curStringToSplit, char delimeter /*= ' '*/, bool ignoreEmptyStrings /*= true */ )
	{
		std::vector< std::string > toReturn;

		toReturn.clear();
		size_t position = 0;

		std::string stringRemaining;

		while( position != std::string::npos )
		{
			position = curStringToSplit.find( delimeter );
			if( position != std::string::npos )
			{
				//if we 'find' the first character, then curStringToSplit will always be "",
				// so advance by 1, and ignore this empty string
				if( position == 0 )
				{
					++position;
					curStringToSplit = curStringToSplit.substr( position );
					continue;
				}

				//save the remaining characters
				stringRemaining = curStringToSplit.substr( position );

				//retrieve current substring
				curStringToSplit = curStringToSplit.substr( 0, position );

				//check if we're ignoring empty strings
				if( !ignoreEmptyStrings || ( ignoreEmptyStrings && ( !isStringEmpty( curStringToSplit ) ) ) )
				{
					toReturn.push_back( curStringToSplit );
				}

				//continue splitting the rest of the characters
				curStringToSplit = stringRemaining;
			}
			else
			{
				//character to split on not found, simply use the entire string or nothing if it is empty and we're ignoring empty strings
				if( !( ignoreEmptyStrings && isStringEmpty( curStringToSplit ) ) )
				{
					toReturn.push_back( curStringToSplit );
				}
			}

		}

		return toReturn;
	}
Example #2
0
static errorCode ops_stringData(const String value, void* app_data)
{
	struct ops_AppData* o_appD = (struct ops_AppData*) app_data;

	if(o_appD->prevElementUriID == 4) // URI == http://www.w3.org/2009/exi
	{
		if(o_appD->prevElementLnID != 31) // schemaId
		{
			DEBUG_MSG(ERROR, DEBUG_CONTENT_IO, (">Corrupt EXI Options\n"));
			return EXIP_HANDLER_STOP;
		}
		else
		{
			if(isStringEmpty(&value))
			{
				o_appD->parsed_ops->schemaIDMode = SCHEMA_ID_EMPTY;
			}
			else
			{
				o_appD->parsed_ops->schemaIDMode = SCHEMA_ID_SET;
				if(cloneStringManaged(&value, &o_appD->parsed_ops->schemaID, o_appD->permanentAllocList) != ERR_OK)
				{
					DEBUG_MSG(ERROR, DEBUG_CONTENT_IO, (">Memory error\n"));
					return EXIP_HANDLER_STOP;
				}
			}
		}
	}
	else
	{
		// Handle here the user defined meta-data that follows! http://www.w3.org/TR/2011/REC-exi-20110310/#key-userMetaData
	}

	return ERR_OK;
}
Example #3
0
static errorCode sample_attribute(QName qname, void* app_data)
{
	struct appData* appD = (struct appData*) app_data;
	if(appD->outputFormat == OUT_EXI)
	{
		printf("AT ");
		printString(qname.uri);
		printf(" ");
		printString(qname.localName);
		printf("=\"");
	}
	else if(appD->outputFormat == OUT_XML)
	{
		printf(" ");
		if(!isStringEmpty(qname.uri))
		{
			printString(qname.uri);
			printf(":");
		}
		printString(qname.localName);
		printf("=\"");
	}
	appD->expectAttributeData = 1;

	return ERR_OK;
}
Example #4
0
/**
 * @brief Callback called when the EXIP library has parsed the header.
 * This is the place to check for schemaID and load schemas files if any.
 *
 * @param app_data Pointer to the struct appData passed to initParser()
 * @return An EXIPSchema or NULL
 */
static EXIPSchema *sample_retrieveSchema(void* app_data) {
	struct appData* appD = (struct appData*) app_data;
	EXIheader *hdr = &appD->parser->strm.header;

	if	(!hdr->has_options)
		return	g_schemaPtr;

	if	(isStringEmpty(&hdr->opts.schemaID))
		return	g_schemaPtr;

	PRINT ("sample_retrieveSchema\n");
	PRINT ("schemaID = ");
	writeString (hdr->opts.schemaID);
	PRINT ("\n");

	char	sch[100];
	copyString(hdr->opts.schemaID, sch);

	//	Obix specific : simulate xmlns attribute
	if	(!strcmp(sch, "xobix")) {
		t_ctxt	*ctxt = &appD->ctxt;
		ctxt->atname[ctxt->atcount]	= strdup("xmlns");
		ctxt->atvalue[ctxt->atcount]	= strdup("http://obix.org/ns/schema/1.1");
		ctxt->atcount++;
	}

	XoExiLoadSchema (sch);
	return g_schemaPtr;
}
Example #5
0
static errorCode sample_startElement(QName qname, void* app_data)
{
	struct appData* appD = (struct appData*) app_data;
	if(appD->outputFormat == OUT_EXI)
	{
		printf("SE ");
		printString(qname.uri);
		printf(" ");
		printString(qname.localName);
		printf("\n");
	}
	else if(appD->outputFormat == OUT_XML)
	{
		char error = 0;
		unsigned char prefixIndex = 0;
		unsigned char prxHit = 1;
		int t;

		if(!isStringEmpty(qname.uri))
		{
			error = lookupPrefix(appD, *qname.uri, &prxHit, &prefixIndex);
			if(error != 0)
				return EXIP_HANDLER_STOP;

			sprintf(appD->nameBuf, "p%d:", prefixIndex);
			t = strlen(appD->nameBuf);
			memcpy(appD->nameBuf + t, qname.localName->str, qname.localName->length);
			appD->nameBuf[t + qname.localName->length] = '\0';
		}
		else
		{
			memcpy(appD->nameBuf, qname.localName->str, qname.localName->length);
			appD->nameBuf[qname.localName->length] = '\0';
		}
		push(&(appD->stack), createElement(appD->nameBuf));
		if(appD->unclosedElement)
			printf(">\n");
		printf("<%s", appD->nameBuf);

		if(prxHit == 0)
		{
			sprintf(appD->nameBuf, " xmlns:p%d=\"", prefixIndex);
			printf("%s", appD->nameBuf);
			printString(qname.uri);
			printf("\"");
		}

		appD->unclosedElement = 1;
	}

	return ERR_OK;
}
Example #6
0
/**
 * @brief Callback called when the EXIP library has found the start of an element
 * @param qname The qualified name of the element
 * @param app_data Pointer to the struct appData passed to initParser()
 * @return EXIP_HANDLER_OK if success, or EXIP_HANDLER_STOP if need to stop the parser
 */
static errorCode sample_startElement(QName qname, void* app_data) {
	struct appData* appD = (struct appData*) app_data;
	char error = 0;
	unsigned char prefixIndex = 0;
	unsigned char prxHit = 1;
	int t = 0;

	PRINT ("SE ");
	writeQName(qname);
	PRINT ("\n");

	//	Check if we where in another element. If yes, calls cb_startElement
	checkCallback (appD, 0);

	if(!isStringEmpty(qname.uri)) {
		char uri[200];
		char pfx[30];

		error = lookupPrefix(appD, *qname.uri, &prxHit, &prefixIndex);
		if	(error) {
			fprintf (stderr, "Prefix not found\n");
			return EXIP_HANDLER_STOP;
		}

		copyString(*qname.uri, uri);
		strcpy (pfx, getPrefixByNamespace(uri));
		strcpy (appD->nameBuf, pfx);
		strcat (appD->nameBuf, ":");
		t = strlen(appD->nameBuf);

		if(prxHit == 0) {
			// Create xmlns: attribute
			t_ctxt	*ctxt = &appD->ctxt;
			char tmp[30];
			strcpy (tmp, "xmlns:");
			strcat (tmp, pfx);
			ctxt->atname[ctxt->atcount]	= strdup(tmp);
			ctxt->atvalue[ctxt->atcount]	= StringStrdup(qname.uri);
			ctxt->atcount++;
		}
	}

	memcpy(appD->nameBuf + t, qname.localName->str, qname.localName->length);
	appD->nameBuf[t + qname.localName->length] = '\0';

	push(&(appD->stack), createElement(appD->nameBuf));

	appD->unclosedElement = 1;
	return ERR_OK;
}