| 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 { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 64 #define FXCRTM_XML_CHARTYPE_HexLowerLetter 0x40 | 64 #define FXCRTM_XML_CHARTYPE_HexLowerLetter 0x40 |
| 65 #define FXCRTM_XML_CHARTYPE_HexUpperLetter 0x60 | 65 #define FXCRTM_XML_CHARTYPE_HexUpperLetter 0x60 |
| 66 #define FXCRTM_XML_CHARTYPE_HexChar 0x60 | 66 #define FXCRTM_XML_CHARTYPE_HexChar 0x60 |
| 67 FX_BYTE g_FXCRT_XML_ByteTypes[256] = { | 67 uint8_t g_FXCRT_XML_ByteTypes[256] = { |
| 68 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
, 0x01, 0x01, 0x01, | 68 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
, 0x01, 0x01, 0x01, |
| 69 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
, 0x01, 0x01, 0x01, | 69 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
, 0x01, 0x01, 0x01, |
| 70 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
, 0x10, 0x10, 0x00, | 70 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
, 0x10, 0x10, 0x00, |
| 71 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x08, 0x00, 0x00
, 0x00, 0x00, 0x00, | 71 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x08, 0x00, 0x00
, 0x00, 0x00, 0x00, |
| 72 0x00, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A
, 0x1A, 0x1A, 0x1A, | 72 0x00, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0x7A, 0x1A, 0x1A, 0x1A, 0x1A, 0x1A, 0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A, 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(FX_BYTE ch) | 85 FX_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(FX_BYTE ch) | 89 FX_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(FX_BYTE ch) | 93 FX_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(FX_BYTE ch) | 97 FX_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(FX_BYTE ch) | 101 FX_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(FX_BYTE ch) | 105 FX_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 { |
| 116 while (m_dwIndex < m_dwBufferSize && g_FXCRT_XML_IsWhiteSpace(m_pBuffer[
m_dwIndex])) { | 116 while (m_dwIndex < m_dwBufferSize && g_FXCRT_XML_IsWhiteSpace(m_pBuffer[
m_dwIndex])) { |
| 117 m_dwIndex ++; | 117 m_dwIndex ++; |
| 118 } | 118 } |
| 119 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; | 119 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; |
| 120 if (m_dwIndex < m_dwBufferSize || IsEOF()) { | 120 if (m_dwIndex < m_dwBufferSize || IsEOF()) { |
| 121 break; | 121 break; |
| 122 } | 122 } |
| 123 } while (ReadNextBlock()); | 123 } while (ReadNextBlock()); |
| 124 } | 124 } |
| 125 void CXML_Parser::GetName(CFX_ByteString &space, CFX_ByteString &name) | 125 void CXML_Parser::GetName(CFX_ByteString &space, CFX_ByteString &name) |
| 126 { | 126 { |
| 127 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; | 127 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; |
| 128 if (IsEOF()) { | 128 if (IsEOF()) { |
| 129 return; | 129 return; |
| 130 } | 130 } |
| 131 CFX_ByteTextBuf buf; | 131 CFX_ByteTextBuf buf; |
| 132 FX_BYTE ch; | 132 uint8_t ch; |
| 133 do { | 133 do { |
| 134 while (m_dwIndex < m_dwBufferSize) { | 134 while (m_dwIndex < m_dwBufferSize) { |
| 135 ch = m_pBuffer[m_dwIndex]; | 135 ch = m_pBuffer[m_dwIndex]; |
| 136 if (ch == ':') { | 136 if (ch == ':') { |
| 137 space = buf.GetByteString(); | 137 space = buf.GetByteString(); |
| 138 buf.Clear(); | 138 buf.Clear(); |
| 139 } else if (g_FXCRT_XML_IsNameChar(ch)) { | 139 } else if (g_FXCRT_XML_IsNameChar(ch)) { |
| 140 buf.AppendChar(ch); | 140 buf.AppendChar(ch); |
| 141 } else { | 141 } else { |
| 142 break; | 142 break; |
| 143 } | 143 } |
| 144 m_dwIndex ++; | 144 m_dwIndex ++; |
| 145 } | 145 } |
| 146 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; | 146 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; |
| 147 if (m_dwIndex < m_dwBufferSize || IsEOF()) { | 147 if (m_dwIndex < m_dwBufferSize || IsEOF()) { |
| 148 break; | 148 break; |
| 149 } | 149 } |
| 150 } while (ReadNextBlock()); | 150 } while (ReadNextBlock()); |
| 151 name = buf.GetByteString(); | 151 name = buf.GetByteString(); |
| 152 } | 152 } |
| 153 void CXML_Parser::SkipLiterals(FX_BSTR str) | 153 void CXML_Parser::SkipLiterals(FX_BSTR str) |
| 154 { | 154 { |
| 155 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; | 155 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; |
| 156 if (IsEOF()) { | 156 if (IsEOF()) { |
| 157 return; | 157 return; |
| 158 } | 158 } |
| 159 FX_INT32 i = 0, iLen = str.GetLength(); | 159 int32_t i = 0, iLen = str.GetLength(); |
| 160 do { | 160 do { |
| 161 while (m_dwIndex < m_dwBufferSize) { | 161 while (m_dwIndex < m_dwBufferSize) { |
| 162 if (str.GetAt(i) != m_pBuffer[m_dwIndex ++]) { | 162 if (str.GetAt(i) != m_pBuffer[m_dwIndex ++]) { |
| 163 i = 0; | 163 i = 0; |
| 164 } else { | 164 } else { |
| 165 i ++; | 165 i ++; |
| 166 if (i == iLen) { | 166 if (i == iLen) { |
| 167 break; | 167 break; |
| 168 } | 168 } |
| 169 } | 169 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 181 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwBufferSize; | 181 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwBufferSize; |
| 182 } | 182 } |
| 183 m_dwIndex = m_dwBufferSize; | 183 m_dwIndex = m_dwBufferSize; |
| 184 } | 184 } |
| 185 FX_DWORD CXML_Parser::GetCharRef() | 185 FX_DWORD CXML_Parser::GetCharRef() |
| 186 { | 186 { |
| 187 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; | 187 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; |
| 188 if (IsEOF()) { | 188 if (IsEOF()) { |
| 189 return 0; | 189 return 0; |
| 190 } | 190 } |
| 191 FX_BYTE ch; | 191 uint8_t ch; |
| 192 FX_INT32 iState = 0; | 192 int32_t iState = 0; |
| 193 CFX_ByteTextBuf buf; | 193 CFX_ByteTextBuf buf; |
| 194 FX_DWORD code = 0; | 194 FX_DWORD code = 0; |
| 195 do { | 195 do { |
| 196 while (m_dwIndex < m_dwBufferSize) { | 196 while (m_dwIndex < m_dwBufferSize) { |
| 197 ch = m_pBuffer[m_dwIndex]; | 197 ch = m_pBuffer[m_dwIndex]; |
| 198 switch (iState) { | 198 switch (iState) { |
| 199 case 0: | 199 case 0: |
| 200 if (ch == '#') { | 200 if (ch == '#') { |
| 201 m_dwIndex ++; | 201 m_dwIndex ++; |
| 202 iState = 2; | 202 iState = 2; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 if (g_FXCRT_XML_IsDigital(ch)) { | 239 if (g_FXCRT_XML_IsDigital(ch)) { |
| 240 code = code * 10 + ch - '0'; | 240 code = code * 10 + ch - '0'; |
| 241 } | 241 } |
| 242 break; | 242 break; |
| 243 case 4: | 243 case 4: |
| 244 m_dwIndex ++; | 244 m_dwIndex ++; |
| 245 if (ch == ';') { | 245 if (ch == ';') { |
| 246 iState = 10; | 246 iState = 10; |
| 247 break; | 247 break; |
| 248 } | 248 } |
| 249 FX_BYTE nHex = g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTY
PE_HexChar; | 249 uint8_t nHex = g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTY
PE_HexChar; |
| 250 if (nHex) { | 250 if (nHex) { |
| 251 if (nHex == FXCRTM_XML_CHARTYPE_HexDigital) { | 251 if (nHex == FXCRTM_XML_CHARTYPE_HexDigital) { |
| 252 code = (code << 4) + ch - '0'; | 252 code = (code << 4) + ch - '0'; |
| 253 } else if (nHex == FXCRTM_XML_CHARTYPE_HexLowerLetter) { | 253 } else if (nHex == FXCRTM_XML_CHARTYPE_HexLowerLetter) { |
| 254 code = (code << 4) + ch - 87; | 254 code = (code << 4) + ch - 87; |
| 255 } else { | 255 } else { |
| 256 code = (code << 4) + ch - 55; | 256 code = (code << 4) + ch - 55; |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 break; | 259 break; |
| 260 } | 260 } |
| 261 if (iState == 10) { | 261 if (iState == 10) { |
| 262 break; | 262 break; |
| 263 } | 263 } |
| 264 } | 264 } |
| 265 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; | 265 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; |
| 266 if (iState == 10 || m_dwIndex < m_dwBufferSize || IsEOF()) { | 266 if (iState == 10 || m_dwIndex < m_dwBufferSize || IsEOF()) { |
| 267 break; | 267 break; |
| 268 } | 268 } |
| 269 } while (ReadNextBlock()); | 269 } while (ReadNextBlock()); |
| 270 return code; | 270 return code; |
| 271 } | 271 } |
| 272 void CXML_Parser::GetAttrValue(CFX_WideString &value) | 272 void CXML_Parser::GetAttrValue(CFX_WideString &value) |
| 273 { | 273 { |
| 274 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; | 274 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; |
| 275 if (IsEOF()) { | 275 if (IsEOF()) { |
| 276 return; | 276 return; |
| 277 } | 277 } |
| 278 CFX_UTF8Decoder decoder; | 278 CFX_UTF8Decoder decoder; |
| 279 FX_BYTE mark = 0, ch = 0; | 279 uint8_t mark = 0, ch = 0; |
| 280 do { | 280 do { |
| 281 while (m_dwIndex < m_dwBufferSize) { | 281 while (m_dwIndex < m_dwBufferSize) { |
| 282 ch = m_pBuffer[m_dwIndex]; | 282 ch = m_pBuffer[m_dwIndex]; |
| 283 if (mark == 0) { | 283 if (mark == 0) { |
| 284 if (ch != '\'' && ch != '"') { | 284 if (ch != '\'' && ch != '"') { |
| 285 return; | 285 return; |
| 286 } | 286 } |
| 287 mark = ch; | 287 mark = ch; |
| 288 m_dwIndex ++; | 288 m_dwIndex ++; |
| 289 ch = 0; | 289 ch = 0; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 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, FX_BOO
L &bEndTag, FX_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 FX_BYTE ch; | 320 uint8_t ch; |
| 321 FX_INT32 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; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 } | 403 } |
| 404 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; | 404 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; |
| 405 if (m_dwIndex < m_dwBufferSize || IsEOF()) { | 405 if (m_dwIndex < m_dwBufferSize || IsEOF()) { |
| 406 break; | 406 break; |
| 407 } | 407 } |
| 408 } while (ReadNextBlock()); | 408 } while (ReadNextBlock()); |
| 409 SkipWhiteSpaces(); | 409 SkipWhiteSpaces(); |
| 410 if (IsEOF()) { | 410 if (IsEOF()) { |
| 411 return pElement; | 411 return pElement; |
| 412 } | 412 } |
| 413 FX_BYTE ch = m_pBuffer[m_dwIndex ++]; | 413 uint8_t ch = m_pBuffer[m_dwIndex ++]; |
| 414 if (ch == '/') { | 414 if (ch == '/') { |
| 415 m_dwIndex ++; | 415 m_dwIndex ++; |
| 416 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; | 416 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; |
| 417 return pElement; | 417 return pElement; |
| 418 } | 418 } |
| 419 if (ch != '>') { | 419 if (ch != '>') { |
| 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 FX_BOOL bCDATA = FALSE; |
| 431 FX_INT32 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(); |
| 441 decoder.AppendChar(GetCharRef()); | 441 decoder.AppendChar(GetCharRef()); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 { | 581 { |
| 582 Empty(); | 582 Empty(); |
| 583 } | 583 } |
| 584 void CXML_Element::Empty() | 584 void CXML_Element::Empty() |
| 585 { | 585 { |
| 586 RemoveChildren(); | 586 RemoveChildren(); |
| 587 } | 587 } |
| 588 void CXML_Element::RemoveChildren() | 588 void CXML_Element::RemoveChildren() |
| 589 { | 589 { |
| 590 for (int i = 0; i < m_Children.GetSize(); i += 2) { | 590 for (int i = 0; i < m_Children.GetSize(); i += 2) { |
| 591 ChildType type = (ChildType)(FX_UINTPTR)m_Children.GetAt(i); | 591 ChildType type = (ChildType)(uintptr_t)m_Children.GetAt(i); |
| 592 if (type == Content) { | 592 if (type == Content) { |
| 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(); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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; |
| 712 } | 712 } |
| 713 return (ChildType)(FX_UINTPTR)m_Children.GetAt(index); | 713 return (ChildType)(uintptr_t)m_Children.GetAt(index); |
| 714 } | 714 } |
| 715 CFX_WideString CXML_Element::GetContent(FX_DWORD index) const | 715 CFX_WideString CXML_Element::GetContent(FX_DWORD index) const |
| 716 { | 716 { |
| 717 index <<= 1; | 717 index <<= 1; |
| 718 if (index >= (FX_DWORD)m_Children.GetSize() || | 718 if (index >= (FX_DWORD)m_Children.GetSize() || |
| 719 (ChildType)(FX_UINTPTR)m_Children.GetAt(index) != Content) { | 719 (ChildType)(uintptr_t)m_Children.GetAt(index) != Content) { |
| 720 return CFX_WideString(); | 720 return CFX_WideString(); |
| 721 } | 721 } |
| 722 CXML_Content* pContent = (CXML_Content*)m_Children.GetAt(index + 1); | 722 CXML_Content* pContent = (CXML_Content*)m_Children.GetAt(index + 1); |
| 723 if (pContent) { | 723 if (pContent) { |
| 724 return pContent->m_Content; | 724 return pContent->m_Content; |
| 725 } | 725 } |
| 726 return CFX_WideString(); | 726 return CFX_WideString(); |
| 727 } | 727 } |
| 728 CXML_Element* CXML_Element::GetElement(FX_DWORD index) const | 728 CXML_Element* CXML_Element::GetElement(FX_DWORD index) const |
| 729 { | 729 { |
| 730 index <<= 1; | 730 index <<= 1; |
| 731 if (index >= (FX_DWORD)m_Children.GetSize() || | 731 if (index >= (FX_DWORD)m_Children.GetSize() || |
| 732 (ChildType)(FX_UINTPTR)m_Children.GetAt(index) != Element) { | 732 (ChildType)(uintptr_t)m_Children.GetAt(index) != Element) { |
| 733 return NULL; | 733 return NULL; |
| 734 } | 734 } |
| 735 return (CXML_Element*)m_Children.GetAt(index + 1); | 735 return (CXML_Element*)m_Children.GetAt(index + 1); |
| 736 } | 736 } |
| 737 FX_DWORD CXML_Element::CountElements(FX_BSTR space, FX_BSTR tag) const | 737 FX_DWORD CXML_Element::CountElements(FX_BSTR space, FX_BSTR tag) const |
| 738 { | 738 { |
| 739 int count = 0; | 739 int count = 0; |
| 740 for (int i = 0; i < m_Children.GetSize(); i += 2) { | 740 for (int i = 0; i < m_Children.GetSize(); i += 2) { |
| 741 ChildType type = (ChildType)(FX_UINTPTR)m_Children.GetAt(i); | 741 ChildType type = (ChildType)(uintptr_t)m_Children.GetAt(i); |
| 742 if (type != Element) { | 742 if (type != Element) { |
| 743 continue; | 743 continue; |
| 744 } | 744 } |
| 745 CXML_Element* pKid = (CXML_Element*)m_Children.GetAt(i + 1); | 745 CXML_Element* pKid = (CXML_Element*)m_Children.GetAt(i + 1); |
| 746 if ((space.IsEmpty() || pKid->m_QSpaceName == space) && pKid->m_TagName
== tag) { | 746 if ((space.IsEmpty() || pKid->m_QSpaceName == space) && pKid->m_TagName
== tag) { |
| 747 count ++; | 747 count ++; |
| 748 } | 748 } |
| 749 } | 749 } |
| 750 return count; | 750 return count; |
| 751 } | 751 } |
| 752 CXML_Element* CXML_Element::GetElement(FX_BSTR space, FX_BSTR tag, int index) co
nst | 752 CXML_Element* CXML_Element::GetElement(FX_BSTR space, FX_BSTR tag, int index) co
nst |
| 753 { | 753 { |
| 754 if (index < 0) { | 754 if (index < 0) { |
| 755 return NULL; | 755 return NULL; |
| 756 } | 756 } |
| 757 for (int i = 0; i < m_Children.GetSize(); i += 2) { | 757 for (int i = 0; i < m_Children.GetSize(); i += 2) { |
| 758 ChildType type = (ChildType)(FX_UINTPTR)m_Children.GetAt(i); | 758 ChildType type = (ChildType)(uintptr_t)m_Children.GetAt(i); |
| 759 if (type != Element) { | 759 if (type != Element) { |
| 760 continue; | 760 continue; |
| 761 } | 761 } |
| 762 CXML_Element* pKid = (CXML_Element*)m_Children.GetAt(i + 1); | 762 CXML_Element* pKid = (CXML_Element*)m_Children.GetAt(i + 1); |
| 763 if ((!space.IsEmpty() && pKid->m_QSpaceName != space) || pKid->m_TagName
!= tag) { | 763 if ((!space.IsEmpty() && pKid->m_QSpaceName != space) || pKid->m_TagName
!= tag) { |
| 764 continue; | 764 continue; |
| 765 } | 765 } |
| 766 if (index -- == 0) { | 766 if (index -- == 0) { |
| 767 return pKid; | 767 return pKid; |
| 768 } | 768 } |
| 769 } | 769 } |
| 770 return NULL; | 770 return NULL; |
| 771 } | 771 } |
| 772 FX_DWORD CXML_Element::FindElement(CXML_Element *pChild) const | 772 FX_DWORD CXML_Element::FindElement(CXML_Element *pChild) const |
| 773 { | 773 { |
| 774 for (int i = 0; i < m_Children.GetSize(); i += 2) { | 774 for (int i = 0; i < m_Children.GetSize(); i += 2) { |
| 775 if ((ChildType)(FX_UINTPTR)m_Children.GetAt(i) == Element && | 775 if ((ChildType)(uintptr_t)m_Children.GetAt(i) == Element && |
| 776 (CXML_Element*)m_Children.GetAt(i + 1) == pChild) { | 776 (CXML_Element*)m_Children.GetAt(i + 1) == pChild) { |
| 777 return (FX_DWORD)(i >> 1); | 777 return (FX_DWORD)(i >> 1); |
| 778 } | 778 } |
| 779 } | 779 } |
| 780 return (FX_DWORD) - 1; | 780 return (FX_DWORD) - 1; |
| 781 } | 781 } |
| 782 const CFX_WideString* CXML_AttrMap::Lookup(FX_BSTR space, FX_BSTR name) const | 782 const CFX_WideString* CXML_AttrMap::Lookup(FX_BSTR space, FX_BSTR name) const |
| 783 { | 783 { |
| 784 if (m_pMap == NULL) { | 784 if (m_pMap == NULL) { |
| 785 return NULL; | 785 return NULL; |
| (...skipping 50 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 |