aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/utils/line_split.cpp
blob: 657d0edd9bf343aa6b176baae55b32e7b3b8659c (plain) (blame)
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
#include "line_split.h"

TLineSplitter::TLineSplitter(IInputStream& stream)
    : Stream_(stream)
{
}

size_t TLineSplitter::Next(TString& st) {
    st.clear();
    char c;
    size_t ret = 0;
    if (HasPendingLineChar_) {
        st.push_back(PendingLineChar_);
        HasPendingLineChar_ = false;
        ++ret;
    }

    while (Stream_.ReadChar(c)) {
        ++ret;
        if (c == '\n') {
            break;
        } else if (c == '\r') {
            if (Stream_.ReadChar(c)) {
                ++ret;
                if (c != '\n') {
                    --ret;
                    PendingLineChar_ = c;
                    HasPendingLineChar_ = true;
                }
            }

            break;
        } else {
            st.push_back(c);
        }
    }

    return ret;
}