| 575 | } |
| 576 | |
| 577 | UIWidget* UISceneNode::loadLayoutFromStream( IOStream& stream, Node* parent, |
| 578 | const Uint32& marker ) { |
| 579 | if ( !stream.isOpen() ) |
| 580 | return NULL; |
| 581 | |
| 582 | ios_size bufferSize = stream.getSize(); |
| 583 | TScopedBuffer<char> scopedBuffer( bufferSize ); |
| 584 | stream.read( scopedBuffer.get(), scopedBuffer.length() ); |
| 585 | |
| 586 | RegEx voidTagsRegex( VOIDTAG_REGEX ); |
| 587 | |
| 588 | pugi::xml_document doc; |
| 589 | pugi::xml_parse_result result; |
| 590 | std::string_view layoutString( scopedBuffer.get(), scopedBuffer.length() ); |
| 591 | std::string fixedLayout; |
| 592 | bool needsReplacements = |
| 593 | voidTagsRegex.matches( scopedBuffer.get(), 0, nullptr, scopedBuffer.length() ); |
| 594 | std::string_view contents; |
| 595 | |
| 596 | if ( needsReplacements ) { |
| 597 | fixedLayout = voidTagsRegex.gsub( layoutString.data(), "%1 />" ); |
| 598 | result = doc.load_buffer( fixedLayout.c_str(), fixedLayout.size(), |
| 599 | pugi::parse_default | pugi::parse_ws_pcdata ); |
| 600 | contents = fixedLayout; |
| 601 | } else { |
| 602 | result = doc.load_buffer( scopedBuffer.get(), scopedBuffer.length(), |
| 603 | pugi::parse_default | pugi::parse_ws_pcdata ); |
| 604 | contents = std::string_view( scopedBuffer.get(), scopedBuffer.length() ); |
| 605 | } |
| 606 | |
| 607 | if ( result ) { |
| 608 | return loadLayoutNodes( doc.first_child(), NULL != parent ? parent : this, marker ); |
| 609 | } else { |
| 610 | Log::error( "Couldn't load UI Layout from stream: %s", |
| 611 | needsReplacements ? fixedLayout.c_str() : layoutString.data() ); |
| 612 | Log::error( "Error description: %s", result.description() ); |
| 613 | Log::error( "Error offset: %d", result.offset ); |
| 614 | Log::error( "Error context: %s", getErrorContext( result.offset, contents ) ); |
| 615 | } |
| 616 | |
| 617 | return NULL; |
| 618 | } |
| 619 | |
| 620 | UIWidget* UISceneNode::loadLayoutFromPack( Pack* pack, const std::string& FilePackPath, |
| 621 | Node* parent ) { |
nothing calls this directly
no test coverage detected