aboutsummaryrefslogtreecommitdiff
path: root/src/unstable/newline.cpp
blob: b14b448cbdfecd86c5d443db43e3aafb8ea81b8f (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
61
62
63
64
65
66
67
68
/*
 * Copyright (C) 2007-2019 Xagasoft, All rights reserved.
 *
 * This file is part of the libbu++ library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#include "bu/newline.h"

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

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

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

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

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

    for( Bu::size 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;
}

Bu::size Bu::NewLine::write( const void *, Bu::size )
{
    return 0;
}