2019-07-21 13:26:02 +00:00
|
|
|
// Scintilla Lexer for X12
|
2021-02-21 04:53:09 +00:00
|
|
|
// @file LexX12.cxx
|
2019-07-21 13:26:02 +00:00
|
|
|
// Written by Iain Clarke, IMCSoft & Inobiz AB.
|
|
|
|
// X12 official documentation is behind a paywall, but there's a description of the syntax here:
|
|
|
|
// http://www.rawlinsecconsulting.com/x12tutorial/x12syn.html
|
|
|
|
// This code is subject to the same license terms as the rest of the scintilla project:
|
|
|
|
// The License.txt file describes the conditions under which this software may be distributed.
|
|
|
|
//
|
|
|
|
|
|
|
|
// Header order must match order in scripts/HeaderOrder.txt
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cctype>
|
|
|
|
|
2022-01-04 23:07:50 +00:00
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include "ILexer.h"
|
|
|
|
#include "Scintilla.h"
|
|
|
|
#include "SciLexer.h"
|
|
|
|
#include "LexerModule.h"
|
|
|
|
#include "DefaultLexer.h"
|
|
|
|
|
|
|
|
using namespace Scintilla;
|
2022-01-04 23:07:50 +00:00
|
|
|
using namespace Lexilla;
|
2019-07-21 13:26:02 +00:00
|
|
|
|
|
|
|
class LexerX12 : public DefaultLexer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
LexerX12();
|
|
|
|
virtual ~LexerX12() {} // virtual destructor, as we inherit from ILexer
|
|
|
|
|
2021-02-21 04:53:09 +00:00
|
|
|
static ILexer5 *Factory() {
|
2019-07-21 13:26:02 +00:00
|
|
|
return new LexerX12;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SCI_METHOD Version() const override
|
|
|
|
{
|
2021-02-21 04:53:09 +00:00
|
|
|
return lvRelease5;
|
2019-07-21 13:26:02 +00:00
|
|
|
}
|
|
|
|
void SCI_METHOD Release() override
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * SCI_METHOD PropertyNames() override
|
|
|
|
{
|
|
|
|
return "fold";
|
|
|
|
}
|
|
|
|
int SCI_METHOD PropertyType(const char *) override
|
|
|
|
{
|
|
|
|
return SC_TYPE_BOOLEAN; // Only one property!
|
|
|
|
}
|
|
|
|
const char * SCI_METHOD DescribeProperty(const char *name) override
|
|
|
|
{
|
|
|
|
if (!strcmp(name, "fold"))
|
|
|
|
return "Whether to apply folding to document or not";
|
2022-01-04 23:07:50 +00:00
|
|
|
return "";
|
2019-07-21 13:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override
|
|
|
|
{
|
|
|
|
if (!strcmp(key, "fold"))
|
|
|
|
{
|
|
|
|
m_bFold = strcmp(val, "0") ? true : false;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2021-02-21 04:53:09 +00:00
|
|
|
const char * SCI_METHOD PropertyGet(const char *) override {
|
|
|
|
return "";
|
|
|
|
}
|
2019-07-21 13:26:02 +00:00
|
|
|
const char * SCI_METHOD DescribeWordListSets() override
|
|
|
|
{
|
2022-01-04 23:07:50 +00:00
|
|
|
return "";
|
2019-07-21 13:26:02 +00:00
|
|
|
}
|
|
|
|
Sci_Position SCI_METHOD WordListSet(int, const char *) override
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override;
|
|
|
|
void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override;
|
|
|
|
void * SCI_METHOD PrivateCall(int, void *) override
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
struct Terminator
|
|
|
|
{
|
|
|
|
int Style = SCE_X12_BAD;
|
|
|
|
Sci_PositionU pos = 0;
|
|
|
|
Sci_PositionU length = 0;
|
|
|
|
int FoldChange = 0;
|
|
|
|
};
|
|
|
|
Terminator InitialiseFromISA(IDocument *pAccess);
|
|
|
|
Sci_PositionU FindPreviousSegmentStart(IDocument *pAccess, Sci_Position startPos) const;
|
|
|
|
Terminator DetectSegmentHeader(IDocument *pAccess, Sci_PositionU pos) const;
|
|
|
|
Terminator FindNextTerminator(IDocument *pAccess, Sci_PositionU pos, bool bJustSegmentTerminator = false) const;
|
|
|
|
|
2022-01-04 23:07:50 +00:00
|
|
|
bool m_bFold = false;
|
|
|
|
char m_SeparatorSubElement = 0;
|
|
|
|
char m_SeparatorElement = 0;
|
|
|
|
std::string m_SeparatorSegment; // might be multiple characters
|
|
|
|
std::string m_LineFeed;
|
2019-07-21 13:26:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
LexerModule lmX12(SCLEX_X12, LexerX12::Factory, "x12");
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2021-02-21 04:53:09 +00:00
|
|
|
LexerX12::LexerX12() : DefaultLexer("x12", SCLEX_X12)
|
2019-07-21 13:26:02 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void LexerX12::Lex(Sci_PositionU startPos, Sci_Position length, int, IDocument *pAccess)
|
|
|
|
{
|
|
|
|
Sci_PositionU posFinish = startPos + length;
|
|
|
|
|
|
|
|
Terminator T = InitialiseFromISA(pAccess);
|
|
|
|
|
|
|
|
if (T.Style == SCE_X12_BAD)
|
|
|
|
{
|
|
|
|
if (T.pos < startPos)
|
|
|
|
T.pos = startPos; // we may be colouring in batches.
|
|
|
|
pAccess->StartStyling(startPos);
|
|
|
|
pAccess->SetStyleFor(T.pos - startPos, SCE_X12_ENVELOPE);
|
|
|
|
pAccess->SetStyleFor(posFinish - T.pos, SCE_X12_BAD);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look backwards for a segment start or a document beginning
|
|
|
|
Sci_PositionU posCurrent = FindPreviousSegmentStart (pAccess, startPos);
|
|
|
|
|
|
|
|
// Style buffer, so we're not issuing loads of notifications
|
|
|
|
pAccess->StartStyling(posCurrent);
|
|
|
|
|
|
|
|
while (posCurrent < posFinish)
|
|
|
|
{
|
|
|
|
// Look for first element marker, so we can denote segment
|
|
|
|
T = DetectSegmentHeader(pAccess, posCurrent);
|
|
|
|
if (T.Style == SCE_X12_BAD)
|
|
|
|
break;
|
|
|
|
|
|
|
|
pAccess->SetStyleFor(T.pos - posCurrent, T.Style);
|
|
|
|
pAccess->SetStyleFor(T.length, SCE_X12_SEP_ELEMENT);
|
|
|
|
posCurrent = T.pos + T.length;
|
|
|
|
|
|
|
|
while (T.Style != SCE_X12_BAD && T.Style != SCE_X12_SEGMENTEND) // Break on bad or segment ending
|
|
|
|
{
|
2022-01-04 23:07:50 +00:00
|
|
|
T = FindNextTerminator(pAccess, posCurrent, false);
|
2019-07-21 13:26:02 +00:00
|
|
|
if (T.Style == SCE_X12_BAD)
|
|
|
|
break;
|
|
|
|
|
|
|
|
int Style = T.Style;
|
|
|
|
|
|
|
|
pAccess->SetStyleFor(T.pos - posCurrent, SCE_X12_DEFAULT);
|
|
|
|
pAccess->SetStyleFor(T.length, Style);
|
|
|
|
posCurrent = T.pos + T.length;
|
|
|
|
}
|
|
|
|
if (T.Style == SCE_X12_BAD)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pAccess->SetStyleFor(posFinish - posCurrent, SCE_X12_BAD);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LexerX12::Fold(Sci_PositionU startPos, Sci_Position length, int, IDocument *pAccess)
|
|
|
|
{
|
|
|
|
if (!m_bFold)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Are we even foldable?
|
2022-01-04 23:07:50 +00:00
|
|
|
// check for cr,lf,cr+lf.
|
|
|
|
if (m_LineFeed.empty())
|
2019-07-21 13:26:02 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
Sci_PositionU posFinish = startPos + length;
|
|
|
|
|
|
|
|
// Look backwards for a segment start or a document beginning
|
|
|
|
startPos = FindPreviousSegmentStart(pAccess, startPos);
|
|
|
|
Terminator T;
|
|
|
|
|
|
|
|
Sci_PositionU currLine = pAccess->LineFromPosition(startPos);
|
|
|
|
int levelCurrentStyle = SC_FOLDLEVELBASE;
|
2022-01-04 23:07:50 +00:00
|
|
|
int indentCurrent = 0;
|
2019-07-21 13:26:02 +00:00
|
|
|
if (currLine > 0)
|
2022-01-04 23:07:50 +00:00
|
|
|
{
|
2019-07-21 13:26:02 +00:00
|
|
|
levelCurrentStyle = pAccess->GetLevel(currLine - 1); // bottom 12 bits are level
|
2022-01-04 23:07:50 +00:00
|
|
|
indentCurrent = levelCurrentStyle & (SC_FOLDLEVELBASE - 1); // indent from previous line
|
|
|
|
Sci_PositionU posLine = pAccess->LineStart(currLine - 1);
|
|
|
|
T = DetectSegmentHeader(pAccess, posLine);
|
|
|
|
indentCurrent += T.FoldChange;
|
|
|
|
}
|
2019-07-21 13:26:02 +00:00
|
|
|
|
|
|
|
while (startPos < posFinish)
|
|
|
|
{
|
|
|
|
T = DetectSegmentHeader(pAccess, startPos);
|
|
|
|
int indentNext = indentCurrent + T.FoldChange;
|
|
|
|
if (indentNext < 0)
|
|
|
|
indentNext = 0;
|
|
|
|
|
|
|
|
levelCurrentStyle = (T.FoldChange > 0) ? (SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG) : SC_FOLDLEVELBASE;
|
|
|
|
|
|
|
|
currLine = pAccess->LineFromPosition(startPos);
|
|
|
|
pAccess->SetLevel(currLine, levelCurrentStyle | indentCurrent);
|
|
|
|
|
|
|
|
T = FindNextTerminator(pAccess, startPos, true);
|
2022-01-04 23:07:50 +00:00
|
|
|
|
|
|
|
if (T.Style == SCE_X12_BAD)
|
|
|
|
break;
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
startPos = T.pos + T.length;
|
|
|
|
indentCurrent = indentNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LexerX12::Terminator LexerX12::InitialiseFromISA(IDocument *pAccess)
|
|
|
|
{
|
|
|
|
Sci_Position length = pAccess->Length();
|
2022-01-04 23:07:50 +00:00
|
|
|
if (length <= 108)
|
2019-07-21 13:26:02 +00:00
|
|
|
return { SCE_X12_BAD, 0 };
|
|
|
|
|
2022-01-04 23:07:50 +00:00
|
|
|
pAccess->GetCharRange(&m_SeparatorElement, 3, 1);
|
|
|
|
pAccess->GetCharRange(&m_SeparatorSubElement, 104, 1);
|
|
|
|
|
2023-02-09 16:57:24 +00:00
|
|
|
// Look for GS, as that's the next segment. Anything between 105 and GS/IEA is our segment separator.
|
|
|
|
Sci_Position posNextSegment;
|
|
|
|
char bufSegment[3] = { 0 };
|
|
|
|
for (posNextSegment = 105; posNextSegment < length - 3; posNextSegment++)
|
2019-07-21 13:26:02 +00:00
|
|
|
{
|
2023-02-09 16:57:24 +00:00
|
|
|
pAccess->GetCharRange(bufSegment, posNextSegment, 3);
|
|
|
|
if (!memcmp (bufSegment, "GS", 2) || !memcmp(bufSegment, "IEA", 3))
|
2022-01-04 23:07:50 +00:00
|
|
|
{
|
2023-02-09 16:57:24 +00:00
|
|
|
m_SeparatorSegment.resize(posNextSegment - 105);
|
|
|
|
pAccess->GetCharRange(&m_SeparatorSegment.at(0), 105, posNextSegment - 105);
|
2022-01-04 23:07:50 +00:00
|
|
|
|
|
|
|
// Is some of that CR+LF?
|
|
|
|
size_t nPos = m_SeparatorSegment.find_last_not_of("\r\n");
|
|
|
|
m_LineFeed = m_SeparatorSegment.substr(nPos + 1);
|
|
|
|
m_SeparatorSegment = m_SeparatorSegment.substr(0, nPos + 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_SeparatorSegment.empty() && m_LineFeed.empty())
|
|
|
|
{
|
|
|
|
return { SCE_X12_BAD, 105 };
|
2019-07-21 13:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate we have an element separator, and it's not silly!
|
2022-01-04 23:07:50 +00:00
|
|
|
if (m_SeparatorElement == '\0' || m_SeparatorElement == '\n' || m_SeparatorElement == '\r')
|
2019-07-21 13:26:02 +00:00
|
|
|
return { SCE_X12_BAD, 3 };
|
|
|
|
|
|
|
|
// Validate we have an element separator, and it's not silly!
|
2022-01-04 23:07:50 +00:00
|
|
|
if (m_SeparatorSubElement == '\0' || m_SeparatorSubElement == '\n' || m_SeparatorSubElement == '\r')
|
2019-07-21 13:26:02 +00:00
|
|
|
return { SCE_X12_BAD, 103 };
|
2022-01-04 23:07:50 +00:00
|
|
|
if (m_SeparatorElement == m_SeparatorSubElement)
|
2019-07-21 13:26:02 +00:00
|
|
|
return { SCE_X12_BAD, 104 };
|
2022-01-04 23:07:50 +00:00
|
|
|
for (auto& c : m_SeparatorSegment)
|
|
|
|
{
|
|
|
|
if (m_SeparatorElement == c)
|
|
|
|
return { SCE_X12_BAD, 105 };
|
|
|
|
if (m_SeparatorSubElement == c)
|
|
|
|
return { SCE_X12_BAD, 105 };
|
|
|
|
}
|
2019-07-21 13:26:02 +00:00
|
|
|
|
|
|
|
// Check we have element markers at all the right places! ISA element has fixed entries.
|
2022-01-04 23:07:50 +00:00
|
|
|
std::vector<Sci_PositionU> ElementMarkers = { 3, 6, 17, 20, 31, 34, 50, 53, 69, 76, 81, 83, 89, 99, 101, 103 };
|
2019-07-21 13:26:02 +00:00
|
|
|
for (auto i : ElementMarkers)
|
|
|
|
{
|
2022-01-04 23:07:50 +00:00
|
|
|
char c;
|
2019-07-21 13:26:02 +00:00
|
|
|
pAccess->GetCharRange(&c, i, 1);
|
2022-01-04 23:07:50 +00:00
|
|
|
if (c != m_SeparatorElement)
|
2019-07-21 13:26:02 +00:00
|
|
|
return { SCE_X12_BAD, i };
|
|
|
|
}
|
|
|
|
// Check we have no element markers anywhere else!
|
|
|
|
for (Sci_PositionU i = 0; i < 105; i++)
|
|
|
|
{
|
|
|
|
if (std::find(ElementMarkers.begin(), ElementMarkers.end(), i) != ElementMarkers.end())
|
|
|
|
continue;
|
|
|
|
|
2022-01-04 23:07:50 +00:00
|
|
|
char c;
|
2019-07-21 13:26:02 +00:00
|
|
|
pAccess->GetCharRange(&c, i, 1);
|
2022-01-04 23:07:50 +00:00
|
|
|
if (c == m_SeparatorElement)
|
2019-07-21 13:26:02 +00:00
|
|
|
return { SCE_X12_BAD, i };
|
|
|
|
}
|
|
|
|
|
|
|
|
return { SCE_X12_ENVELOPE };
|
|
|
|
}
|
|
|
|
|
|
|
|
Sci_PositionU LexerX12::FindPreviousSegmentStart(IDocument *pAccess, Sci_Position startPos) const
|
|
|
|
{
|
2022-01-04 23:07:50 +00:00
|
|
|
Sci_PositionU length = pAccess->Length();
|
|
|
|
std::string bufTest = m_SeparatorSegment + m_LineFeed; // quick way of making the lengths the same
|
|
|
|
std::string bufCompare = bufTest;
|
2019-07-21 13:26:02 +00:00
|
|
|
|
2022-01-04 23:07:50 +00:00
|
|
|
for (; startPos > 0; startPos--)
|
2019-07-21 13:26:02 +00:00
|
|
|
{
|
2022-01-04 23:07:50 +00:00
|
|
|
if (startPos + bufTest.size() > length)
|
2019-07-21 13:26:02 +00:00
|
|
|
continue;
|
2022-01-04 23:07:50 +00:00
|
|
|
|
|
|
|
pAccess->GetCharRange(&bufTest.at(0), startPos, bufTest.size());
|
|
|
|
if (bufTest == bufCompare)
|
|
|
|
{
|
|
|
|
return startPos + bufTest.size();
|
|
|
|
}
|
2019-07-21 13:26:02 +00:00
|
|
|
}
|
|
|
|
// We didn't find a ', so just go with the beginning
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LexerX12::Terminator LexerX12::DetectSegmentHeader(IDocument *pAccess, Sci_PositionU pos) const
|
|
|
|
{
|
2022-01-04 23:07:50 +00:00
|
|
|
Sci_PositionU Length = pAccess->Length();
|
|
|
|
Length -= pos;
|
|
|
|
char c, Buf[4] = { 0 }; // max 3 + separator
|
|
|
|
for (Sci_PositionU posOffset = 0; posOffset < std::size(Buf) && posOffset < Length; posOffset++)
|
2019-07-21 13:26:02 +00:00
|
|
|
{
|
2022-01-04 23:07:50 +00:00
|
|
|
pAccess->GetCharRange(&c, pos + posOffset, 1);
|
|
|
|
if (c != m_SeparatorElement)
|
2019-07-21 13:26:02 +00:00
|
|
|
{
|
2022-01-04 23:07:50 +00:00
|
|
|
Buf[posOffset] = c;
|
2019-07-21 13:26:02 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-01-04 23:07:50 +00:00
|
|
|
|
|
|
|
// check for special segments, involved in folding start/stop.
|
|
|
|
if (memcmp(Buf, "ISA", 3) == 0)
|
|
|
|
return { SCE_X12_ENVELOPE, pos + posOffset, 1, +1 };
|
|
|
|
if (memcmp(Buf, "IEA", 3) == 0)
|
|
|
|
return { SCE_X12_ENVELOPE, pos + posOffset, 1, -1 };
|
|
|
|
if (memcmp(Buf, "GS", 2) == 0)
|
|
|
|
return { SCE_X12_FUNCTIONGROUP, pos + posOffset, 1, +1 };
|
|
|
|
if (memcmp(Buf, "GE", 2) == 0)
|
|
|
|
return { SCE_X12_FUNCTIONGROUP, pos + posOffset, 1, -1 };
|
|
|
|
if (memcmp(Buf, "ST", 2) == 0)
|
|
|
|
return { SCE_X12_TRANSACTIONSET, pos + posOffset, 1, +1 };
|
|
|
|
if (memcmp(Buf, "SE", 2) == 0)
|
|
|
|
return { SCE_X12_TRANSACTIONSET, pos + posOffset, 1, -1 };
|
|
|
|
return { SCE_X12_SEGMENTHEADER, pos + posOffset, 1, 0 };
|
2019-07-21 13:26:02 +00:00
|
|
|
}
|
|
|
|
return { SCE_X12_BAD, pos, 0, 0 };
|
|
|
|
}
|
|
|
|
|
|
|
|
LexerX12::Terminator LexerX12::FindNextTerminator(IDocument *pAccess, Sci_PositionU pos, bool bJustSegmentTerminator) const
|
|
|
|
{
|
|
|
|
char c;
|
2022-01-04 23:07:50 +00:00
|
|
|
Sci_PositionU length = pAccess->Length();
|
|
|
|
std::string bufTestSegment = m_SeparatorSegment; // quick way of making the lengths the same
|
|
|
|
std::string bufTestLineFeed = m_LineFeed; // quick way of making the lengths the same
|
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
|
2022-01-04 23:07:50 +00:00
|
|
|
while (pos < (Sci_PositionU)length)
|
2019-07-21 13:26:02 +00:00
|
|
|
{
|
|
|
|
pAccess->GetCharRange(&c, pos, 1);
|
2022-01-04 23:07:50 +00:00
|
|
|
if (pos + m_SeparatorSegment.size() > length)
|
|
|
|
bufTestSegment.clear(); // going up - so once we can't get this, we're done with the buffer.
|
|
|
|
else if (!bufTestSegment.empty())
|
|
|
|
pAccess->GetCharRange(&bufTestSegment.at(0), pos, bufTestSegment.size());
|
|
|
|
if (pos + m_LineFeed.size() > length)
|
|
|
|
bufTestLineFeed.clear(); // going up - so once we can't get this, we're done with the buffer.
|
|
|
|
else if (!bufTestLineFeed.empty())
|
|
|
|
pAccess->GetCharRange(&bufTestLineFeed.at(0), pos, bufTestLineFeed.size());
|
|
|
|
|
|
|
|
if (!bJustSegmentTerminator && c == m_SeparatorElement)
|
2019-07-21 13:26:02 +00:00
|
|
|
return { SCE_X12_SEP_ELEMENT, pos, 1 };
|
2022-01-04 23:07:50 +00:00
|
|
|
else if (!bJustSegmentTerminator && c == m_SeparatorSubElement)
|
2019-07-21 13:26:02 +00:00
|
|
|
return { SCE_X12_SEP_SUBELEMENT, pos, 1 };
|
2022-01-04 23:07:50 +00:00
|
|
|
else if (!m_SeparatorSegment.empty() && bufTestSegment == m_SeparatorSegment)
|
2019-07-21 13:26:02 +00:00
|
|
|
{
|
2022-01-04 23:07:50 +00:00
|
|
|
if (m_LineFeed.empty())
|
|
|
|
return { SCE_X12_SEGMENTEND, pos, m_SeparatorSegment.size() };
|
|
|
|
// is this the end?
|
|
|
|
if (pos + m_SeparatorSegment.size() == length)
|
|
|
|
return { SCE_X12_SEGMENTEND, pos, m_SeparatorSegment.size() };
|
|
|
|
// Check if we're followed by a linefeed.
|
|
|
|
if (pos + m_SeparatorSegment.size() + m_LineFeed.size() > length)
|
|
|
|
return { SCE_X12_BAD, pos };
|
|
|
|
bufTestSegment = m_LineFeed;
|
|
|
|
pAccess->GetCharRange(&bufTestSegment.at(0), pos + m_SeparatorSegment.size(), bufTestSegment.size());
|
|
|
|
if (bufTestSegment == m_LineFeed)
|
|
|
|
return { SCE_X12_SEGMENTEND, pos, m_SeparatorSegment.size() + m_LineFeed.size() };
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (m_SeparatorSegment.empty() && bufTestLineFeed == m_LineFeed)
|
|
|
|
{
|
|
|
|
return { SCE_X12_SEGMENTEND, pos, m_LineFeed.size() };
|
2019-07-21 13:26:02 +00:00
|
|
|
}
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return { SCE_X12_BAD, pos };
|
|
|
|
}
|