@@ -475,9 +475,11 @@ UIWidget* UISceneNode::loadLayoutFromString( const char* layoutString, Node* par
475475
476476 pugi::xml_document doc;
477477 pugi::xml_parse_result result;
478+ std::string fixedLayout;
479+ bool needsReplacements = voidTagsRegex.matches ( layoutString );
478480
479- if ( voidTagsRegex. matches ( layoutString ) ) {
480- std::string fixedLayout = voidTagsRegex.gsub ( layoutString, " %1 />" );
481+ if ( needsReplacements ) {
482+ fixedLayout = voidTagsRegex.gsub ( layoutString, " %1 />" );
481483 result =
482484 doc.load_string ( fixedLayout.c_str (), pugi::parse_default | pugi::parse_ws_pcdata );
483485 } else {
@@ -487,7 +489,8 @@ UIWidget* UISceneNode::loadLayoutFromString( const char* layoutString, Node* par
487489 if ( result ) {
488490 return loadLayoutNodes ( doc.first_child (), NULL != parent ? parent : this , marker );
489491 } else {
490- Log::error ( " Couldn't load UI Layout from string: %s" , layoutString );
492+ Log::error ( " Couldn't load UI Layout from string: %s" ,
493+ needsReplacements ? fixedLayout.c_str () : layoutString );
491494 Log::error ( " Error description: %s" , result.description () );
492495 Log::error ( " Error offset: %d" , result.offset );
493496 }
@@ -506,10 +509,13 @@ UIWidget* UISceneNode::loadLayoutFromMemory( const void* buffer, Int32 bufferSiz
506509
507510 pugi::xml_document doc;
508511 pugi::xml_parse_result result;
512+ std::string_view layoutString ( static_cast <const char *>( buffer ), bufferSize );
513+ std::string fixedLayout;
514+ bool needsReplacements =
515+ voidTagsRegex.matches ( static_cast <const char *>( buffer ), 0 , nullptr , bufferSize );
509516
510- if ( voidTagsRegex.matches ( static_cast <const char *>( buffer ), 0 , nullptr , bufferSize ) ) {
511- std::string strBuffer ( static_cast <const char *>( buffer ), bufferSize );
512- std::string fixedLayout = voidTagsRegex.gsub ( strBuffer, " %1 />" );
517+ if ( needsReplacements ) {
518+ fixedLayout = voidTagsRegex.gsub ( layoutString.data (), " %1 />" );
513519 result = doc.load_buffer ( fixedLayout.c_str (), fixedLayout.size (),
514520 pugi::parse_default | pugi::parse_ws_pcdata );
515521 } else {
@@ -519,7 +525,8 @@ UIWidget* UISceneNode::loadLayoutFromMemory( const void* buffer, Int32 bufferSiz
519525 if ( result ) {
520526 return loadLayoutNodes ( doc.first_child (), NULL != parent ? parent : this , marker );
521527 } else {
522- Log::error ( " Couldn't load UI Layout from buffer" );
528+ Log::error ( " Couldn't load UI Layout from memory: %s" ,
529+ needsReplacements ? fixedLayout.c_str () : layoutString.data () );
523530 Log::error ( " Error description: %s" , result.description () );
524531 Log::error ( " Error offset: %d" , result.offset );
525532 }
@@ -540,10 +547,13 @@ UIWidget* UISceneNode::loadLayoutFromStream( IOStream& stream, Node* parent,
540547
541548 pugi::xml_document doc;
542549 pugi::xml_parse_result result;
550+ std::string_view layoutString ( scopedBuffer.get (), scopedBuffer.length () );
551+ std::string fixedLayout;
552+ bool needsReplacements =
553+ voidTagsRegex.matches ( scopedBuffer.get (), 0 , nullptr , scopedBuffer.length () );
543554
544- if ( voidTagsRegex.matches ( scopedBuffer.get (), 0 , nullptr , scopedBuffer.length () ) ) {
545- std::string strBuffer ( scopedBuffer.get (), scopedBuffer.length () );
546- std::string fixedLayout = voidTagsRegex.gsub ( strBuffer, " %1 />" );
555+ if ( needsReplacements ) {
556+ fixedLayout = voidTagsRegex.gsub ( layoutString.data (), " %1 />" );
547557 result = doc.load_buffer ( fixedLayout.c_str (), fixedLayout.size (),
548558 pugi::parse_default | pugi::parse_ws_pcdata );
549559 } else {
@@ -554,8 +564,8 @@ UIWidget* UISceneNode::loadLayoutFromStream( IOStream& stream, Node* parent,
554564 if ( result ) {
555565 return loadLayoutNodes ( doc.first_child (), NULL != parent ? parent : this , marker );
556566 } else {
557- // Preserves the unique stream error log
558- Log::error ( " Couldn't load UI Layout from stream " );
567+ Log::error ( " Couldn't load UI Layout from stream: %s " ,
568+ needsReplacements ? fixedLayout. c_str () : layoutString. data () );
559569 Log::error ( " Error description: %s" , result.description () );
560570 Log::error ( " Error offset: %d" , result.offset );
561571 }
0 commit comments