Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: core/src/fxcrt/fx_xml_parser.cpp

Issue 372473003: Remove custom memory manager (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Change malloc to calloc Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fxcrt/fx_xml_composer.cpp ('k') | core/src/fxcrt/fxcrt_platforms.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 && m_pDataAcc) { 11 if (m_bOwnedStream) {
12 m_pDataAcc->Release(); 12 m_pDataAcc->Release();
13 } 13 }
14 } 14 }
15 FX_BOOL CXML_Parser::Init(FX_LPBYTE pBuffer, size_t size) 15 FX_BOOL CXML_Parser::Init(FX_LPBYTE pBuffer, size_t size)
16 { 16 {
17 if (m_pAllocator) { 17 m_pDataAcc = FX_NEW CXML_DataBufAcc(pBuffer, size);
18 m_pDataAcc = FX_NewAtAllocator(m_pAllocator)CXML_DataBufAcc(pBuffer, siz e, m_pAllocator);
19 } else {
20 m_pDataAcc = FX_NEW CXML_DataBufAcc(pBuffer, size, NULL);
21 }
22 if (!m_pDataAcc) { 18 if (!m_pDataAcc) {
23 return FALSE; 19 return FALSE;
24 } 20 }
25 return Init(TRUE); 21 return Init(TRUE);
26 } 22 }
27 FX_BOOL CXML_Parser::Init(IFX_FileRead *pFileRead) 23 FX_BOOL CXML_Parser::Init(IFX_FileRead *pFileRead)
28 { 24 {
29 if (m_pAllocator) { 25 m_pDataAcc = FX_NEW CXML_DataStmAcc(pFileRead);
30 m_pDataAcc = FX_NewAtAllocator(m_pAllocator)CXML_DataStmAcc(pFileRead, m _pAllocator);
31 } else {
32 m_pDataAcc = FX_NEW CXML_DataStmAcc(pFileRead, NULL);
33 }
34 if (!m_pDataAcc) { 26 if (!m_pDataAcc) {
35 return FALSE; 27 return FALSE;
36 } 28 }
37 return Init(TRUE); 29 return Init(TRUE);
38 } 30 }
39 FX_BOOL CXML_Parser::Init(IFX_BufferRead *pBuffer) 31 FX_BOOL CXML_Parser::Init(IFX_BufferRead *pBuffer)
40 { 32 {
41 if (!pBuffer) { 33 if (!pBuffer) {
42 return FALSE; 34 return FALSE;
43 } 35 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 do { 121 do {
130 while (m_dwIndex < m_dwBufferSize && g_FXCRT_XML_IsWhiteSpace(m_pBuffer[ m_dwIndex])) { 122 while (m_dwIndex < m_dwBufferSize && g_FXCRT_XML_IsWhiteSpace(m_pBuffer[ m_dwIndex])) {
131 m_dwIndex ++; 123 m_dwIndex ++;
132 } 124 }
133 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; 125 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex;
134 if (m_dwIndex < m_dwBufferSize || IsEOF()) { 126 if (m_dwIndex < m_dwBufferSize || IsEOF()) {
135 break; 127 break;
136 } 128 }
137 } while (ReadNextBlock()); 129 } while (ReadNextBlock());
138 } 130 }
139 void CXML_Parser::GetName(CFX_ByteStringL &space, CFX_ByteStringL &name) 131 void CXML_Parser::GetName(CFX_ByteString &space, CFX_ByteString &name)
140 { 132 {
141 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; 133 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex;
142 if (IsEOF()) { 134 if (IsEOF()) {
143 return; 135 return;
144 } 136 }
145 CFX_ByteTextBuf buf(m_pAllocator); 137 CFX_ByteTextBuf buf;
146 FX_BYTE ch; 138 FX_BYTE ch;
147 do { 139 do {
148 while (m_dwIndex < m_dwBufferSize) { 140 while (m_dwIndex < m_dwBufferSize) {
149 ch = m_pBuffer[m_dwIndex]; 141 ch = m_pBuffer[m_dwIndex];
150 if (ch == ':') { 142 if (ch == ':') {
151 buf.GetByteStringL(space); 143 space = buf.GetByteString();
152 buf.Clear(); 144 buf.Clear();
153 } else if (g_FXCRT_XML_IsNameChar(ch)) { 145 } else if (g_FXCRT_XML_IsNameChar(ch)) {
154 buf.AppendChar(ch); 146 buf.AppendChar(ch);
155 } else { 147 } else {
156 break; 148 break;
157 } 149 }
158 m_dwIndex ++; 150 m_dwIndex ++;
159 } 151 }
160 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; 152 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex;
161 if (m_dwIndex < m_dwBufferSize || IsEOF()) { 153 if (m_dwIndex < m_dwBufferSize || IsEOF()) {
162 break; 154 break;
163 } 155 }
164 } while (ReadNextBlock()); 156 } while (ReadNextBlock());
165 buf.GetByteStringL(name); 157 name = buf.GetByteString();
166 } 158 }
167 void CXML_Parser::SkipLiterals(FX_BSTR str) 159 void CXML_Parser::SkipLiterals(FX_BSTR str)
168 { 160 {
169 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; 161 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex;
170 if (IsEOF()) { 162 if (IsEOF()) {
171 return; 163 return;
172 } 164 }
173 FX_INT32 i = 0, iLen = str.GetLength(); 165 FX_INT32 i = 0, iLen = str.GetLength();
174 do { 166 do {
175 while (m_dwIndex < m_dwBufferSize) { 167 while (m_dwIndex < m_dwBufferSize) {
(...skipping 21 matching lines...) Expand all
197 m_dwIndex = m_dwBufferSize; 189 m_dwIndex = m_dwBufferSize;
198 } 190 }
199 FX_DWORD CXML_Parser::GetCharRef() 191 FX_DWORD CXML_Parser::GetCharRef()
200 { 192 {
201 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; 193 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex;
202 if (IsEOF()) { 194 if (IsEOF()) {
203 return 0; 195 return 0;
204 } 196 }
205 FX_BYTE ch; 197 FX_BYTE ch;
206 FX_INT32 iState = 0; 198 FX_INT32 iState = 0;
207 CFX_ByteTextBuf buf(m_pAllocator); 199 CFX_ByteTextBuf buf;
208 FX_DWORD code = 0; 200 FX_DWORD code = 0;
209 do { 201 do {
210 while (m_dwIndex < m_dwBufferSize) { 202 while (m_dwIndex < m_dwBufferSize) {
211 ch = m_pBuffer[m_dwIndex]; 203 ch = m_pBuffer[m_dwIndex];
212 switch (iState) { 204 switch (iState) {
213 case 0: 205 case 0:
214 if (ch == '#') { 206 if (ch == '#') {
215 m_dwIndex ++; 207 m_dwIndex ++;
216 iState = 2; 208 iState = 2;
217 break; 209 break;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 break; 268 break;
277 } 269 }
278 } 270 }
279 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; 271 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex;
280 if (iState == 10 || m_dwIndex < m_dwBufferSize || IsEOF()) { 272 if (iState == 10 || m_dwIndex < m_dwBufferSize || IsEOF()) {
281 break; 273 break;
282 } 274 }
283 } while (ReadNextBlock()); 275 } while (ReadNextBlock());
284 return code; 276 return code;
285 } 277 }
286 void CXML_Parser::GetAttrValue(CFX_WideStringL &value) 278 void CXML_Parser::GetAttrValue(CFX_WideString &value)
287 { 279 {
288 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; 280 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex;
289 if (IsEOF()) { 281 if (IsEOF()) {
290 return; 282 return;
291 } 283 }
292 CFX_UTF8Decoder decoder(m_pAllocator); 284 CFX_UTF8Decoder decoder;
293 FX_BYTE mark = 0, ch; 285 FX_BYTE mark = 0, ch;
294 do { 286 do {
295 while (m_dwIndex < m_dwBufferSize) { 287 while (m_dwIndex < m_dwBufferSize) {
296 ch = m_pBuffer[m_dwIndex]; 288 ch = m_pBuffer[m_dwIndex];
297 if (mark == 0) { 289 if (mark == 0) {
298 if (ch != '\'' && ch != '"') { 290 if (ch != '\'' && ch != '"') {
299 return; 291 return;
300 } 292 }
301 mark = ch; 293 mark = ch;
302 m_dwIndex ++; 294 m_dwIndex ++;
303 ch = 0; 295 ch = 0;
304 continue; 296 continue;
305 } 297 }
306 m_dwIndex ++; 298 m_dwIndex ++;
307 if (ch == mark) { 299 if (ch == mark) {
308 break; 300 break;
309 } 301 }
310 if (ch == '&') { 302 if (ch == '&') {
311 decoder.AppendChar(GetCharRef()); 303 decoder.AppendChar(GetCharRef());
312 if (IsEOF()) { 304 if (IsEOF()) {
313 decoder.GetResult(value); 305 value = decoder.GetResult();
314 return; 306 return;
315 } 307 }
316 } else { 308 } else {
317 decoder.Input(ch); 309 decoder.Input(ch);
318 } 310 }
319 } 311 }
320 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; 312 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex;
321 if (ch == mark || m_dwIndex < m_dwBufferSize || IsEOF()) { 313 if (ch == mark || m_dwIndex < m_dwBufferSize || IsEOF()) {
322 break; 314 break;
323 } 315 }
324 } while (ReadNextBlock()); 316 } while (ReadNextBlock());
325 decoder.GetResult(value); 317 value = decoder.GetResult();
326 } 318 }
327 void CXML_Parser::GetTagName(CFX_ByteStringL &space, CFX_ByteStringL &name, FX_B OOL &bEndTag, FX_BOOL bStartTag) 319 void CXML_Parser::GetTagName(CFX_ByteString &space, CFX_ByteString &name, FX_BOO L &bEndTag, FX_BOOL bStartTag)
328 { 320 {
329 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; 321 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex;
330 if (IsEOF()) { 322 if (IsEOF()) {
331 return; 323 return;
332 } 324 }
333 bEndTag = FALSE; 325 bEndTag = FALSE;
334 FX_BYTE ch; 326 FX_BYTE ch;
335 FX_INT32 iState = bStartTag ? 1 : 0; 327 FX_INT32 iState = bStartTag ? 1 : 0;
336 do { 328 do {
337 while (m_dwIndex < m_dwBufferSize) { 329 while (m_dwIndex < m_dwBufferSize) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 break; 364 break;
373 } 365 }
374 } while (ReadNextBlock()); 366 } while (ReadNextBlock());
375 } 367 }
376 CXML_Element* CXML_Parser::ParseElement(CXML_Element* pParent, FX_BOOL bStartTag ) 368 CXML_Element* CXML_Parser::ParseElement(CXML_Element* pParent, FX_BOOL bStartTag )
377 { 369 {
378 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; 370 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex;
379 if (IsEOF()) { 371 if (IsEOF()) {
380 return NULL; 372 return NULL;
381 } 373 }
382 CFX_ByteStringL tag_name, tag_space; 374 CFX_ByteString tag_name, tag_space;
383 FX_BOOL bEndTag; 375 FX_BOOL bEndTag;
384 GetTagName(tag_space, tag_name, bEndTag, bStartTag); 376 GetTagName(tag_space, tag_name, bEndTag, bStartTag);
385 if (tag_name.IsEmpty() || bEndTag) { 377 if (tag_name.IsEmpty() || bEndTag) {
386 tag_space.Empty(m_pAllocator);
387 return NULL; 378 return NULL;
388 } 379 }
389 CXML_Element* pElement; 380 CXML_Element* pElement;
390 if (m_pAllocator) { 381 pElement = FX_NEW CXML_Element;
391 pElement = FX_NewAtAllocator(m_pAllocator)CXML_Element(m_pAllocator);
392 } else {
393 pElement = FX_NEW CXML_Element;
394 }
395 if (pElement) { 382 if (pElement) {
396 pElement->m_pParent = pParent; 383 pElement->m_pParent = pParent;
397 pElement->SetTag(tag_space, tag_name); 384 pElement->SetTag(tag_space, tag_name);
398 } 385 }
399 tag_space.Empty(m_pAllocator);
400 tag_name.Empty(m_pAllocator);
401 if (!pElement) { 386 if (!pElement) {
402 return NULL; 387 return NULL;
403 } 388 }
404 do { 389 do {
405 CFX_ByteStringL attr_space, attr_name; 390 CFX_ByteString attr_space, attr_name;
406 while (m_dwIndex < m_dwBufferSize) { 391 while (m_dwIndex < m_dwBufferSize) {
407 SkipWhiteSpaces(); 392 SkipWhiteSpaces();
408 if (IsEOF()) { 393 if (IsEOF()) {
409 break; 394 break;
410 } 395 }
411 if (!g_FXCRT_XML_IsNameIntro(m_pBuffer[m_dwIndex])) { 396 if (!g_FXCRT_XML_IsNameIntro(m_pBuffer[m_dwIndex])) {
412 break; 397 break;
413 } 398 }
414 attr_space.Empty(m_pAllocator);
415 attr_name.Empty(m_pAllocator);
416 GetName(attr_space, attr_name); 399 GetName(attr_space, attr_name);
417 SkipWhiteSpaces(); 400 SkipWhiteSpaces();
418 if (IsEOF()) { 401 if (IsEOF()) {
419 break; 402 break;
420 } 403 }
421 if (m_pBuffer[m_dwIndex] != '=') { 404 if (m_pBuffer[m_dwIndex] != '=') {
422 break; 405 break;
423 } 406 }
424 m_dwIndex ++; 407 m_dwIndex ++;
425 SkipWhiteSpaces(); 408 SkipWhiteSpaces();
426 if (IsEOF()) { 409 if (IsEOF()) {
427 break; 410 break;
428 } 411 }
429 CFX_WideStringL attr_value; 412 CFX_WideString attr_value;
430 GetAttrValue(attr_value); 413 GetAttrValue(attr_value);
431 pElement->m_AttrMap.SetAt(attr_space, attr_name, attr_value, m_pAllo cator); 414 pElement->m_AttrMap.SetAt(attr_space, attr_name, attr_value);
432 attr_value.Empty(m_pAllocator);
433 } 415 }
434 attr_space.Empty(m_pAllocator);
435 attr_name.Empty(m_pAllocator);
436 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; 416 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex;
437 if (m_dwIndex < m_dwBufferSize || IsEOF()) { 417 if (m_dwIndex < m_dwBufferSize || IsEOF()) {
438 break; 418 break;
439 } 419 }
440 } while (ReadNextBlock()); 420 } while (ReadNextBlock());
441 SkipWhiteSpaces(); 421 SkipWhiteSpaces();
442 if (IsEOF()) { 422 if (IsEOF()) {
443 return pElement; 423 return pElement;
444 } 424 }
445 FX_BYTE ch = m_pBuffer[m_dwIndex ++]; 425 FX_BYTE ch = m_pBuffer[m_dwIndex ++];
446 if (ch == '/') { 426 if (ch == '/') {
447 m_dwIndex ++; 427 m_dwIndex ++;
448 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; 428 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex;
449 return pElement; 429 return pElement;
450 } 430 }
451 if (ch != '>') { 431 if (ch != '>') {
452 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; 432 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex;
453 if (m_pAllocator) { 433 delete pElement;
454 FX_DeleteAtAllocator(pElement, m_pAllocator, CXML_Element);
455 } else {
456 delete pElement;
457 }
458 return NULL; 434 return NULL;
459 } 435 }
460 SkipWhiteSpaces(); 436 SkipWhiteSpaces();
461 if (IsEOF()) { 437 if (IsEOF()) {
462 return pElement; 438 return pElement;
463 } 439 }
464 CFX_UTF8Decoder decoder(m_pAllocator); 440 CFX_UTF8Decoder decoder;
465 CFX_WideTextBuf content(m_pAllocator); 441 CFX_WideTextBuf content;
466 FX_BOOL bCDATA = FALSE; 442 FX_BOOL bCDATA = FALSE;
467 FX_INT32 iState = 0; 443 FX_INT32 iState = 0;
468 do { 444 do {
469 while (m_dwIndex < m_dwBufferSize) { 445 while (m_dwIndex < m_dwBufferSize) {
470 ch = m_pBuffer[m_dwIndex ++]; 446 ch = m_pBuffer[m_dwIndex ++];
471 switch (iState) { 447 switch (iState) {
472 case 0: 448 case 0:
473 if (ch == '<') { 449 if (ch == '<') {
474 iState = 1; 450 iState = 1;
475 } else if (ch == '&') { 451 } else if (ch == '&') {
476 decoder.ClearStatus(); 452 decoder.ClearStatus();
477 decoder.AppendChar(GetCharRef()); 453 decoder.AppendChar(GetCharRef());
478 } else { 454 } else {
479 decoder.Input(ch); 455 decoder.Input(ch);
480 } 456 }
481 break; 457 break;
482 case 1: 458 case 1:
483 if (ch == '!') { 459 if (ch == '!') {
484 iState = 2; 460 iState = 2;
485 } else if (ch == '?') { 461 } else if (ch == '?') {
486 SkipLiterals(FX_BSTRC("?>")); 462 SkipLiterals(FX_BSTRC("?>"));
487 SkipWhiteSpaces(); 463 SkipWhiteSpaces();
488 iState = 0; 464 iState = 0;
489 } else if (ch == '/') { 465 } else if (ch == '/') {
490 CFX_ByteStringL space, name; 466 CFX_ByteString space, name;
491 GetName(space, name); 467 GetName(space, name);
492 space.Empty(m_pAllocator);
493 name.Empty(m_pAllocator);
494 SkipWhiteSpaces(); 468 SkipWhiteSpaces();
495 m_dwIndex ++; 469 m_dwIndex ++;
496 iState = 10; 470 iState = 10;
497 } else { 471 } else {
498 content << decoder.GetResult(); 472 content << decoder.GetResult();
499 CFX_WideStringL dataStr; 473 CFX_WideString dataStr = content.GetWideString();
500 content.GetWideStringL(dataStr);
501 if (!bCDATA && !m_bSaveSpaceChars) { 474 if (!bCDATA && !m_bSaveSpaceChars) {
502 dataStr.TrimRight((FX_LPCWSTR)L" \t\r\n"); 475 dataStr.TrimRight((FX_LPCWSTR)L" \t\r\n");
503 } 476 }
504 InsertContentSegment(bCDATA, dataStr, pElement); 477 InsertContentSegment(bCDATA, dataStr, pElement);
505 dataStr.Empty(m_pAllocator);
506 content.Clear(); 478 content.Clear();
507 decoder.Clear(); 479 decoder.Clear();
508 bCDATA = FALSE; 480 bCDATA = FALSE;
509 iState = 0; 481 iState = 0;
510 m_dwIndex --; 482 m_dwIndex --;
511 CXML_Element* pSubElement = ParseElement(pElement, TRUE) ; 483 CXML_Element* pSubElement = ParseElement(pElement, TRUE) ;
512 if (pSubElement == NULL) { 484 if (pSubElement == NULL) {
513 break; 485 break;
514 } 486 }
515 pSubElement->m_pParent = pElement; 487 pSubElement->m_pParent = pElement;
(...skipping 19 matching lines...) Expand all
535 if (iState == 10) { 507 if (iState == 10) {
536 break; 508 break;
537 } 509 }
538 } 510 }
539 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex; 511 m_nOffset = m_nBufferOffset + (FX_FILESIZE)m_dwIndex;
540 if (iState == 10 || m_dwIndex < m_dwBufferSize || IsEOF()) { 512 if (iState == 10 || m_dwIndex < m_dwBufferSize || IsEOF()) {
541 break; 513 break;
542 } 514 }
543 } while (ReadNextBlock()); 515 } while (ReadNextBlock());
544 content << decoder.GetResult(); 516 content << decoder.GetResult();
545 CFX_WideStringL dataStr; 517 CFX_WideString dataStr = content.GetWideString();
546 content.GetWideStringL(dataStr);
547 if (!m_bSaveSpaceChars) { 518 if (!m_bSaveSpaceChars) {
548 dataStr.TrimRight((FX_LPCWSTR)L" \t\r\n"); 519 dataStr.TrimRight((FX_LPCWSTR)L" \t\r\n");
549 } 520 }
550 InsertContentSegment(bCDATA, dataStr, pElement); 521 InsertContentSegment(bCDATA, dataStr, pElement);
551 dataStr.Empty(m_pAllocator);
552 content.Clear(); 522 content.Clear();
553 decoder.Clear(); 523 decoder.Clear();
554 bCDATA = FALSE; 524 bCDATA = FALSE;
555 return pElement; 525 return pElement;
556 } 526 }
557 void CXML_Parser::InsertContentSegment(FX_BOOL bCDATA, FX_WSTR content, CXML_Ele ment* pElement) 527 void CXML_Parser::InsertContentSegment(FX_BOOL bCDATA, FX_WSTR content, CXML_Ele ment* pElement)
558 { 528 {
559 if (content.IsEmpty()) { 529 if (content.IsEmpty()) {
560 return; 530 return;
561 } 531 }
562 CXML_Content* pContent; 532 CXML_Content* pContent;
563 if (m_pAllocator) { 533 pContent = FX_NEW CXML_Content;
564 pContent = FX_NewAtAllocator(m_pAllocator)CXML_Content;
565 } else {
566 pContent = FX_NEW CXML_Content;
567 }
568 if (!pContent) { 534 if (!pContent) {
569 return; 535 return;
570 } 536 }
571 pContent->Set(bCDATA, content, m_pAllocator); 537 pContent->Set(bCDATA, content);
572 pElement->m_Children.Add((FX_LPVOID)CXML_Element::Content); 538 pElement->m_Children.Add((FX_LPVOID)CXML_Element::Content);
573 pElement->m_Children.Add(pContent); 539 pElement->m_Children.Add(pContent);
574 } 540 }
575 static CXML_Element* XML_ContinueParse(CXML_Parser &parser, FX_BOOL bSaveSpaceCh ars, FX_FILESIZE* pParsedSize) 541 static CXML_Element* XML_ContinueParse(CXML_Parser &parser, FX_BOOL bSaveSpaceCh ars, FX_FILESIZE* pParsedSize)
576 { 542 {
577 parser.m_bSaveSpaceChars = bSaveSpaceChars; 543 parser.m_bSaveSpaceChars = bSaveSpaceChars;
578 CXML_Element* pElement = parser.ParseElement(NULL, FALSE); 544 CXML_Element* pElement = parser.ParseElement(NULL, FALSE);
579 if (pParsedSize) { 545 if (pParsedSize) {
580 *pParsedSize = parser.m_nOffset; 546 *pParsedSize = parser.m_nOffset;
581 } 547 }
582 return pElement; 548 return pElement;
583 } 549 }
584 CXML_Element* CXML_Element::Parse(const void* pBuffer, size_t size, FX_BOOL bSav eSpaceChars, FX_FILESIZE* pParsedSize, IFX_Allocator* pAllocator) 550 CXML_Element* CXML_Element::Parse(const void* pBuffer, size_t size, FX_BOOL bSav eSpaceChars, FX_FILESIZE* pParsedSize)
585 { 551 {
586 CXML_Parser parser(pAllocator); 552 CXML_Parser parser;
587 if (!parser.Init((FX_LPBYTE)pBuffer, size)) { 553 if (!parser.Init((FX_LPBYTE)pBuffer, size)) {
588 return NULL; 554 return NULL;
589 } 555 }
590 return XML_ContinueParse(parser, bSaveSpaceChars, pParsedSize); 556 return XML_ContinueParse(parser, bSaveSpaceChars, pParsedSize);
591 } 557 }
592 CXML_Element* CXML_Element::Parse(IFX_FileRead *pFile, FX_BOOL bSaveSpaceChars, FX_FILESIZE* pParsedSize, IFX_Allocator* pAllocator) 558 CXML_Element* CXML_Element::Parse(IFX_FileRead *pFile, FX_BOOL bSaveSpaceChars, FX_FILESIZE* pParsedSize)
593 { 559 {
594 CXML_Parser parser(pAllocator); 560 CXML_Parser parser;
595 if (!parser.Init(pFile)) { 561 if (!parser.Init(pFile)) {
596 return NULL; 562 return NULL;
597 } 563 }
598 return XML_ContinueParse(parser, bSaveSpaceChars, pParsedSize); 564 return XML_ContinueParse(parser, bSaveSpaceChars, pParsedSize);
599 } 565 }
600 CXML_Element* CXML_Element::Parse(IFX_BufferRead *pBuffer, FX_BOOL bSaveSpaceCha rs, FX_FILESIZE* pParsedSize, IFX_Allocator* pAllocator) 566 CXML_Element* CXML_Element::Parse(IFX_BufferRead *pBuffer, FX_BOOL bSaveSpaceCha rs, FX_FILESIZE* pParsedSize)
601 { 567 {
602 CXML_Parser parser(pAllocator); 568 CXML_Parser parser;
603 if (!parser.Init(pBuffer)) { 569 if (!parser.Init(pBuffer)) {
604 return NULL; 570 return NULL;
605 } 571 }
606 return XML_ContinueParse(parser, bSaveSpaceChars, pParsedSize); 572 return XML_ContinueParse(parser, bSaveSpaceChars, pParsedSize);
607 } 573 }
608 CXML_Element::CXML_Element(IFX_Allocator* pAllocator) 574 CXML_Element::CXML_Element()
575 : m_QSpaceName()
576 , m_TagName()
577 , m_AttrMap()
578 {
579 }
580 CXML_Element::CXML_Element(FX_BSTR qSpace, FX_BSTR tagName)
581 : m_QSpaceName()
582 , m_TagName()
583 , m_AttrMap()
584 {
585 m_QSpaceName = qSpace;
586 m_TagName = tagName;
587 }
588 CXML_Element::CXML_Element(FX_BSTR qTagName)
609 : m_pParent(NULL) 589 : m_pParent(NULL)
610 , m_QSpaceName() 590 , m_QSpaceName()
611 , m_TagName() 591 , m_TagName()
612 , m_AttrMap() 592 , m_AttrMap()
613 , m_Children(pAllocator)
614 {
615 }
616 CXML_Element::CXML_Element(FX_BSTR qSpace, FX_BSTR tagName, IFX_Allocator* pAllo cator)
617 : m_pParent(NULL)
618 , m_QSpaceName()
619 , m_TagName()
620 , m_AttrMap()
621 , m_Children(pAllocator)
622 {
623 m_QSpaceName.Set(qSpace, pAllocator);
624 m_TagName.Set(tagName, pAllocator);
625 }
626 CXML_Element::CXML_Element(FX_BSTR qTagName, IFX_Allocator* pAllocator)
627 : m_pParent(NULL)
628 , m_QSpaceName()
629 , m_TagName()
630 , m_AttrMap()
631 , m_Children(pAllocator)
632 { 593 {
633 SetTag(qTagName); 594 SetTag(qTagName);
634 } 595 }
635 CXML_Element::~CXML_Element() 596 CXML_Element::~CXML_Element()
636 { 597 {
637 Empty(); 598 Empty();
638 } 599 }
639 void CXML_Element::Empty() 600 void CXML_Element::Empty()
640 { 601 {
641 IFX_Allocator* pAllocator = m_Children.m_pAllocator;
642 m_QSpaceName.Empty(pAllocator);
643 m_TagName.Empty(pAllocator);
644 m_AttrMap.RemoveAll(pAllocator);
645 RemoveChildren(); 602 RemoveChildren();
646 } 603 }
647 void CXML_Element::RemoveChildren() 604 void CXML_Element::RemoveChildren()
648 { 605 {
649 IFX_Allocator* pAllocator = m_Children.m_pAllocator;
650 for (int i = 0; i < m_Children.GetSize(); i += 2) { 606 for (int i = 0; i < m_Children.GetSize(); i += 2) {
651 ChildType type = (ChildType)(FX_UINTPTR)m_Children.GetAt(i); 607 ChildType type = (ChildType)(FX_UINTPTR)m_Children.GetAt(i);
652 if (type == Content) { 608 if (type == Content) {
653 CXML_Content* content = (CXML_Content*)m_Children.GetAt(i + 1); 609 CXML_Content* content = (CXML_Content*)m_Children.GetAt(i + 1);
654 if (pAllocator) { 610 delete content;
655 FX_DeleteAtAllocator(content, pAllocator, CXML_Content);
656 } else {
657 delete content;
658 }
659 } else if (type == Element) { 611 } else if (type == Element) {
660 CXML_Element* child = (CXML_Element*)m_Children.GetAt(i + 1); 612 CXML_Element* child = (CXML_Element*)m_Children.GetAt(i + 1);
661 child->RemoveChildren(); 613 child->RemoveChildren();
662 if (pAllocator) { 614 delete child;
663 FX_DeleteAtAllocator(child, pAllocator, CXML_Element);
664 } else {
665 delete child;
666 }
667 } 615 }
668 } 616 }
669 m_Children.RemoveAll(); 617 m_Children.RemoveAll();
670 } 618 }
671 CFX_ByteString CXML_Element::GetTagName(FX_BOOL bQualified) const 619 CFX_ByteString CXML_Element::GetTagName(FX_BOOL bQualified) const
672 { 620 {
673 if (!bQualified || m_QSpaceName.IsEmpty()) { 621 if (!bQualified || m_QSpaceName.IsEmpty()) {
674 return m_TagName; 622 return m_TagName;
675 } 623 }
676 CFX_ByteString bsTag = m_QSpaceName; 624 CFX_ByteString bsTag = m_QSpaceName;
677 bsTag += ":"; 625 bsTag += ":";
678 bsTag += m_TagName; 626 bsTag += m_TagName;
679 return bsTag; 627 return bsTag;
680 } 628 }
681 void CXML_Element::GetTagName(CFX_ByteStringL &tagName, FX_BOOL bQualified) cons t
682 {
683 IFX_Allocator* pAllocator = m_Children.m_pAllocator;
684 if (!bQualified || m_QSpaceName.IsEmpty()) {
685 tagName.Set(m_TagName, pAllocator);
686 return;
687 }
688 FX_LPSTR str = tagName.AllocBuffer(m_QSpaceName.GetLength() + m_TagName.GetL ength() + 2, pAllocator);
689 if (!str) {
690 return;
691 }
692 FXSYS_memcpy32(str, m_QSpaceName.GetCStr(), m_QSpaceName.GetLength());
693 str += m_QSpaceName.GetLength();
694 *str = ':';
695 str ++;
696 FXSYS_memcpy32(str, m_TagName.GetCStr(), m_TagName.GetLength());
697 str += m_TagName.GetLength();
698 *str = '\0';
699 }
700 CFX_ByteString CXML_Element::GetNamespace(FX_BOOL bQualified) const 629 CFX_ByteString CXML_Element::GetNamespace(FX_BOOL bQualified) const
701 { 630 {
702 if (bQualified) { 631 if (bQualified) {
703 return m_QSpaceName; 632 return m_QSpaceName;
704 } 633 }
705 return GetNamespaceURI(m_QSpaceName); 634 return GetNamespaceURI(m_QSpaceName);
706 } 635 }
707 void CXML_Element::GetNamespace(CFX_ByteStringL &nameSpace, FX_BOOL bQualified) const
708 {
709 IFX_Allocator* pAllocator = m_Children.m_pAllocator;
710 if (bQualified) {
711 nameSpace.Set(m_QSpaceName, pAllocator);
712 return;
713 }
714 GetNamespaceURI(m_QSpaceName, nameSpace);
715 }
716 CFX_ByteString CXML_Element::GetNamespaceURI(FX_BSTR qName) const 636 CFX_ByteString CXML_Element::GetNamespaceURI(FX_BSTR qName) const
717 { 637 {
718 const CFX_WideStringL* pwsSpace; 638 const CFX_WideString* pwsSpace;
719 const CXML_Element *pElement = this; 639 const CXML_Element *pElement = this;
720 do { 640 do {
721 if (qName.IsEmpty()) { 641 if (qName.IsEmpty()) {
722 pwsSpace = pElement->m_AttrMap.Lookup(FX_BSTRC(""), FX_BSTRC("xmlns" )); 642 pwsSpace = pElement->m_AttrMap.Lookup(FX_BSTRC(""), FX_BSTRC("xmlns" ));
723 } else { 643 } else {
724 pwsSpace = pElement->m_AttrMap.Lookup(FX_BSTRC("xmlns"), qName); 644 pwsSpace = pElement->m_AttrMap.Lookup(FX_BSTRC("xmlns"), qName);
725 } 645 }
726 if (pwsSpace) { 646 if (pwsSpace) {
727 break; 647 break;
728 } 648 }
729 pElement = pElement->GetParent(); 649 pElement = pElement->GetParent();
730 } while(pElement); 650 } while(pElement);
731 return pwsSpace ? FX_UTF8Encode(*pwsSpace) : CFX_ByteString(); 651 return pwsSpace ? FX_UTF8Encode(*pwsSpace) : CFX_ByteString();
732 } 652 }
733 void CXML_Element::GetNamespaceURI(FX_BSTR qName, CFX_ByteStringL &uri) const
734 {
735 IFX_Allocator* pAllocator = m_Children.m_pAllocator;
736 const CFX_WideStringL* pwsSpace;
737 const CXML_Element *pElement = this;
738 do {
739 if (qName.IsEmpty()) {
740 pwsSpace = pElement->m_AttrMap.Lookup(FX_BSTRC(""), FX_BSTRC("xmlns" ));
741 } else {
742 pwsSpace = pElement->m_AttrMap.Lookup(FX_BSTRC("xmlns"), qName);
743 }
744 if (pwsSpace) {
745 break;
746 }
747 pElement = pElement->GetParent();
748 } while(pElement);
749 if (pwsSpace) {
750 FX_UTF8Encode(pwsSpace->GetPtr(), pwsSpace->GetLength(), uri, pAllocator );
751 }
752 }
753 void CXML_Element::GetAttrByIndex(int index, CFX_ByteString& space, CFX_ByteStri ng& name, CFX_WideString& value) const 653 void CXML_Element::GetAttrByIndex(int index, CFX_ByteString& space, CFX_ByteStri ng& name, CFX_WideString& value) const
754 { 654 {
755 if (index < 0 || index >= m_AttrMap.GetSize()) { 655 if (index < 0 || index >= m_AttrMap.GetSize()) {
756 return; 656 return;
757 } 657 }
758 CXML_AttrItem& item = m_AttrMap.GetAt(index); 658 CXML_AttrItem& item = m_AttrMap.GetAt(index);
759 space = item.m_QSpaceName; 659 space = item.m_QSpaceName;
760 name = item.m_AttrName; 660 name = item.m_AttrName;
761 value = item.m_Value; 661 value = item.m_Value;
762 } 662 }
763 void CXML_Element::GetAttrByIndex(int index, CFX_ByteStringL &space, CFX_ByteStr ingL &name, CFX_WideStringL &value) const
764 {
765 if (index < 0 || index >= m_AttrMap.GetSize()) {
766 return;
767 }
768 IFX_Allocator* pAllocator = m_Children.m_pAllocator;
769 CXML_AttrItem& item = m_AttrMap.GetAt(index);
770 space.Set(item.m_QSpaceName, pAllocator);
771 name.Set(item.m_AttrName, pAllocator);
772 value.Set(item.m_Value, pAllocator);
773 }
774 FX_BOOL CXML_Element::HasAttr(FX_BSTR name) const 663 FX_BOOL CXML_Element::HasAttr(FX_BSTR name) const
775 { 664 {
776 CFX_ByteStringC bsSpace, bsName; 665 CFX_ByteStringC bsSpace, bsName;
777 FX_XML_SplitQualifiedName(name, bsSpace, bsName); 666 FX_XML_SplitQualifiedName(name, bsSpace, bsName);
778 return m_AttrMap.Lookup(bsSpace, bsName) != NULL; 667 return m_AttrMap.Lookup(bsSpace, bsName) != NULL;
779 } 668 }
780 FX_BOOL CXML_Element::GetAttrValue(FX_BSTR name, CFX_WideString& attribute) cons t 669 FX_BOOL CXML_Element::GetAttrValue(FX_BSTR name, CFX_WideString& attribute) cons t
781 { 670 {
782 CFX_ByteStringC bsSpace, bsName; 671 CFX_ByteStringC bsSpace, bsName;
783 FX_XML_SplitQualifiedName(name, bsSpace, bsName); 672 FX_XML_SplitQualifiedName(name, bsSpace, bsName);
784 const CFX_WideStringL* pValue = m_AttrMap.Lookup(bsSpace, bsName); 673 const CFX_WideString* pValue = m_AttrMap.Lookup(bsSpace, bsName);
785 if (pValue) { 674 if (pValue) {
786 attribute = CFX_WideString(pValue->GetPtr(), pValue->GetLength()); 675 attribute = CFX_WideString((FX_LPCWSTR)pValue, pValue->GetLength());
787 return TRUE; 676 return TRUE;
788 } 677 }
789 return FALSE; 678 return FALSE;
790 } 679 }
791 const CFX_WideStringL* CXML_Element::GetAttrValuePtr(FX_BSTR name) const
792 {
793 CFX_ByteStringC bsSpace, bsName;
794 FX_XML_SplitQualifiedName(name, bsSpace, bsName);
795 return m_AttrMap.Lookup(bsSpace, bsName);
796 }
797 FX_BOOL CXML_Element::GetAttrValue(FX_BSTR space, FX_BSTR name, CFX_WideString& attribute) const 680 FX_BOOL CXML_Element::GetAttrValue(FX_BSTR space, FX_BSTR name, CFX_WideString& attribute) const
798 { 681 {
799 const CFX_WideStringL* pValue = m_AttrMap.Lookup(space, name); 682 const CFX_WideString* pValue = m_AttrMap.Lookup(space, name);
800 if (pValue) { 683 if (pValue) {
801 attribute = CFX_WideString(pValue->GetPtr(), pValue->GetLength()); 684 attribute = CFX_WideString((FX_LPCWSTR)pValue, pValue->GetLength());
802 return TRUE; 685 return TRUE;
803 } 686 }
804 return FALSE; 687 return FALSE;
805 } 688 }
806 const CFX_WideStringL* CXML_Element::GetAttrValuePtr(FX_BSTR space, FX_BSTR name ) const
807 {
808 return m_AttrMap.Lookup(space, name);
809 }
810 FX_BOOL CXML_Element::GetAttrInteger(FX_BSTR name, int& attribute) const 689 FX_BOOL CXML_Element::GetAttrInteger(FX_BSTR name, int& attribute) const
811 { 690 {
812 CFX_ByteStringC bsSpace, bsName; 691 CFX_ByteStringC bsSpace, bsName;
813 FX_XML_SplitQualifiedName(name, bsSpace, bsName); 692 FX_XML_SplitQualifiedName(name, bsSpace, bsName);
814 const CFX_WideStringL* pwsValue = m_AttrMap.Lookup(bsSpace, bsName); 693 const CFX_WideString* pwsValue = m_AttrMap.Lookup(bsSpace, bsName);
815 if (pwsValue) { 694 if (pwsValue) {
816 attribute = pwsValue->GetInteger(); 695 attribute = pwsValue->GetInteger();
817 return TRUE; 696 return TRUE;
818 } 697 }
819 return FALSE; 698 return FALSE;
820 } 699 }
821 FX_BOOL CXML_Element::GetAttrInteger(FX_BSTR space, FX_BSTR name, int& attribute ) const 700 FX_BOOL CXML_Element::GetAttrInteger(FX_BSTR space, FX_BSTR name, int& attribute ) const
822 { 701 {
823 const CFX_WideStringL* pwsValue = m_AttrMap.Lookup(space, name); 702 const CFX_WideString* pwsValue = m_AttrMap.Lookup(space, name);
824 if (pwsValue) { 703 if (pwsValue) {
825 attribute = pwsValue->GetInteger(); 704 attribute = pwsValue->GetInteger();
826 return TRUE; 705 return TRUE;
827 } 706 }
828 return FALSE; 707 return FALSE;
829 } 708 }
830 FX_BOOL CXML_Element::GetAttrFloat(FX_BSTR name, FX_FLOAT& attribute) const 709 FX_BOOL CXML_Element::GetAttrFloat(FX_BSTR name, FX_FLOAT& attribute) const
831 { 710 {
832 CFX_ByteStringC bsSpace, bsName; 711 CFX_ByteStringC bsSpace, bsName;
833 FX_XML_SplitQualifiedName(name, bsSpace, bsName); 712 FX_XML_SplitQualifiedName(name, bsSpace, bsName);
834 return GetAttrFloat(bsSpace, bsName, attribute); 713 return GetAttrFloat(bsSpace, bsName, attribute);
835 } 714 }
836 FX_BOOL CXML_Element::GetAttrFloat(FX_BSTR space, FX_BSTR name, FX_FLOAT& attrib ute) const 715 FX_BOOL CXML_Element::GetAttrFloat(FX_BSTR space, FX_BSTR name, FX_FLOAT& attrib ute) const
837 { 716 {
838 CFX_WideString value; 717 const CFX_WideString* pValue = m_AttrMap.Lookup(space, name);
839 const CFX_WideStringL* pValue = m_AttrMap.Lookup(space, name);
840 if (pValue) { 718 if (pValue) {
841 attribute = pValue->GetFloat(); 719 attribute = pValue->GetFloat();
842 return TRUE; 720 return TRUE;
843 } 721 }
844 return FALSE; 722 return FALSE;
845 } 723 }
846 FX_DWORD CXML_Element::CountChildren() const 724 FX_DWORD CXML_Element::CountChildren() const
847 { 725 {
848 return m_Children.GetSize() / 2; 726 return m_Children.GetSize() / 2;
849 } 727 }
(...skipping 11 matching lines...) Expand all
861 if (index >= (FX_DWORD)m_Children.GetSize() || 739 if (index >= (FX_DWORD)m_Children.GetSize() ||
862 (ChildType)(FX_UINTPTR)m_Children.GetAt(index) != Content) { 740 (ChildType)(FX_UINTPTR)m_Children.GetAt(index) != Content) {
863 return CFX_WideString(); 741 return CFX_WideString();
864 } 742 }
865 CXML_Content* pContent = (CXML_Content*)m_Children.GetAt(index + 1); 743 CXML_Content* pContent = (CXML_Content*)m_Children.GetAt(index + 1);
866 if (pContent) { 744 if (pContent) {
867 return pContent->m_Content; 745 return pContent->m_Content;
868 } 746 }
869 return CFX_WideString(); 747 return CFX_WideString();
870 } 748 }
871 const CFX_WideStringL* CXML_Element::GetContentPtr(FX_DWORD index) const
872 {
873 index <<= 1;
874 if (index >= (FX_DWORD)m_Children.GetSize() ||
875 (ChildType)(FX_UINTPTR)m_Children.GetAt(index) != Content) {
876 return NULL;
877 }
878 CXML_Content* pContent = (CXML_Content*)m_Children.GetAt(index + 1);
879 if (pContent) {
880 return &pContent->m_Content;
881 }
882 return NULL;
883 }
884 CXML_Element* CXML_Element::GetElement(FX_DWORD index) const 749 CXML_Element* CXML_Element::GetElement(FX_DWORD index) const
885 { 750 {
886 index <<= 1; 751 index <<= 1;
887 if (index >= (FX_DWORD)m_Children.GetSize() || 752 if (index >= (FX_DWORD)m_Children.GetSize() ||
888 (ChildType)(FX_UINTPTR)m_Children.GetAt(index) != Element) { 753 (ChildType)(FX_UINTPTR)m_Children.GetAt(index) != Element) {
889 return NULL; 754 return NULL;
890 } 755 }
891 return (CXML_Element*)m_Children.GetAt(index + 1); 756 return (CXML_Element*)m_Children.GetAt(index + 1);
892 } 757 }
893 FX_DWORD CXML_Element::CountElements(FX_BSTR space, FX_BSTR tag) const 758 FX_DWORD CXML_Element::CountElements(FX_BSTR space, FX_BSTR tag) const
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 FX_DWORD CXML_Element::FindElement(CXML_Element *pChild) const 793 FX_DWORD CXML_Element::FindElement(CXML_Element *pChild) const
929 { 794 {
930 for (int i = 0; i < m_Children.GetSize(); i += 2) { 795 for (int i = 0; i < m_Children.GetSize(); i += 2) {
931 if ((ChildType)(FX_UINTPTR)m_Children.GetAt(i) == Element && 796 if ((ChildType)(FX_UINTPTR)m_Children.GetAt(i) == Element &&
932 (CXML_Element*)m_Children.GetAt(i + 1) == pChild) { 797 (CXML_Element*)m_Children.GetAt(i + 1) == pChild) {
933 return (FX_DWORD)(i >> 1); 798 return (FX_DWORD)(i >> 1);
934 } 799 }
935 } 800 }
936 return (FX_DWORD) - 1; 801 return (FX_DWORD) - 1;
937 } 802 }
938 const CFX_WideStringL* CXML_AttrMap::Lookup(FX_BSTR space, FX_BSTR name) const 803 const CFX_WideString* CXML_AttrMap::Lookup(FX_BSTR space, FX_BSTR name) const
939 { 804 {
940 if (m_pMap == NULL) { 805 if (m_pMap == NULL) {
941 return NULL; 806 return NULL;
942 } 807 }
943 for (int i = 0; i < m_pMap->GetSize(); i ++) { 808 for (int i = 0; i < m_pMap->GetSize(); i ++) {
944 CXML_AttrItem& item = GetAt(i); 809 CXML_AttrItem& item = GetAt(i);
945 if ((space.IsEmpty() || item.m_QSpaceName == space) && item.m_AttrName = = name) { 810 if ((space.IsEmpty() || item.m_QSpaceName == space) && item.m_AttrName = = name) {
946 return &item.m_Value; 811 return &item.m_Value;
947 } 812 }
948 } 813 }
949 return NULL; 814 return NULL;
950 } 815 }
951 void CXML_AttrMap::SetAt(FX_BSTR space, FX_BSTR name, FX_WSTR value, IFX_Allocat or* pAllocator) 816 void CXML_AttrMap::SetAt(FX_BSTR space, FX_BSTR name, FX_WSTR value)
952 { 817 {
953 for (int i = 0; i < GetSize(); i ++) { 818 for (int i = 0; i < GetSize(); i++) {
954 CXML_AttrItem& item = GetAt(i); 819 CXML_AttrItem& item = GetAt(i);
955 if ((space.IsEmpty() || item.m_QSpaceName == space) && item.m_AttrName = = name) { 820 if ((space.IsEmpty() || item.m_QSpaceName == space) && item.m_AttrName = = name) {
956 item.m_Value.Set(value, pAllocator); 821 item.m_Value = value;
957 return; 822 return;
958 } 823 }
959 } 824 }
960 if (!m_pMap) { 825 if (!m_pMap) {
961 if (pAllocator) { 826 m_pMap = FX_NEW CFX_ObjectArray < CXML_AttrItem > ;
962 m_pMap = FX_NewAtAllocator(pAllocator)CFX_ObjectArray<CXML_AttrItem> (pAllocator);
963 } else {
964 m_pMap = FX_NEW CFX_ObjectArray<CXML_AttrItem>;
965 }
966 } 827 }
967 if (!m_pMap) { 828 if (!m_pMap) {
968 return; 829 return;
969 } 830 }
970 CXML_AttrItem* pItem = (CXML_AttrItem*)m_pMap->AddSpace(); 831 CXML_AttrItem* pItem = (CXML_AttrItem*)m_pMap->AddSpace();
971 if (!pItem) { 832 if (!pItem) {
972 return; 833 return;
973 } 834 }
974 pItem->m_QSpaceName.Set(space, pAllocator); 835 pItem->m_QSpaceName = space;
975 pItem->m_AttrName.Set(name, pAllocator); 836 pItem->m_AttrName = name;
976 pItem->m_Value.Set(value, pAllocator); 837 pItem->m_Value = value;
977 } 838 }
978 void CXML_AttrMap::RemoveAt(FX_BSTR space, FX_BSTR name, IFX_Allocator* pAllocat or) 839 void CXML_AttrMap::RemoveAt(FX_BSTR space, FX_BSTR name)
979 { 840 {
980 if (m_pMap == NULL) { 841 if (m_pMap == NULL) {
981 return; 842 return;
982 } 843 }
983 for (int i = 0; i < m_pMap->GetSize(); i ++) { 844 for (int i = 0; i < m_pMap->GetSize(); i ++) {
984 CXML_AttrItem& item = GetAt(i); 845 CXML_AttrItem& item = GetAt(i);
985 if ((space.IsEmpty() || item.m_QSpaceName == space) && item.m_AttrName = = name) { 846 if ((space.IsEmpty() || item.m_QSpaceName == space) && item.m_AttrName = = name) {
986 item.Empty(pAllocator);
987 m_pMap->RemoveAt(i); 847 m_pMap->RemoveAt(i);
988 return; 848 return;
989 } 849 }
990 } 850 }
991 } 851 }
992 int CXML_AttrMap::GetSize() const 852 int CXML_AttrMap::GetSize() const
993 { 853 {
994 return m_pMap == NULL ? 0 : m_pMap->GetSize(); 854 return m_pMap == NULL ? 0 : m_pMap->GetSize();
995 } 855 }
996 CXML_AttrItem& CXML_AttrMap::GetAt(int index) const 856 CXML_AttrItem& CXML_AttrMap::GetAt(int index) const
997 { 857 {
998 ASSERT(m_pMap != NULL); 858 ASSERT(m_pMap != NULL);
999 return (*m_pMap)[index]; 859 return (*m_pMap)[index];
1000 } 860 }
1001 void CXML_AttrMap::RemoveAll(IFX_Allocator* pAllocator) 861 void CXML_AttrMap::RemoveAll()
1002 { 862 {
1003 if (!m_pMap) { 863 if (!m_pMap) {
1004 return; 864 return;
1005 } 865 }
1006 for (int i = 0; i < m_pMap->GetSize(); i ++) { 866 for (int i = 0; i < m_pMap->GetSize(); i ++) {
1007 CXML_AttrItem& item = (*m_pMap)[i]; 867 CXML_AttrItem& item = (*m_pMap)[i];
1008 item.Empty(pAllocator);
1009 } 868 }
1010 m_pMap->RemoveAll(); 869 m_pMap->RemoveAll();
1011 if (pAllocator) { 870 delete m_pMap;
1012 FX_DeleteAtAllocator(m_pMap, pAllocator, CFX_ObjectArray<CXML_AttrItem>) ;
1013 } else {
1014 delete m_pMap;
1015 }
1016 m_pMap = NULL; 871 m_pMap = NULL;
1017 } 872 }
OLDNEW
« no previous file with comments | « core/src/fxcrt/fx_xml_composer.cpp ('k') | core/src/fxcrt/fxcrt_platforms.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698