summaryrefslogtreecommitdiff
path: root/xfa
diff options
context:
space:
mode:
Diffstat (limited to 'xfa')
-rw-r--r--xfa/fde/xml/cfde_xmlsyntaxparser.cpp88
-rw-r--r--xfa/fde/xml/cfde_xmlsyntaxparser.h1
2 files changed, 46 insertions, 43 deletions
diff --git a/xfa/fde/xml/cfde_xmlsyntaxparser.cpp b/xfa/fde/xml/cfde_xmlsyntaxparser.cpp
index 116b2e5a67..9adf11be0f 100644
--- a/xfa/fde/xml/cfde_xmlsyntaxparser.cpp
+++ b/xfa/fde/xml/cfde_xmlsyntaxparser.cpp
@@ -93,7 +93,6 @@ CFDE_XMLSyntaxParser::CFDE_XMLSyntaxParser(
m_Start(0),
m_End(0),
m_iAllocStep(m_BlockBuffer.GetAllocStep()),
- m_iDataLength(m_BlockBuffer.GetDataLengthRef()),
m_pCurrentBlock(nullptr),
m_iIndexInBlock(0),
m_iTextDataLength(0),
@@ -166,8 +165,8 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() {
switch (m_syntaxParserState) {
case FDE_XmlSyntaxState::Text:
if (ch == L'<') {
- if (m_iDataLength > 0) {
- m_iTextDataLength = m_iDataLength;
+ if (!m_BlockBuffer.IsEmpty()) {
+ m_iTextDataLength = m_BlockBuffer.GetDataLength();
m_BlockBuffer.Reset(true);
std::tie(m_pCurrentBlock, m_iIndexInBlock) =
m_BlockBuffer.GetAvailableBlock();
@@ -209,22 +208,22 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() {
break;
case FDE_XmlSyntaxState::Target:
case FDE_XmlSyntaxState::Tag:
- if (!IsXMLNameChar(ch, m_iDataLength < 1)) {
- if (m_iDataLength < 1) {
+ if (!IsXMLNameChar(ch, m_BlockBuffer.IsEmpty())) {
+ if (m_BlockBuffer.IsEmpty()) {
m_syntaxParserResult = FDE_XmlSyntaxResult::Error;
return m_syntaxParserResult;
- } else {
- m_iTextDataLength = m_iDataLength;
- m_BlockBuffer.Reset(true);
- std::tie(m_pCurrentBlock, m_iIndexInBlock) =
- m_BlockBuffer.GetAvailableBlock();
- if (m_syntaxParserState != FDE_XmlSyntaxState::Target) {
- syntaxParserResult = FDE_XmlSyntaxResult::TagName;
- } else {
- syntaxParserResult = FDE_XmlSyntaxResult::TargetName;
- }
- m_syntaxParserState = FDE_XmlSyntaxState::AttriName;
}
+
+ m_iTextDataLength = m_BlockBuffer.GetDataLength();
+ m_BlockBuffer.Reset(true);
+ std::tie(m_pCurrentBlock, m_iIndexInBlock) =
+ m_BlockBuffer.GetAvailableBlock();
+ if (m_syntaxParserState != FDE_XmlSyntaxState::Target)
+ syntaxParserResult = FDE_XmlSyntaxResult::TagName;
+ else
+ syntaxParserResult = FDE_XmlSyntaxResult::TargetName;
+
+ m_syntaxParserState = FDE_XmlSyntaxState::AttriName;
} else {
if (m_iIndexInBlock == m_iAllocStep) {
std::tie(m_pCurrentBlock, m_iIndexInBlock) =
@@ -234,17 +233,17 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() {
}
}
m_pCurrentBlock[m_iIndexInBlock++] = ch;
- m_iDataLength++;
+ m_BlockBuffer.IncrementDataLength();
m_Start++;
}
break;
case FDE_XmlSyntaxState::AttriName:
- if (m_iDataLength < 1 && IsXMLWhiteSpace(ch)) {
+ if (m_BlockBuffer.IsEmpty() && IsXMLWhiteSpace(ch)) {
m_Start++;
break;
}
- if (!IsXMLNameChar(ch, m_iDataLength < 1)) {
- if (m_iDataLength < 1) {
+ if (!IsXMLNameChar(ch, m_BlockBuffer.IsEmpty())) {
+ if (m_BlockBuffer.IsEmpty()) {
if (m_CurNode.eNodeType == FDE_XMLNODE_Element) {
if (ch == L'>' || ch == L'/') {
m_syntaxParserState = FDE_XmlSyntaxState::BreakElement;
@@ -268,7 +267,7 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() {
break;
}
}
- m_iTextDataLength = m_iDataLength;
+ m_iTextDataLength = m_BlockBuffer.GetDataLength();
m_BlockBuffer.Reset(true);
std::tie(m_pCurrentBlock, m_iIndexInBlock) =
m_BlockBuffer.GetAvailableBlock();
@@ -284,7 +283,7 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() {
}
}
m_pCurrentBlock[m_iIndexInBlock++] = ch;
- m_iDataLength++;
+ m_BlockBuffer.IncrementDataLength();
m_Start++;
}
break;
@@ -325,7 +324,7 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() {
m_syntaxParserResult = FDE_XmlSyntaxResult::Error;
return m_syntaxParserResult;
}
- m_iTextDataLength = m_iDataLength;
+ m_iTextDataLength = m_BlockBuffer.GetDataLength();
m_wQuotationMark = 0;
m_BlockBuffer.Reset(true);
std::tie(m_pCurrentBlock, m_iIndexInBlock) =
@@ -347,10 +346,10 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() {
}
}
m_pCurrentBlock[m_iIndexInBlock++] = ch;
- m_iDataLength++;
+ m_BlockBuffer.IncrementDataLength();
m_syntaxParserState = FDE_XmlSyntaxState::TargetData;
- } else if (m_iDataLength > 0) {
- m_iTextDataLength = m_iDataLength;
+ } else if (!m_BlockBuffer.IsEmpty()) {
+ m_iTextDataLength = m_BlockBuffer.GetDataLength();
m_BlockBuffer.Reset(true);
std::tie(m_pCurrentBlock, m_iIndexInBlock) =
m_BlockBuffer.GetAvailableBlock();
@@ -389,7 +388,7 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() {
m_Start++;
break;
case FDE_XmlSyntaxState::CloseElement:
- if (!IsXMLNameChar(ch, m_iDataLength < 1)) {
+ if (!IsXMLNameChar(ch, m_BlockBuffer.IsEmpty())) {
if (ch == L'>') {
if (m_XMLNodeStack.empty()) {
m_syntaxParserResult = FDE_XmlSyntaxResult::Error;
@@ -403,7 +402,7 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() {
m_CurNode.eNodeType = FDE_XMLNODE_Unknown;
}
m_iCurrentNodeNum = m_CurNode.iNodeNum;
- m_iTextDataLength = m_iDataLength;
+ m_iTextDataLength = m_BlockBuffer.GetDataLength();
m_BlockBuffer.Reset(true);
std::tie(m_pCurrentBlock, m_iIndexInBlock) =
m_BlockBuffer.GetAvailableBlock();
@@ -422,7 +421,7 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() {
}
}
m_pCurrentBlock[m_iIndexInBlock++] = ch;
- m_iDataLength++;
+ m_BlockBuffer.IncrementDataLength();
}
m_Start++;
break;
@@ -444,7 +443,7 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() {
if (FXSYS_wcsnicmp(m_Buffer.data() + m_Start, L"]]>", 3) == 0) {
m_Start += 3;
syntaxParserResult = FDE_XmlSyntaxResult::CData;
- m_iTextDataLength = m_iDataLength;
+ m_iTextDataLength = m_BlockBuffer.GetDataLength();
m_BlockBuffer.Reset(true);
std::tie(m_pCurrentBlock, m_iIndexInBlock) =
m_BlockBuffer.GetAvailableBlock();
@@ -457,7 +456,7 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() {
return FDE_XmlSyntaxResult::Error;
}
m_pCurrentBlock[m_iIndexInBlock++] = ch;
- m_iDataLength++;
+ m_BlockBuffer.IncrementDataLength();
m_Start++;
}
break;
@@ -499,10 +498,10 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() {
if (ch == m_SkipChar) {
m_SkipStack.pop();
if (m_SkipStack.empty()) {
- if (m_iDataLength >= 9)
+ if (m_BlockBuffer.GetDataLength() >= 9)
(void)m_BlockBuffer.GetTextData(0, 7);
- m_iTextDataLength = m_iDataLength;
+ m_iTextDataLength = m_BlockBuffer.GetDataLength();
m_BlockBuffer.Reset(true);
std::tie(m_pCurrentBlock, m_iIndexInBlock) =
m_BlockBuffer.GetAvailableBlock();
@@ -522,7 +521,7 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() {
}
}
m_pCurrentBlock[m_iIndexInBlock++] = ch;
- m_iDataLength++;
+ m_BlockBuffer.IncrementDataLength();
}
m_Start++;
}
@@ -537,11 +536,11 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() {
break;
case FDE_XmlSyntaxState::TargetData:
if (IsXMLWhiteSpace(ch)) {
- if (m_iDataLength < 1) {
+ if (m_BlockBuffer.IsEmpty()) {
m_Start++;
break;
} else if (m_wQuotationMark == 0) {
- m_iTextDataLength = m_iDataLength;
+ m_iTextDataLength = m_BlockBuffer.GetDataLength();
m_wQuotationMark = 0;
m_BlockBuffer.Reset(true);
std::tie(m_pCurrentBlock, m_iIndexInBlock) =
@@ -559,7 +558,7 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() {
m_wQuotationMark = ch;
m_Start++;
} else if (ch == m_wQuotationMark) {
- m_iTextDataLength = m_iDataLength;
+ m_iTextDataLength = m_BlockBuffer.GetDataLength();
m_wQuotationMark = 0;
m_BlockBuffer.Reset(true);
std::tie(m_pCurrentBlock, m_iIndexInBlock) =
@@ -579,7 +578,7 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() {
}
}
m_pCurrentBlock[m_iIndexInBlock++] = ch;
- m_iDataLength++;
+ m_BlockBuffer.IncrementDataLength();
m_Start++;
}
break;
@@ -626,10 +625,11 @@ void CFDE_XMLSyntaxParser::ParseTextChar(wchar_t character) {
}
m_pCurrentBlock[m_iIndexInBlock++] = character;
- m_iDataLength++;
+ m_BlockBuffer.IncrementDataLength();
if (m_iEntityStart > -1 && character == L';') {
CFX_WideString csEntity = m_BlockBuffer.GetTextData(
- m_iEntityStart + 1, (m_iDataLength - 1) - m_iEntityStart - 1);
+ m_iEntityStart + 1,
+ m_BlockBuffer.GetDataLength() - 1 - m_iEntityStart - 1);
int32_t iLen = csEntity.GetLength();
if (iLen > 0) {
if (csEntity[0] == L'#') {
@@ -683,12 +683,16 @@ void CFDE_XMLSyntaxParser::ParseTextChar(wchar_t character) {
}
}
}
- m_BlockBuffer.DeleteTextChars(m_iDataLength - m_iEntityStart);
+ if (m_iEntityStart > 0 &&
+ m_BlockBuffer.GetDataLength() > static_cast<size_t>(m_iEntityStart)) {
+ m_BlockBuffer.DeleteTextChars(m_BlockBuffer.GetDataLength() -
+ m_iEntityStart);
+ }
std::tie(m_pCurrentBlock, m_iIndexInBlock) =
m_BlockBuffer.GetAvailableBlock();
m_iEntityStart = -1;
} else if (m_iEntityStart < 0 && character == L'&') {
- m_iEntityStart = m_iDataLength - 1;
+ m_iEntityStart = m_BlockBuffer.GetDataLength() - 1;
}
m_Start++;
}
diff --git a/xfa/fde/xml/cfde_xmlsyntaxparser.h b/xfa/fde/xml/cfde_xmlsyntaxparser.h
index 6fa310476e..9f1274fa83 100644
--- a/xfa/fde/xml/cfde_xmlsyntaxparser.h
+++ b/xfa/fde/xml/cfde_xmlsyntaxparser.h
@@ -113,7 +113,6 @@ class CFDE_XMLSyntaxParser {
std::stack<FDE_XMLNODE> m_XMLNodeStack;
CFX_BlockBuffer m_BlockBuffer;
int32_t m_iAllocStep;
- int32_t& m_iDataLength;
wchar_t* m_pCurrentBlock; // Pointer into CFX_BlockBuffer
int32_t m_iIndexInBlock;
int32_t m_iTextDataLength;