Skip to content

Commit daf992e

Browse files
committed
simplified checking of empty <t> nodes
1 parent 1690265 commit daf992e

1 file changed

Lines changed: 14 additions & 24 deletions

File tree

src/folia_impl.cxx

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,7 +1715,7 @@ namespace folia {
17151715
cerr << "DEBUG: BEGIN check_text_consistency_while_parsing("
17161716
<< trim_spaces << ")" << endl;
17171717
}
1718-
map<string,bool> text_found;
1718+
// map<string,bool> text_found;
17191719
// check the text for every possible text class
17201720
for ( const auto& st : doc()->textclasses() ){
17211721
UnicodeString s1, s2;
@@ -1732,7 +1732,7 @@ namespace folia {
17321732
catch (...){
17331733
}
17341734
if ( !s1.isEmpty() ){
1735-
text_found[st] = true;
1735+
// text_found[st] = true;
17361736
if ( debug ){
17371737
cerr << "S1: " << s1 << endl;
17381738
}
@@ -1795,30 +1795,20 @@ namespace folia {
17951795
}
17961796
}
17971797
}
1798-
else {
1799-
auto is_text_node = []( auto elt ){ return elt->element_id() == XmlText_t; };
1800-
text_found[st] = std::any_of( _data.begin(), _data.end(),
1801-
is_text_node );
1802-
}
1798+
// else {
1799+
// auto is_text_node = []( auto elt ){ return elt->element_id() == XmlText_t; };
1800+
// text_found[st] = std::any_of( _data.begin(), _data.end(),
1801+
// is_text_node );
1802+
// }
18031803
}
18041804
if ( element_id() == TextContent_t ){
1805-
bool none_found = true;
1806-
for ( const auto& it : text_found ){
1807-
if ( it.second ) {
1808-
none_found = false;
1809-
}
1810-
}
1811-
if ( none_found ){
1812-
// we have to check for a child with the IMPLICITSPACE property
1813-
// ONLY in that case, an "empty" text is allowed.
1814-
auto implicit = []( auto elt ){ return elt->implicitspace(); };
1815-
bool has_implicit = std::any_of( _data.begin(), _data.end(),
1816-
implicit );
1817-
if ( has_implicit ){
1818-
none_found = false;
1819-
}
1820-
}
1821-
if ( none_found ){
1805+
// we have to check for at least one XmlText or TEXTCONTAINER child
1806+
auto valid_text = []( auto elt ){
1807+
return ( elt->element_id() == XmlText_t
1808+
|| elt->is_textcontainer() ); };
1809+
bool found = std::any_of( _data.begin(), _data.end(),
1810+
valid_text );
1811+
if ( !found ){
18221812
string msg = "Empty text content elements are not allowed. Parsing <"
18231813
+ xmltag() + ">, id=" + id();
18241814
throw XmlError( msg );

0 commit comments

Comments
 (0)