Esempio n. 1
0
//----------------------------------------------------------------//
static STLString _escapeString ( cc8* str ) {
	
	u32 len = ( u32 )strlen ( str );
	
	STLString outStr;
	outStr.reserve ( len * 2 );
	
	for ( u32 i = 0; i < len; ++i ) {
		char c = str [ i ];
		if ( c == '\\' ) {
			outStr.append ( "\\\\" );
		}
		else {
			outStr.push_back ( c );
		}
	}
	return outStr;
}
Esempio n. 2
0
//----------------------------------------------------------------//
STLString USStream::ReadToken ( cc8* delimiters ) {

	STLString str;
	if ( this->IsAtEnd ()) return str;

	char stackBuffer [ LOCAL_BUFFER ];
	
	USMemStream memStream;
	memStream.SetChunkSize ( LOCAL_BUFFER );
	memStream.SetGuestBuffer ( stackBuffer, LOCAL_BUFFER );
	
	char c = 0;
	size_t size = 0;
	
	do {
		
		c = this->Read < char >( 0 );
		
		if ( delimiters && c ) {
		
			bool isDelimiter = false;
		
			for ( size_t i = 0; delimiters [ i ]; ++i ) {
				if ( delimiters [ i ] == c ) {
					isDelimiter = true;
					break;
				}
			}
			
			if ( isDelimiter ) {
				if ( size ) {
					c = 0;
				}
				else {
					continue;
				}
			}
		}
		
		memStream.Write < char >( c );
		size++;
	}
	while ( c );
	
	if ( size ) {
		
		str.reserve ( size + 1 );
		memStream.Seek ( 0, SEEK_SET );
		
		while ( size > 0 ) {
			
			char buffer [ LOCAL_BUFFER ];
			
			size_t readSize = size;
			if ( LOCAL_BUFFER < readSize ) {
				readSize = LOCAL_BUFFER;
			}
			
			memStream.ReadBytes ( buffer, readSize );
			str.append ( buffer, readSize );
			size -= readSize;
		}
	}
	return str;
}