summaryrefslogtreecommitdiff
path: root/core/fxcrt/fx_xml_parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcrt/fx_xml_parser.cpp')
-rw-r--r--core/fxcrt/fx_xml_parser.cpp179
1 files changed, 93 insertions, 86 deletions
diff --git a/core/fxcrt/fx_xml_parser.cpp b/core/fxcrt/fx_xml_parser.cpp
index e6c3543378..f6b81dad93 100644
--- a/core/fxcrt/fx_xml_parser.cpp
+++ b/core/fxcrt/fx_xml_parser.cpp
@@ -13,6 +13,62 @@
#include "third_party/base/ptr_util.h"
#include "third_party/base/stl_util.h"
+namespace {
+
+#define FXCRTM_XML_CHARTYPE_Normal 0x00
+#define FXCRTM_XML_CHARTYPE_SpaceChar 0x01
+#define FXCRTM_XML_CHARTYPE_Letter 0x02
+#define FXCRTM_XML_CHARTYPE_Digital 0x04
+#define FXCRTM_XML_CHARTYPE_NameIntro 0x08
+#define FXCRTM_XML_CHARTYPE_NameChar 0x10
+#define FXCRTM_XML_CHARTYPE_HexDigital 0x20
+#define FXCRTM_XML_CHARTYPE_HexLowerLetter 0x40
+#define FXCRTM_XML_CHARTYPE_HexUpperLetter 0x60
+#define FXCRTM_XML_CHARTYPE_HexChar 0x60
+
+const uint8_t g_FXCRT_XML_ByteTypes[256] = {
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,
+ 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x08, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x7A, 0x7A, 0x7A, 0x7A, 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A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A,
+ 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A,
+ 0x1A, 0x1A, 0x01, 0x01,
+};
+
+bool g_FXCRT_XML_IsWhiteSpace(uint8_t ch) {
+ return !!(g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_SpaceChar);
+}
+
+bool g_FXCRT_XML_IsDigital(uint8_t ch) {
+ return !!(g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_Digital);
+}
+
+bool g_FXCRT_XML_IsNameIntro(uint8_t ch) {
+ return !!(g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_NameIntro);
+}
+
+bool g_FXCRT_XML_IsNameChar(uint8_t ch) {
+ return !!(g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_NameChar);
+}
+
+} // namespace
+
CXML_DataBufAcc::CXML_DataBufAcc(const uint8_t* pBuffer, size_t size)
: m_pBuffer(pBuffer), m_dwSize(size), m_dwCurPos(0) {}
@@ -22,7 +78,7 @@ void CXML_DataBufAcc::Release() {
delete this;
}
-FX_BOOL CXML_DataBufAcc::IsEOF() {
+bool CXML_DataBufAcc::IsEOF() {
return m_dwCurPos >= m_dwSize;
}
@@ -34,15 +90,15 @@ size_t CXML_DataBufAcc::ReadBlock(void* buffer, size_t size) {
return 0;
}
-FX_BOOL CXML_DataBufAcc::ReadNextBlock(FX_BOOL bRestart) {
- if (bRestart) {
+bool CXML_DataBufAcc::ReadNextBlock(bool bRestart) {
+ if (bRestart)
m_dwCurPos = 0;
- }
+
if (m_dwCurPos < m_dwSize) {
m_dwCurPos = m_dwSize;
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
const uint8_t* CXML_DataBufAcc::GetBlockBuffer() {
@@ -70,7 +126,7 @@ void CXML_DataStmAcc::Release() {
delete this;
}
-FX_BOOL CXML_DataStmAcc::IsEOF() {
+bool CXML_DataStmAcc::IsEOF() {
return m_nStart + (FX_FILESIZE)m_dwSize >= m_pFileRead->GetSize();
}
@@ -82,21 +138,21 @@ size_t CXML_DataStmAcc::ReadBlock(void* buffer, size_t size) {
return 0;
}
-FX_BOOL CXML_DataStmAcc::ReadNextBlock(FX_BOOL bRestart) {
- if (bRestart) {
+bool CXML_DataStmAcc::ReadNextBlock(bool bRestart) {
+ if (bRestart)
m_nStart = 0;
- }
+
FX_FILESIZE nLength = m_pFileRead->GetSize();
m_nStart += (FX_FILESIZE)m_dwSize;
- if (m_nStart >= nLength) {
- return FALSE;
- }
+ if (m_nStart >= nLength)
+ return false;
+
static const FX_FILESIZE FX_XMLDATASTREAM_BufferSize = 32 * 1024;
m_dwSize = static_cast<size_t>(
std::min(FX_XMLDATASTREAM_BufferSize, nLength - m_nStart));
- if (!m_pBuffer) {
+ if (!m_pBuffer)
m_pBuffer = FX_Alloc(uint8_t, m_dwSize);
- }
+
return m_pFileRead->ReadBlock(m_pBuffer, m_nStart, m_dwSize);
}
@@ -128,94 +184,45 @@ CXML_Parser::~CXML_Parser() {
}
}
-FX_BOOL CXML_Parser::Init(uint8_t* pBuffer, size_t size) {
+bool CXML_Parser::Init(uint8_t* pBuffer, size_t size) {
m_pDataAcc = new CXML_DataBufAcc(pBuffer, size);
- return Init(TRUE);
+ return Init(true);
}
-FX_BOOL CXML_Parser::Init(IFX_SeekableReadStream* pFileRead) {
+
+bool CXML_Parser::Init(IFX_SeekableReadStream* pFileRead) {
m_pDataAcc = new CXML_DataStmAcc(pFileRead);
- return Init(TRUE);
+ return Init(true);
}
-FX_BOOL CXML_Parser::Init(IFX_BufferRead* pBuffer) {
- if (!pBuffer) {
- return FALSE;
- }
+
+bool CXML_Parser::Init(IFX_BufferRead* pBuffer) {
+ if (!pBuffer)
+ return false;
+
m_pDataAcc = pBuffer;
- return Init(FALSE);
+ return Init(false);
}
-FX_BOOL CXML_Parser::Init(FX_BOOL bOwndedStream) {
+
+bool CXML_Parser::Init(bool bOwndedStream) {
m_bOwnedStream = bOwndedStream;
m_nOffset = 0;
return ReadNextBlock();
}
-FX_BOOL CXML_Parser::ReadNextBlock() {
- if (!m_pDataAcc->ReadNextBlock()) {
- return FALSE;
- }
+
+bool CXML_Parser::ReadNextBlock() {
+ if (!m_pDataAcc->ReadNextBlock())
+ return false;
+
m_pBuffer = m_pDataAcc->GetBlockBuffer();
m_dwBufferSize = m_pDataAcc->GetBlockSize();
m_nBufferOffset = m_pDataAcc->GetBlockOffset();
m_dwIndex = 0;
return m_dwBufferSize > 0;
}
-FX_BOOL CXML_Parser::IsEOF() {
- if (!m_pDataAcc->IsEOF()) {
- return FALSE;
- }
- return m_dwIndex >= m_dwBufferSize;
-}
-#define FXCRTM_XML_CHARTYPE_Normal 0x00
-#define FXCRTM_XML_CHARTYPE_SpaceChar 0x01
-#define FXCRTM_XML_CHARTYPE_Letter 0x02
-#define FXCRTM_XML_CHARTYPE_Digital 0x04
-#define FXCRTM_XML_CHARTYPE_NameIntro 0x08
-#define FXCRTM_XML_CHARTYPE_NameChar 0x10
-#define FXCRTM_XML_CHARTYPE_HexDigital 0x20
-#define FXCRTM_XML_CHARTYPE_HexLowerLetter 0x40
-#define FXCRTM_XML_CHARTYPE_HexUpperLetter 0x60
-#define FXCRTM_XML_CHARTYPE_HexChar 0x60
-uint8_t g_FXCRT_XML_ByteTypes[256] = {
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,
- 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x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A, 0x1A,
- 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A,
- 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A,
- 0x1A, 0x1A, 0x01, 0x01,
-};
-FX_BOOL g_FXCRT_XML_IsWhiteSpace(uint8_t ch) {
- return (g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_SpaceChar) != 0;
-}
-FX_BOOL g_FXCRT_XML_IsLetter(uint8_t ch) {
- return (g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_Letter) != 0;
-}
-FX_BOOL g_FXCRT_XML_IsDigital(uint8_t ch) {
- return (g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_Digital) != 0;
-}
-FX_BOOL g_FXCRT_XML_IsNameIntro(uint8_t ch) {
- return (g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_NameIntro) != 0;
-}
-FX_BOOL g_FXCRT_XML_IsNameChar(uint8_t ch) {
- return (g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_NameChar) != 0;
-}
-FX_BOOL g_FXCRT_XML_IsHexChar(uint8_t ch) {
- return (g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_HexChar) != 0;
+
+bool CXML_Parser::IsEOF() {
+ return m_pDataAcc->IsEOF() && m_dwIndex >= m_dwBufferSize;
}
+
void CXML_Parser::SkipWhiteSpaces() {
m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex;
if (IsEOF()) {