| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "../../include/fxcrt/fx_xml.h" | 7 #include "../../include/fxcrt/fx_xml.h" |
| 8 #include "xml_int.h" | 8 #include "xml_int.h" |
| 9 CXML_Parser::~CXML_Parser() | 9 CXML_Parser::~CXML_Parser() |
| 10 { | 10 { |
| 11 if (m_bOwnedStream) { | 11 if (m_bOwnedStream) { |
| 12 m_pDataAcc->Release(); | 12 m_pDataAcc->Release(); |
| 13 } | 13 } |
| 14 } | 14 } |
| 15 FX_BOOL CXML_Parser::Init(uint8_t* pBuffer, size_t size) | 15 bool CXML_Parser::Init(uint8_t* pBuffer, size_t size) |
| 16 { | 16 { |
| 17 m_pDataAcc = new CXML_DataBufAcc(pBuffer, size); | 17 m_pDataAcc = new CXML_DataBufAcc(pBuffer, size); |
| 18 return Init(TRUE); | 18 return Init(true); |
| 19 } | 19 } |
| 20 FX_BOOL CXML_Parser::Init(IFX_FileRead *pFileRead) | 20 bool CXML_Parser::Init(IFX_FileRead *pFileRead) |
| 21 { | 21 { |
| 22 m_pDataAcc = new CXML_DataStmAcc(pFileRead); | 22 m_pDataAcc = new CXML_DataStmAcc(pFileRead); |
| 23 return Init(TRUE); | 23 return Init(true); |
| 24 } | 24 } |
| 25 FX_BOOL CXML_Parser::Init(IFX_BufferRead *pBuffer) | 25 bool CXML_Parser::Init(IFX_BufferRead *pBuffer) |
| 26 { | 26 { |
| 27 if (!pBuffer) { | 27 if (!pBuffer) { |
| 28 return FALSE; | 28 return false; |
| 29 } | 29 } |
| 30 m_pDataAcc = pBuffer; | 30 m_pDataAcc = pBuffer; |
| 31 return Init(FALSE); | 31 return Init(false); |
| 32 } | 32 } |
| 33 FX_BOOL CXML_Parser::Init(FX_BOOL bOwndedStream) | 33 bool CXML_Parser::Init(bool bOwndedStream) |
| 34 { | 34 { |
| 35 m_bOwnedStream = bOwndedStream; | 35 m_bOwnedStream = bOwndedStream; |
| 36 m_nOffset = 0; | 36 m_nOffset = 0; |
| 37 return ReadNextBlock(); | 37 return ReadNextBlock(); |
| 38 } | 38 } |
| 39 FX_BOOL CXML_Parser::ReadNextBlock() | 39 bool CXML_Parser::ReadNextBlock() |
| 40 { | 40 { |
| 41 if (!m_pDataAcc->ReadNextBlock()) { | 41 if (!m_pDataAcc->ReadNextBlock()) { |
| 42 return FALSE; | 42 return false; |
| 43 } | 43 } |
| 44 m_pBuffer = m_pDataAcc->GetBlockBuffer(); | 44 m_pBuffer = m_pDataAcc->GetBlockBuffer(); |
| 45 m_dwBufferSize = m_pDataAcc->GetBlockSize(); | 45 m_dwBufferSize = m_pDataAcc->GetBlockSize(); |
| 46 m_nBufferOffset = m_pDataAcc->GetBlockOffset(); | 46 m_nBufferOffset = m_pDataAcc->GetBlockOffset(); |
| 47 m_dwIndex = 0; | 47 m_dwIndex = 0; |
| 48 return m_dwBufferSize > 0; | 48 return m_dwBufferSize > 0; |
| 49 } | 49 } |
| 50 FX_BOOL CXML_Parser::IsEOF() | 50 bool CXML_Parser::IsEOF() |
| 51 { | 51 { |
| 52 if (!m_pDataAcc->IsEOF()) { | 52 if (!m_pDataAcc->IsEOF()) { |
| 53 return FALSE; | 53 return false; |
| 54 } | 54 } |
| 55 return m_dwIndex >= m_dwBufferSize; | 55 return m_dwIndex >= m_dwBufferSize; |
| 56 } | 56 } |
| 57 #define FXCRTM_XML_CHARTYPE_Normal 0x00 | 57 #define FXCRTM_XML_CHARTYPE_Normal 0x00 |
| 58 #define FXCRTM_XML_CHARTYPE_SpaceChar 0x01 | 58 #define FXCRTM_XML_CHARTYPE_SpaceChar 0x01 |
| 59 #define FXCRTM_XML_CHARTYPE_Letter 0x02 | 59 #define FXCRTM_XML_CHARTYPE_Letter 0x02 |
| 60 #define FXCRTM_XML_CHARTYPE_Digital 0x04 | 60 #define FXCRTM_XML_CHARTYPE_Digital 0x04 |
| 61 #define FXCRTM_XML_CHARTYPE_NameIntro 0x08 | 61 #define FXCRTM_XML_CHARTYPE_NameIntro 0x08 |
| 62 #define FXCRTM_XML_CHARTYPE_NameChar 0x10 | 62 #define FXCRTM_XML_CHARTYPE_NameChar 0x10 |
| 63 #define FXCRTM_XML_CHARTYPE_HexDigital 0x20 | 63 #define FXCRTM_XML_CHARTYPE_HexDigital 0x20 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 75 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x00, 0x00
, 0x00, 0x00, 0x00, | 75 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x00, 0x00
, 0x00, 0x00, 0x00, |
| 76 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A
, 0x1A, 0x1A, 0x1A, | 76 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A
, 0x1A, 0x1A, 0x1A, |
| 77 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A
, 0x1A, 0x1A, 0x1A, | 77 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A
, 0x1A, 0x1A, 0x1A, |
| 78 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A
, 0x1A, 0x1A, 0x1A, | 78 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A
, 0x1A, 0x1A, 0x1A, |
| 79 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A
, 0x1A, 0x1A, 0x1A, | 79 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A
, 0x1A, 0x1A, 0x1A, |
| 80 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A
, 0x1A, 0x1A, 0x1A, | 80 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A
, 0x1A, 0x1A, 0x1A, |
| 81 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A
, 0x1A, 0x1A, 0x1A, | 81 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A
, 0x1A, 0x1A, 0x1A, |
| 82 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A
, 0x1A, 0x1A, 0x1A, | 82 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A
, 0x1A, 0x1A, 0x1A, |
| 83 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A
, 0x1A, 0x01, 0x01, | 83 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A
, 0x1A, 0x01, 0x01, |
| 84 }; | 84 }; |
| 85 FX_BOOL g_FXCRT_XML_IsWhiteSpace(uint8_t ch) | 85 bool g_FXCRT_XML_IsWhiteSpace(uint8_t ch) |
| 86 { | 86 { |
| 87 return (g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_SpaceChar) != 0; | 87 return (g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_SpaceChar) != 0; |
| 88 } | 88 } |
| 89 FX_BOOL g_FXCRT_XML_IsLetter(uint8_t ch) | 89 bool g_FXCRT_XML_IsLetter(uint8_t ch) |
| 90 { | 90 { |
| 91 return (g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_Letter) != 0; | 91 return (g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_Letter) != 0; |
| 92 } | 92 } |
| 93 FX_BOOL g_FXCRT_XML_IsDigital(uint8_t ch) | 93 bool g_FXCRT_XML_IsDigital(uint8_t ch) |
| 94 { | 94 { |
| 95 return (g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_Digital) != 0; | 95 return (g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_Digital) != 0; |
| 96 } | 96 } |
| 97 FX_BOOL g_FXCRT_XML_IsNameIntro(uint8_t ch) | 97 bool g_FXCRT_XML_IsNameIntro(uint8_t ch) |
| 98 { | 98 { |
| 99 return (g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_NameIntro) != 0; | 99 return (g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_NameIntro) != 0; |
| 100 } | 100 } |
| 101 FX_BOOL g_FXCRT_XML_IsNameChar(uint8_t ch) | 101 bool g_FXCRT_XML_IsNameChar(uint8_t ch) |
| 102 { | 102 { |
| 103 return (g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_NameChar) != 0; | 103 return (g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_NameChar) != 0; |
| 104 } | 104 } |
| 105 FX_BOOL g_FXCRT_XML_IsHexChar(uint8_t ch) | 105 bool g_FXCRT_XML_IsHexChar(uint8_t ch) |
| 106 { | 106 { |
| 107 return (g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_HexChar) != 0; | 107 return (g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_HexChar) != 0; |
| 108 } | 108 } |
| 109 void CXML_Parser::SkipWhiteSpaces() | 109 void CXML_Parser::SkipWhiteSpaces() |
| 110 { | 110 { |
| 111 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; | 111 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; |
| 112 if (IsEOF()) { | 112 if (IsEOF()) { |
| 113 return; | 113 return; |
| 114 } | 114 } |
| 115 do { | 115 do { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 decoder.Input(ch); | 303 decoder.Input(ch); |
| 304 } | 304 } |
| 305 } | 305 } |
| 306 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; | 306 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; |
| 307 if (ch == mark || m_dwIndex < m_dwBufferSize || IsEOF()) { | 307 if (ch == mark || m_dwIndex < m_dwBufferSize || IsEOF()) { |
| 308 break; | 308 break; |
| 309 } | 309 } |
| 310 } while (ReadNextBlock()); | 310 } while (ReadNextBlock()); |
| 311 value = decoder.GetResult(); | 311 value = decoder.GetResult(); |
| 312 } | 312 } |
| 313 void CXML_Parser::GetTagName(CFX_ByteString &space, CFX_ByteString &name, FX_BOO
L &bEndTag, FX_BOOL bStartTag) | 313 void CXML_Parser::GetTagName(CFX_ByteString &space, CFX_ByteString &name, bool &
bEndTag, bool bStartTag) |
| 314 { | 314 { |
| 315 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; | 315 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; |
| 316 if (IsEOF()) { | 316 if (IsEOF()) { |
| 317 return; | 317 return; |
| 318 } | 318 } |
| 319 bEndTag = FALSE; | 319 bEndTag = false; |
| 320 uint8_t ch; | 320 uint8_t ch; |
| 321 int32_t iState = bStartTag ? 1 : 0; | 321 int32_t iState = bStartTag ? 1 : 0; |
| 322 do { | 322 do { |
| 323 while (m_dwIndex < m_dwBufferSize) { | 323 while (m_dwIndex < m_dwBufferSize) { |
| 324 ch = m_pBuffer[m_dwIndex]; | 324 ch = m_pBuffer[m_dwIndex]; |
| 325 switch (iState) { | 325 switch (iState) { |
| 326 case 0: | 326 case 0: |
| 327 m_dwIndex ++; | 327 m_dwIndex ++; |
| 328 if (ch != '<') { | 328 if (ch != '<') { |
| 329 break; | 329 break; |
| 330 } | 330 } |
| 331 iState = 1; | 331 iState = 1; |
| 332 break; | 332 break; |
| 333 case 1: | 333 case 1: |
| 334 if (ch == '?') { | 334 if (ch == '?') { |
| 335 m_dwIndex ++; | 335 m_dwIndex ++; |
| 336 SkipLiterals(FX_BSTRC("?>")); | 336 SkipLiterals(FX_BSTRC("?>")); |
| 337 iState = 0; | 337 iState = 0; |
| 338 break; | 338 break; |
| 339 } else if (ch == '!') { | 339 } else if (ch == '!') { |
| 340 m_dwIndex ++; | 340 m_dwIndex ++; |
| 341 SkipLiterals(FX_BSTRC("-->")); | 341 SkipLiterals(FX_BSTRC("-->")); |
| 342 iState = 0; | 342 iState = 0; |
| 343 break; | 343 break; |
| 344 } | 344 } |
| 345 if (ch == '/') { | 345 if (ch == '/') { |
| 346 m_dwIndex ++; | 346 m_dwIndex ++; |
| 347 GetName(space, name); | 347 GetName(space, name); |
| 348 bEndTag = TRUE; | 348 bEndTag = true; |
| 349 } else { | 349 } else { |
| 350 GetName(space, name); | 350 GetName(space, name); |
| 351 bEndTag = FALSE; | 351 bEndTag = false; |
| 352 } | 352 } |
| 353 return; | 353 return; |
| 354 } | 354 } |
| 355 } | 355 } |
| 356 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; | 356 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; |
| 357 if (m_dwIndex < m_dwBufferSize || IsEOF()) { | 357 if (m_dwIndex < m_dwBufferSize || IsEOF()) { |
| 358 break; | 358 break; |
| 359 } | 359 } |
| 360 } while (ReadNextBlock()); | 360 } while (ReadNextBlock()); |
| 361 } | 361 } |
| 362 CXML_Element* CXML_Parser::ParseElement(CXML_Element* pParent, FX_BOOL bStartTag
) | 362 CXML_Element* CXML_Parser::ParseElement(CXML_Element* pParent, bool bStartTag) |
| 363 { | 363 { |
| 364 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; | 364 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; |
| 365 if (IsEOF()) { | 365 if (IsEOF()) { |
| 366 return NULL; | 366 return NULL; |
| 367 } | 367 } |
| 368 CFX_ByteString tag_name, tag_space; | 368 CFX_ByteString tag_name, tag_space; |
| 369 FX_BOOL bEndTag; | 369 bool bEndTag; |
| 370 GetTagName(tag_space, tag_name, bEndTag, bStartTag); | 370 GetTagName(tag_space, tag_name, bEndTag, bStartTag); |
| 371 if (tag_name.IsEmpty() || bEndTag) { | 371 if (tag_name.IsEmpty() || bEndTag) { |
| 372 return NULL; | 372 return NULL; |
| 373 } | 373 } |
| 374 CXML_Element* pElement = new CXML_Element; | 374 CXML_Element* pElement = new CXML_Element; |
| 375 pElement->m_pParent = pParent; | 375 pElement->m_pParent = pParent; |
| 376 pElement->SetTag(tag_space, tag_name); | 376 pElement->SetTag(tag_space, tag_name); |
| 377 do { | 377 do { |
| 378 CFX_ByteString attr_space, attr_name; | 378 CFX_ByteString attr_space, attr_name; |
| 379 while (m_dwIndex < m_dwBufferSize) { | 379 while (m_dwIndex < m_dwBufferSize) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; | 420 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; |
| 421 delete pElement; | 421 delete pElement; |
| 422 return NULL; | 422 return NULL; |
| 423 } | 423 } |
| 424 SkipWhiteSpaces(); | 424 SkipWhiteSpaces(); |
| 425 if (IsEOF()) { | 425 if (IsEOF()) { |
| 426 return pElement; | 426 return pElement; |
| 427 } | 427 } |
| 428 CFX_UTF8Decoder decoder; | 428 CFX_UTF8Decoder decoder; |
| 429 CFX_WideTextBuf content; | 429 CFX_WideTextBuf content; |
| 430 FX_BOOL bCDATA = FALSE; | 430 bool bCDATA = false; |
| 431 int32_t iState = 0; | 431 int32_t iState = 0; |
| 432 do { | 432 do { |
| 433 while (m_dwIndex < m_dwBufferSize) { | 433 while (m_dwIndex < m_dwBufferSize) { |
| 434 ch = m_pBuffer[m_dwIndex ++]; | 434 ch = m_pBuffer[m_dwIndex ++]; |
| 435 switch (iState) { | 435 switch (iState) { |
| 436 case 0: | 436 case 0: |
| 437 if (ch == '<') { | 437 if (ch == '<') { |
| 438 iState = 1; | 438 iState = 1; |
| 439 } else if (ch == '&') { | 439 } else if (ch == '&') { |
| 440 decoder.ClearStatus(); | 440 decoder.ClearStatus(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 458 iState = 10; | 458 iState = 10; |
| 459 } else { | 459 } else { |
| 460 content << decoder.GetResult(); | 460 content << decoder.GetResult(); |
| 461 CFX_WideString dataStr = content.GetWideString(); | 461 CFX_WideString dataStr = content.GetWideString(); |
| 462 if (!bCDATA && !m_bSaveSpaceChars) { | 462 if (!bCDATA && !m_bSaveSpaceChars) { |
| 463 dataStr.TrimRight(L" \t\r\n"); | 463 dataStr.TrimRight(L" \t\r\n"); |
| 464 } | 464 } |
| 465 InsertContentSegment(bCDATA, dataStr, pElement); | 465 InsertContentSegment(bCDATA, dataStr, pElement); |
| 466 content.Clear(); | 466 content.Clear(); |
| 467 decoder.Clear(); | 467 decoder.Clear(); |
| 468 bCDATA = FALSE; | 468 bCDATA = false; |
| 469 iState = 0; | 469 iState = 0; |
| 470 m_dwIndex --; | 470 m_dwIndex --; |
| 471 CXML_Element* pSubElement = ParseElement(pElement, TRUE)
; | 471 CXML_Element* pSubElement = ParseElement(pElement, true)
; |
| 472 if (pSubElement == NULL) { | 472 if (pSubElement == NULL) { |
| 473 break; | 473 break; |
| 474 } | 474 } |
| 475 pSubElement->m_pParent = pElement; | 475 pSubElement->m_pParent = pElement; |
| 476 pElement->m_Children.Add((void*)CXML_Element::Element); | 476 pElement->m_Children.Add((void*)CXML_Element::Element); |
| 477 pElement->m_Children.Add(pSubElement); | 477 pElement->m_Children.Add(pSubElement); |
| 478 SkipWhiteSpaces(); | 478 SkipWhiteSpaces(); |
| 479 } | 479 } |
| 480 break; | 480 break; |
| 481 case 2: | 481 case 2: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 502 } | 502 } |
| 503 } while (ReadNextBlock()); | 503 } while (ReadNextBlock()); |
| 504 content << decoder.GetResult(); | 504 content << decoder.GetResult(); |
| 505 CFX_WideString dataStr = content.GetWideString(); | 505 CFX_WideString dataStr = content.GetWideString(); |
| 506 if (!m_bSaveSpaceChars) { | 506 if (!m_bSaveSpaceChars) { |
| 507 dataStr.TrimRight(L" \t\r\n"); | 507 dataStr.TrimRight(L" \t\r\n"); |
| 508 } | 508 } |
| 509 InsertContentSegment(bCDATA, dataStr, pElement); | 509 InsertContentSegment(bCDATA, dataStr, pElement); |
| 510 content.Clear(); | 510 content.Clear(); |
| 511 decoder.Clear(); | 511 decoder.Clear(); |
| 512 bCDATA = FALSE; | 512 bCDATA = false; |
| 513 return pElement; | 513 return pElement; |
| 514 } | 514 } |
| 515 void CXML_Parser::InsertContentSegment(FX_BOOL bCDATA, const CFX_WideStringC& co
ntent, CXML_Element* pElement) | 515 void CXML_Parser::InsertContentSegment(bool bCDATA, const CFX_WideStringC& conte
nt, CXML_Element* pElement) |
| 516 { | 516 { |
| 517 if (content.IsEmpty()) { | 517 if (content.IsEmpty()) { |
| 518 return; | 518 return; |
| 519 } | 519 } |
| 520 CXML_Content* pContent = new CXML_Content; | 520 CXML_Content* pContent = new CXML_Content; |
| 521 pContent->Set(bCDATA, content); | 521 pContent->Set(bCDATA, content); |
| 522 pElement->m_Children.Add((void*)CXML_Element::Content); | 522 pElement->m_Children.Add((void*)CXML_Element::Content); |
| 523 pElement->m_Children.Add(pContent); | 523 pElement->m_Children.Add(pContent); |
| 524 } | 524 } |
| 525 static CXML_Element* XML_ContinueParse(CXML_Parser &parser, FX_BOOL bSaveSpaceCh
ars, FX_FILESIZE* pParsedSize) | 525 static CXML_Element* XML_ContinueParse(CXML_Parser &parser, bool bSaveSpaceChars
, FX_FILESIZE* pParsedSize) |
| 526 { | 526 { |
| 527 parser.m_bSaveSpaceChars = bSaveSpaceChars; | 527 parser.m_bSaveSpaceChars = bSaveSpaceChars; |
| 528 CXML_Element* pElement = parser.ParseElement(NULL, FALSE); | 528 CXML_Element* pElement = parser.ParseElement(NULL, false); |
| 529 if (pParsedSize) { | 529 if (pParsedSize) { |
| 530 *pParsedSize = parser.m_nOffset; | 530 *pParsedSize = parser.m_nOffset; |
| 531 } | 531 } |
| 532 return pElement; | 532 return pElement; |
| 533 } | 533 } |
| 534 CXML_Element* CXML_Element::Parse(const void* pBuffer, size_t size, FX_BOOL bSav
eSpaceChars, FX_FILESIZE* pParsedSize) | 534 CXML_Element* CXML_Element::Parse(const void* pBuffer, size_t size, bool bSaveSp
aceChars, FX_FILESIZE* pParsedSize) |
| 535 { | 535 { |
| 536 CXML_Parser parser; | 536 CXML_Parser parser; |
| 537 if (!parser.Init((uint8_t*)pBuffer, size)) { | 537 if (!parser.Init((uint8_t*)pBuffer, size)) { |
| 538 return NULL; | 538 return NULL; |
| 539 } | 539 } |
| 540 return XML_ContinueParse(parser, bSaveSpaceChars, pParsedSize); | 540 return XML_ContinueParse(parser, bSaveSpaceChars, pParsedSize); |
| 541 } | 541 } |
| 542 CXML_Element* CXML_Element::Parse(IFX_FileRead *pFile, FX_BOOL bSaveSpaceChars,
FX_FILESIZE* pParsedSize) | 542 CXML_Element* CXML_Element::Parse(IFX_FileRead *pFile, bool bSaveSpaceChars, FX_
FILESIZE* pParsedSize) |
| 543 { | 543 { |
| 544 CXML_Parser parser; | 544 CXML_Parser parser; |
| 545 if (!parser.Init(pFile)) { | 545 if (!parser.Init(pFile)) { |
| 546 return NULL; | 546 return NULL; |
| 547 } | 547 } |
| 548 return XML_ContinueParse(parser, bSaveSpaceChars, pParsedSize); | 548 return XML_ContinueParse(parser, bSaveSpaceChars, pParsedSize); |
| 549 } | 549 } |
| 550 CXML_Element* CXML_Element::Parse(IFX_BufferRead *pBuffer, FX_BOOL bSaveSpaceCha
rs, FX_FILESIZE* pParsedSize) | 550 CXML_Element* CXML_Element::Parse(IFX_BufferRead *pBuffer, bool bSaveSpaceChars,
FX_FILESIZE* pParsedSize) |
| 551 { | 551 { |
| 552 CXML_Parser parser; | 552 CXML_Parser parser; |
| 553 if (!parser.Init(pBuffer)) { | 553 if (!parser.Init(pBuffer)) { |
| 554 return NULL; | 554 return NULL; |
| 555 } | 555 } |
| 556 return XML_ContinueParse(parser, bSaveSpaceChars, pParsedSize); | 556 return XML_ContinueParse(parser, bSaveSpaceChars, pParsedSize); |
| 557 } | 557 } |
| 558 CXML_Element::CXML_Element() | 558 CXML_Element::CXML_Element() |
| 559 : m_QSpaceName() | 559 : m_QSpaceName() |
| 560 , m_TagName() | 560 , m_TagName() |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 CXML_Content* content = (CXML_Content*)m_Children.GetAt(i + 1); | 593 CXML_Content* content = (CXML_Content*)m_Children.GetAt(i + 1); |
| 594 delete content; | 594 delete content; |
| 595 } else if (type == Element) { | 595 } else if (type == Element) { |
| 596 CXML_Element* child = (CXML_Element*)m_Children.GetAt(i + 1); | 596 CXML_Element* child = (CXML_Element*)m_Children.GetAt(i + 1); |
| 597 child->RemoveChildren(); | 597 child->RemoveChildren(); |
| 598 delete child; | 598 delete child; |
| 599 } | 599 } |
| 600 } | 600 } |
| 601 m_Children.RemoveAll(); | 601 m_Children.RemoveAll(); |
| 602 } | 602 } |
| 603 CFX_ByteString CXML_Element::GetTagName(FX_BOOL bQualified) const | 603 CFX_ByteString CXML_Element::GetTagName(bool bQualified) const |
| 604 { | 604 { |
| 605 if (!bQualified || m_QSpaceName.IsEmpty()) { | 605 if (!bQualified || m_QSpaceName.IsEmpty()) { |
| 606 return m_TagName; | 606 return m_TagName; |
| 607 } | 607 } |
| 608 CFX_ByteString bsTag = m_QSpaceName; | 608 CFX_ByteString bsTag = m_QSpaceName; |
| 609 bsTag += ":"; | 609 bsTag += ":"; |
| 610 bsTag += m_TagName; | 610 bsTag += m_TagName; |
| 611 return bsTag; | 611 return bsTag; |
| 612 } | 612 } |
| 613 CFX_ByteString CXML_Element::GetNamespace(FX_BOOL bQualified) const | 613 CFX_ByteString CXML_Element::GetNamespace(bool bQualified) const |
| 614 { | 614 { |
| 615 if (bQualified) { | 615 if (bQualified) { |
| 616 return m_QSpaceName; | 616 return m_QSpaceName; |
| 617 } | 617 } |
| 618 return GetNamespaceURI(m_QSpaceName); | 618 return GetNamespaceURI(m_QSpaceName); |
| 619 } | 619 } |
| 620 CFX_ByteString CXML_Element::GetNamespaceURI(const CFX_ByteStringC& qName) const | 620 CFX_ByteString CXML_Element::GetNamespaceURI(const CFX_ByteStringC& qName) const |
| 621 { | 621 { |
| 622 const CFX_WideString* pwsSpace; | 622 const CFX_WideString* pwsSpace; |
| 623 const CXML_Element *pElement = this; | 623 const CXML_Element *pElement = this; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 637 void CXML_Element::GetAttrByIndex(int index, CFX_ByteString& space, CFX_ByteStri
ng& name, CFX_WideString& value) const | 637 void CXML_Element::GetAttrByIndex(int index, CFX_ByteString& space, CFX_ByteStri
ng& name, CFX_WideString& value) const |
| 638 { | 638 { |
| 639 if (index < 0 || index >= m_AttrMap.GetSize()) { | 639 if (index < 0 || index >= m_AttrMap.GetSize()) { |
| 640 return; | 640 return; |
| 641 } | 641 } |
| 642 CXML_AttrItem& item = m_AttrMap.GetAt(index); | 642 CXML_AttrItem& item = m_AttrMap.GetAt(index); |
| 643 space = item.m_QSpaceName; | 643 space = item.m_QSpaceName; |
| 644 name = item.m_AttrName; | 644 name = item.m_AttrName; |
| 645 value = item.m_Value; | 645 value = item.m_Value; |
| 646 } | 646 } |
| 647 FX_BOOL CXML_Element::HasAttr(const CFX_ByteStringC& name) const | 647 bool CXML_Element::HasAttr(const CFX_ByteStringC& name) const |
| 648 { | 648 { |
| 649 CFX_ByteStringC bsSpace, bsName; | 649 CFX_ByteStringC bsSpace, bsName; |
| 650 FX_XML_SplitQualifiedName(name, bsSpace, bsName); | 650 FX_XML_SplitQualifiedName(name, bsSpace, bsName); |
| 651 return m_AttrMap.Lookup(bsSpace, bsName) != NULL; | 651 return m_AttrMap.Lookup(bsSpace, bsName) != NULL; |
| 652 } | 652 } |
| 653 FX_BOOL CXML_Element::GetAttrValue(const CFX_ByteStringC& name, CFX_WideString&
attribute) const | 653 bool CXML_Element::GetAttrValue(const CFX_ByteStringC& name, CFX_WideString& att
ribute) const |
| 654 { | 654 { |
| 655 CFX_ByteStringC bsSpace, bsName; | 655 CFX_ByteStringC bsSpace, bsName; |
| 656 FX_XML_SplitQualifiedName(name, bsSpace, bsName); | 656 FX_XML_SplitQualifiedName(name, bsSpace, bsName); |
| 657 return GetAttrValue(bsSpace, bsName, attribute); | 657 return GetAttrValue(bsSpace, bsName, attribute); |
| 658 } | 658 } |
| 659 FX_BOOL CXML_Element::GetAttrValue(const CFX_ByteStringC& space, const CFX_ByteS
tringC& name, CFX_WideString& attribute) const | 659 bool CXML_Element::GetAttrValue(const CFX_ByteStringC& space, const CFX_ByteStri
ngC& name, CFX_WideString& attribute) const |
| 660 { | 660 { |
| 661 const CFX_WideString* pValue = m_AttrMap.Lookup(space, name); | 661 const CFX_WideString* pValue = m_AttrMap.Lookup(space, name); |
| 662 if (pValue) { | 662 if (pValue) { |
| 663 attribute = *pValue; | 663 attribute = *pValue; |
| 664 return TRUE; | 664 return true; |
| 665 } | 665 } |
| 666 return FALSE; | 666 return false; |
| 667 } | 667 } |
| 668 FX_BOOL CXML_Element::GetAttrInteger(const CFX_ByteStringC& name, int& attribute
) const | 668 bool CXML_Element::GetAttrInteger(const CFX_ByteStringC& name, int& attribute) c
onst |
| 669 { | 669 { |
| 670 CFX_ByteStringC bsSpace, bsName; | 670 CFX_ByteStringC bsSpace, bsName; |
| 671 FX_XML_SplitQualifiedName(name, bsSpace, bsName); | 671 FX_XML_SplitQualifiedName(name, bsSpace, bsName); |
| 672 const CFX_WideString* pwsValue = m_AttrMap.Lookup(bsSpace, bsName); | 672 const CFX_WideString* pwsValue = m_AttrMap.Lookup(bsSpace, bsName); |
| 673 if (pwsValue) { | 673 if (pwsValue) { |
| 674 attribute = pwsValue->GetInteger(); | 674 attribute = pwsValue->GetInteger(); |
| 675 return TRUE; | 675 return true; |
| 676 } | 676 } |
| 677 return FALSE; | 677 return false; |
| 678 } | 678 } |
| 679 FX_BOOL»CXML_Element::GetAttrInteger(const CFX_ByteStringC& space, const CFX_Byt
eStringC& name, int& attribute) const | 679 bool» CXML_Element::GetAttrInteger(const CFX_ByteStringC& space, const CFX_Byt
eStringC& name, int& attribute) const |
| 680 { | 680 { |
| 681 const CFX_WideString* pwsValue = m_AttrMap.Lookup(space, name); | 681 const CFX_WideString* pwsValue = m_AttrMap.Lookup(space, name); |
| 682 if (pwsValue) { | 682 if (pwsValue) { |
| 683 attribute = pwsValue->GetInteger(); | 683 attribute = pwsValue->GetInteger(); |
| 684 return TRUE; | 684 return true; |
| 685 } | 685 } |
| 686 return FALSE; | 686 return false; |
| 687 } | 687 } |
| 688 FX_BOOL CXML_Element::GetAttrFloat(const CFX_ByteStringC& name, FX_FLOAT& attrib
ute) const | 688 bool CXML_Element::GetAttrFloat(const CFX_ByteStringC& name, FX_FLOAT& attribute
) const |
| 689 { | 689 { |
| 690 CFX_ByteStringC bsSpace, bsName; | 690 CFX_ByteStringC bsSpace, bsName; |
| 691 FX_XML_SplitQualifiedName(name, bsSpace, bsName); | 691 FX_XML_SplitQualifiedName(name, bsSpace, bsName); |
| 692 return GetAttrFloat(bsSpace, bsName, attribute); | 692 return GetAttrFloat(bsSpace, bsName, attribute); |
| 693 } | 693 } |
| 694 FX_BOOL CXML_Element::GetAttrFloat(const CFX_ByteStringC& space, const CFX_ByteS
tringC& name, FX_FLOAT& attribute) const | 694 bool CXML_Element::GetAttrFloat(const CFX_ByteStringC& space, const CFX_ByteStri
ngC& name, FX_FLOAT& attribute) const |
| 695 { | 695 { |
| 696 const CFX_WideString* pValue = m_AttrMap.Lookup(space, name); | 696 const CFX_WideString* pValue = m_AttrMap.Lookup(space, name); |
| 697 if (pValue) { | 697 if (pValue) { |
| 698 attribute = pValue->GetFloat(); | 698 attribute = pValue->GetFloat(); |
| 699 return TRUE; | 699 return true; |
| 700 } | 700 } |
| 701 return FALSE; | 701 return false; |
| 702 } | 702 } |
| 703 FX_DWORD CXML_Element::CountChildren() const | 703 FX_DWORD CXML_Element::CountChildren() const |
| 704 { | 704 { |
| 705 return m_Children.GetSize() / 2; | 705 return m_Children.GetSize() / 2; |
| 706 } | 706 } |
| 707 CXML_Element::ChildType CXML_Element::GetChildType(FX_DWORD index) const | 707 CXML_Element::ChildType CXML_Element::GetChildType(FX_DWORD index) const |
| 708 { | 708 { |
| 709 index <<= 1; | 709 index <<= 1; |
| 710 if (index >= (FX_DWORD)m_Children.GetSize()) { | 710 if (index >= (FX_DWORD)m_Children.GetSize()) { |
| 711 return Invalid; | 711 return Invalid; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 } | 836 } |
| 837 void CXML_AttrMap::RemoveAll() | 837 void CXML_AttrMap::RemoveAll() |
| 838 { | 838 { |
| 839 if (!m_pMap) { | 839 if (!m_pMap) { |
| 840 return; | 840 return; |
| 841 } | 841 } |
| 842 m_pMap->RemoveAll(); | 842 m_pMap->RemoveAll(); |
| 843 delete m_pMap; | 843 delete m_pMap; |
| 844 m_pMap = NULL; | 844 m_pMap = NULL; |
| 845 } | 845 } |
| OLD | NEW |