CString
CMSWindowsClipboardAnyTextConverter::convertLinefeedToWin32(
				const CString& src) const
{
	// note -- we assume src is a valid UTF-8 string

	// count newlines in string
	UInt32 numNewlines = 0;
	UInt32 n = (UInt32)src.size();
	for (const char* scan = src.c_str(); n > 0; ++scan, --n) {
		if (*scan == '\n') {
			++numNewlines;
		}
	}
	if (numNewlines == 0) {
		return src;
	}

	// allocate new string
	CString dst;
	dst.reserve(src.size() + numNewlines);

	// copy string, converting newlines
	n = (UInt32)src.size();
	for (const char* scan = src.c_str(); n > 0; ++scan, --n) {
		if (scan[0] == '\n') {
			dst += '\r';
		}
		dst += scan[0];
	}

	return dst;
}
CString
CMSWindowsClipboardAnyTextConverter::convertLinefeedToUnix(
				const CString& src) const
{
	// count newlines in string
	UInt32 numNewlines = 0;
	UInt32 n = (UInt32)src.size();
	for (const char* scan = src.c_str(); n > 0; ++scan, --n) {
		if (scan[0] == '\r' && scan[1] == '\n') {
			++numNewlines;
		}
	}
	if (numNewlines == 0) {
		return src;
	}

	// allocate new string
	CString dst;
	dst.reserve(src.size());

	// copy string, converting newlines
	n = (UInt32)src.size();
	for (const char* scan = src.c_str(); n > 0; ++scan, --n) {
		if (scan[0] != '\r' || scan[1] != '\n') {
			dst += scan[0];
		}
	}

	return dst;
}
Example #3
0
int RageFileObj::Read( CString &sBuffer, int iBytes )
{
	sBuffer.reserve( iBytes != -1? iBytes: this->GetFileSize() );

	int iRet = 0;
	char buf[4096];
	while( iBytes == -1 || iRet < iBytes )
	{
		int ToRead = sizeof(buf);
		if( iBytes != -1 )
			ToRead  = min( ToRead, iBytes-iRet );

		const int iGot = Read( buf, ToRead );
		if( iGot == 0 )
			break;
		if( iGot == -1 )
			return -1;

		sBuffer.append( buf, iGot );
		iRet += iGot;
	}

	return iRet;
}