-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCStringLineParser.cpp
90 lines (76 loc) · 1.58 KB
/
CStringLineParser.cpp
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// CStringLineParser.cpp: implementation of the CCStringLineParser class.
//
// $Id$
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "phreeqci2.h"
#include "CStringLineParser.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNAMIC(CCStringLineParser, CLineParser)
CCStringLineParser::CCStringLineParser(const CString& rString)
: m_rString(rString), m_nLineNumber(0), m_nextChar(0)
{
m_lastChar = m_rString.GetLength();
}
CCStringLineParser::~CCStringLineParser()
{
}
//
// returns:
// false if end-of-string was reached without reading any data.
// true otherwise
//
bool CCStringLineParser::GetNextLine(CString& rStr)
{
rStr.Empty();
if (m_nextChar >= m_lastChar)
{
return false;
}
int i;
bool bEol = false;
TCHAR c = 0;
for (i = m_nextChar; i < m_lastChar; ++i)
{
c = m_rString[i];
if ((c == _T('\n')) || (c == _T('\r')))
{
m_nLineNumber++;
bEol = true;
break;
}
}
rStr = CString((LPCTSTR)m_rString + m_nextChar, i - m_nextChar);
m_nextChar = i;
if (bEol)
{
// skip CR or LF
m_nextChar++;
if (c == _T('\r'))
{
if ((m_nextChar < m_lastChar) && (m_rString[m_nextChar] == '\n'))
{
// skip LF
m_nextChar++;
}
}
}
#ifdef _DEBUG
else
{
ASSERT(m_nextChar == m_lastChar);
}
#endif
return true;
}
int CCStringLineParser::GetLineNumber()
{
return m_nLineNumber;
}