MCPcopy Create free account
hub / github.com/SpartanJ/eepp / loadLayoutFromStream

Method loadLayoutFromStream

src/eepp/ui/uiscenenode.cpp:577–618  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

575}
576
577UIWidget* 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
620UIWidget* UISceneNode::loadLayoutFromPack( Pack* pack, const std::string& FilePackPath,
621 Node* parent ) {

Callers

nothing calls this directly

Calls 12

errorFunction · 0.85
getErrorContextFunction · 0.85
gsubMethod · 0.80
c_strMethod · 0.80
isOpenMethod · 0.45
getSizeMethod · 0.45
readMethod · 0.45
getMethod · 0.45
lengthMethod · 0.45
matchesMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected