summaryrefslogtreecommitdiff
path: root/src/newline.cpp
blob: 00c73f9423c1031b953bc0d536e6c1cfb8f5e4fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "bu/newline.h"

Bu::NewLine::NewLine( Bu::Stream &rNext ) :
	Bu::Filter( rNext ),
	bExChar( false )
{
}

Bu::NewLine::~NewLine()
{
}

void Bu::NewLine::start()
{
}

size_t Bu::NewLine::stop()
{
	return 0;
}

size_t Bu::NewLine::read( void *pBufV, size_t iAmnt )
{
	size_t iTotal = 0;
	size_t iOffset = 0;
	size_t iRead = rNext.read( pBufV, iAmnt );
	char *pBuf = (char *)pBufV;

	for( size_t i = 0; i < iRead; i++ )
	{
		if( pBuf[i] == '\r' )
		{
			pBuf[i+iOffset] = '\n';
			if( pBuf[i+1] == '\n' )
			{
				iOffset--;
			}
		}
		else if( pBuf[i] == '\n' )
		{
			pBuf[i+iOffset] = '\n';
			if( pBuf[i+1] == '\r' )
			{
				iOffset--;
			}
		}
		else if( iOffset )
		{
			pBuf[i+iOffset] = pBuf[i];
		}
	}

	iTotal += iRead + iOffset;
	return iTotal;
}

size_t Bu::NewLine::write( const void *pBuf, size_t iAmnt )
{
}