void rtx_strtok(const CHAR * str, CHAR * ret, const CHAR * delimiters) { static char copy [1024] = ""; static BYTE i = 0; if ( str != NULL ) { rtx_strcpy ( copy, str, 100 ); i = 0; } BYTE j = 0; //skip leading characters to be ignored while ( _findChar( copy[i], delimiters ) == 1 ) { i++; } while ( copy[i] != '\0' && _findChar( copy[i], delimiters ) == 0 ) { ret[j] = copy [i]; i++; j++; } ret[j]='\0'; }
int indri::xml::XMLReader::_findEndTag( const char* buffer, int start, int finish ) { return _findChar( '>', buffer, start, finish ); }
int indri::xml::XMLReader::_readTag( const char* buffer, int bufferStart, int bufferEnd, std::string* tagName, std::map<std::string, std::string>* attributes, int* tagType ) { // skip opening whitespace int startLocation = bufferStart; int endLocation = _findEndTag( buffer, startLocation, bufferEnd ); int position = startLocation+1; int trueEndLocation = endLocation+1; if( endLocation - position < 1 ) LEMUR_THROW( LEMUR_GENERIC_ERROR, "Found a tag with no body" ); // is it a <!CDATA[ tag? // expand this test for completeness if ( buffer[position] == '!' && buffer[position + 1] == 'C' ) { if( tagType ) *tagType = TAG_CDATA_TYPE; trueEndLocation = position + 7; return trueEndLocation; } // is it an opening tag? if( buffer[position] == '/' ) { if( tagType ) *tagType = TAG_CLOSE_TYPE; position++; if( position >= endLocation ) LEMUR_THROW( LEMUR_GENERIC_ERROR, "Found a tag with no body" ); } else { if( buffer[endLocation-1] == '/' ) { if( tagType ) *tagType = TAG_OPEN_CLOSE_TYPE; endLocation--; } else if( tagType ) { *tagType = TAG_OPEN_TYPE; } } if( tagName || attributes ) { int textBegin = _findText( buffer, position, endLocation ); int textEnd = _findNotName( buffer, textBegin, endLocation+1 ); if( tagName ) tagName->assign( &buffer[textBegin], &buffer[textEnd] ); position = textEnd; if( attributes ) { attributes->clear(); textBegin = _findText( buffer, position, endLocation+1 ); position = textBegin; for( ; position != endLocation; position = _tryFindText( buffer, position, endLocation ) ) { textEnd = _findNotName( buffer, position, endLocation ); int equalsPosition = _findChar( '=', buffer, textEnd, endLocation ); int quotePosition = _findText( buffer, equalsPosition+1, endLocation ); int endQuotePosition = _findChar( buffer[quotePosition], buffer, quotePosition+1, endLocation ); std::string attributeName; std::string valueText; assert( position <= textEnd ); assert( quotePosition+1 <= endQuotePosition ); assert( textEnd < quotePosition+1 ); attributeName.assign( &buffer[position], &buffer[textEnd] ); valueText.assign( &buffer[quotePosition+1], &buffer[endQuotePosition] ); attributes->insert( std::make_pair( attributeName, valueText ) ); position = endQuotePosition+1; } } } return trueEndLocation; }