@@ -448,7 +448,9 @@ PList::PList() {
448448}
449449
450450PList::PList (const String &p_string) {
451- load_string (p_string);
451+ String err_str;
452+ bool ok = load_string (p_string, err_str);
453+ ERR_FAIL_COND_MSG (!ok, " PList: " + err_str);
452454}
453455
454456uint64_t PList::read_bplist_var_size_int (Ref<FileAccess> p_file, uint8_t p_size) {
@@ -642,11 +644,15 @@ bool PList::load_file(const String &p_filename) {
642644
643645 String ret;
644646 ret.parse_utf8 ((const char *)array.ptr (), array.size ());
645- return load_string (ret);
647+ String err_str;
648+ bool ok = load_string (ret, err_str);
649+ ERR_FAIL_COND_V_MSG (!ok, false , " PList: " + err_str);
650+
651+ return true ;
646652 }
647653}
648654
649- bool PList::load_string (const String &p_string) {
655+ bool PList::load_string (const String &p_string, String &r_err_out ) {
650656 root = Ref<PListNode>();
651657
652658 int pos = 0 ;
@@ -657,14 +663,16 @@ bool PList::load_string(const String &p_string) {
657663 while (pos >= 0 ) {
658664 int open_token_s = p_string.find (" <" , pos);
659665 if (open_token_s == -1 ) {
660- ERR_FAIL_V_MSG (false , " PList: Unexpected end of data. No tags found." );
666+ r_err_out = " Unexpected end of data. No tags found." ;
667+ return false ;
661668 }
662669 int open_token_e = p_string.find (" >" , open_token_s);
663670 pos = open_token_e;
664671
665672 String token = p_string.substr (open_token_s + 1 , open_token_e - open_token_s - 1 );
666673 if (token.is_empty ()) {
667- ERR_FAIL_V_MSG (false , " PList: Invalid token name." );
674+ r_err_out = " Invalid token name." ;
675+ return false ;
668676 }
669677 String value;
670678 if (token[0 ] == ' ?' || token[0 ] == ' !' ) { // Skip <?xml ... ?> and <!DOCTYPE ... >
@@ -684,7 +692,8 @@ bool PList::load_string(const String &p_string) {
684692 }
685693
686694 if (!in_plist) {
687- ERR_FAIL_V_MSG (false , " PList: Node outside of <plist> tag." );
695+ r_err_out = " Node outside of <plist> tag." ;
696+ return false ;
688697 }
689698
690699 if (token == " dict" ) {
@@ -693,13 +702,15 @@ bool PList::load_string(const String &p_string) {
693702 Ref<PListNode> dict = PListNode::new_dict ();
694703 dict->data_type = PList::PLNodeType::PL_NODE_TYPE_DICT;
695704 if (!stack.back ()->get ()->push_subnode (dict, key)) {
696- ERR_FAIL_V_MSG (false , " PList: Can't push subnode, invalid parent type." );
705+ r_err_out = " Can't push subnode, invalid parent type." ;
706+ return false ;
697707 }
698708 stack.push_back (dict);
699709 } else {
700710 // Add root node.
701711 if (!root.is_null ()) {
702- ERR_FAIL_V_MSG (false , " PList: Root node already set." );
712+ r_err_out = " Root node already set." ;
713+ return false ;
703714 }
704715 Ref<PListNode> dict = PListNode::new_dict ();
705716 stack.push_back (dict);
@@ -711,7 +722,8 @@ bool PList::load_string(const String &p_string) {
711722 if (token == " /dict" ) {
712723 // Exit current dict.
713724 if (stack.is_empty () || stack.back ()->get ()->data_type != PList::PLNodeType::PL_NODE_TYPE_DICT) {
714- ERR_FAIL_V_MSG (false , " PList: Mismatched </dict> tag." );
725+ r_err_out = " Mismatched </dict> tag." ;
726+ return false ;
715727 }
716728 stack.pop_back ();
717729 continue ;
@@ -722,13 +734,15 @@ bool PList::load_string(const String &p_string) {
722734 // Add subnode end enter it.
723735 Ref<PListNode> arr = PListNode::new_array ();
724736 if (!stack.back ()->get ()->push_subnode (arr, key)) {
725- ERR_FAIL_V_MSG (false , " PList: Can't push subnode, invalid parent type." );
737+ r_err_out = " Can't push subnode, invalid parent type." ;
738+ return false ;
726739 }
727740 stack.push_back (arr);
728741 } else {
729742 // Add root node.
730743 if (!root.is_null ()) {
731- ERR_FAIL_V_MSG (false , " PList: Root node already set." );
744+ r_err_out = " Root node already set." ;
745+ return false ;
732746 }
733747 Ref<PListNode> arr = PListNode::new_array ();
734748 stack.push_back (arr);
@@ -740,7 +754,8 @@ bool PList::load_string(const String &p_string) {
740754 if (token == " /array" ) {
741755 // Exit current array.
742756 if (stack.is_empty () || stack.back ()->get ()->data_type != PList::PLNodeType::PL_NODE_TYPE_ARRAY) {
743- ERR_FAIL_V_MSG (false , " PList: Mismatched </array> tag." );
757+ r_err_out = " Mismatched </array> tag." ;
758+ return false ;
744759 }
745760 stack.pop_back ();
746761 continue ;
@@ -751,13 +766,15 @@ bool PList::load_string(const String &p_string) {
751766 } else {
752767 int end_token_s = p_string.find (" </" , pos);
753768 if (end_token_s == -1 ) {
754- ERR_FAIL_V_MSG (false , vformat (" PList: Mismatched <%s> tag." , token));
769+ r_err_out = vformat (" Mismatched <%s> tag." , token);
770+ return false ;
755771 }
756772 int end_token_e = p_string.find (" >" , end_token_s);
757773 pos = end_token_e;
758774 String end_token = p_string.substr (end_token_s + 2 , end_token_e - end_token_s - 2 );
759775 if (end_token != token) {
760- ERR_FAIL_V_MSG (false , vformat (" PList: Mismatched <%s> and <%s> token pair." , token, end_token));
776+ r_err_out = vformat (" Mismatched <%s> and <%s> token pair." , token, end_token);
777+ return false ;
761778 }
762779 value = p_string.substr (open_token_e + 1 , end_token_s - open_token_e - 1 );
763780 }
@@ -780,15 +797,18 @@ bool PList::load_string(const String &p_string) {
780797 } else if (token == " date" ) {
781798 var = PListNode::new_date (value);
782799 } else {
783- ERR_FAIL_V_MSG (false , " PList: Invalid value type." );
800+ r_err_out = vformat (" Invalid value type: %s." , token);
801+ return false ;
784802 }
785803 if (stack.is_empty () || !stack.back ()->get ()->push_subnode (var, key)) {
786- ERR_FAIL_V_MSG (false , " PList: Can't push subnode, invalid parent type." );
804+ r_err_out = " Can't push subnode, invalid parent type." ;
805+ return false ;
787806 }
788807 }
789808 }
790809 if (!stack.is_empty () || !done_plist) {
791- ERR_FAIL_V_MSG (false , " PList: Unexpected end of data. Root node is not closed." );
810+ r_err_out = " Unexpected end of data. Root node is not closed." ;
811+ return false ;
792812 }
793813 return true ;
794814}
0 commit comments