Exemple #1
0
bool SIMPLEAPI IsWhiteSpace(wchar_t ch)
{
	return IsLineSpace(ch) || IsLineEndChar(ch);
}
	static PGPError
sLineEndIOWriteProc(
	PGPIORef		ref,
	PGPSize			requestCount,
	const void *	buffer )
{
	PGPSize				remaining;
	const char *		cur;
	PGPLineEndIORef		self	= (PGPLineEndIORef)ref;
	PGPError			err	= kPGPError_NoErr;
	PGPInt32			delta	= 0;
	
	if ( requestCount == 0 )
		return( kPGPError_NoErr );
	
	remaining	= requestCount;
	cur			= (const char *)buffer;
	
	if ( self->lastCharWasCR &&
		*(char const *)buffer == '\n' )
	{
		/* eat line feed; it followed CR */
		++cur;
		--remaining;
		--delta;
	}

	while ( remaining != 0 )
	{
		char	curChar;
		
		curChar	= *cur++;
		--remaining;
		
		if ( IsLineEndChar( curChar ) )
		{
			/* eat newline if it follows carriage return */
			if ( remaining != 0  &&
				curChar == '\r' &&
				*cur == '\n' )
			{
				++cur;
				--remaining;
				--delta;
			}
			
			/* output correct line end */
			if ( self->toType == kCRLFLineEndType )
			{
				err	= AddToBuffer( self, '\r' );
				if ( IsntPGPError( err ) )
					err	= AddToBuffer( self, '\n' );
				++delta;
			}
			else if ( self->toType == kCRLineEndType)
			{
				err	= AddToBuffer( self, '\r' );
			}
			else
			{
				err	= AddToBuffer( self, '\n' );
			}
		}
		else
		{
			err	= AddToBuffer( self, curChar );
		}
	}
	
	/* must remember this for next write which starts with '\n' */
	self->lastCharWasCR	=
		((const char *)buffer)[ requestCount - 1 ] == '\r';
	
	/* PGPIOWrite function will add the request count in;
		we add in the delta bytes to account for more, fewer we output */
	if ( IsntPGPError( err ) )
		ref->offset	+= delta;
		
	return( err );
}