@@ -78,6 +78,52 @@ namespace folia {
7878 return result;
7979 }
8080
81+ bool TextContent::addable ( const FoliaElement *parent ) const {
82+ // / test if an TextContent might succesfully appended to \em parent
83+ /* !
84+ * \param parent the node to check
85+ * \return true if it doesn't throw
86+ *
87+ * \note It will allways throw an error, instead of returning false
88+ */
89+ if ( AbstractElement::addable ( parent ) ){
90+ string my_cls = cls ();
91+ if ( parent->isinstance <Word>() ) {
92+ string val = str (my_cls);
93+ val = trim ( val );
94+ if ( val.empty () ) {
95+ // we have to check for a child with the IMPLICITSPACE property
96+ // ONLY in that case, an "empty" text is allowed.
97+ auto implicit = []( auto elt ){ return elt->implicitspace (); };
98+ bool has_implicit = std::any_of ( data ().begin (), data ().end (),
99+ implicit );
100+ if ( !has_implicit ){
101+ throw ValueError ( this ,
102+ " attempt to add an empty <t> to word: "
103+ + parent->id () );
104+ }
105+ }
106+ }
107+ string st = sett ();
108+ vector<TextContent*> tmp
109+ = parent->select <TextContent>( st,
110+ SELECT_FLAGS::LOCAL );
111+ if ( any_of ( tmp.cbegin (),
112+ tmp.cend (),
113+ [my_cls]( const TextContent *t) { return ( t->cls () == my_cls);} ) ){
114+ throw DuplicateAnnotationError ( this ,
115+ " attempt to add <t> with class="
116+ + my_cls + " to element: "
117+ + parent->id ()
118+ + " which already has a <t> with that class" );
119+ }
120+ }
121+ if ( is_textcontainer () ){
122+ parent->check_append_text_consistency ( this );
123+ }
124+ return true ;
125+ }
126+
81127 FoliaElement *TextContent::postappend ( ) {
82128 // / perform some extra checks after appending a TextContent
83129 if ( doc () ){
@@ -1386,6 +1432,34 @@ namespace folia {
13861432 return result;
13871433 }
13881434
1435+ bool WordReference::addable ( const FoliaElement *parent ) const {
1436+ // / test if a reference might succesfully appended to \em parent
1437+ /* !
1438+ * \param parent the node to check
1439+ * \return true if it doesn't throw
1440+ *
1441+ * \note It will allways throw an error, instead of returning false
1442+ */
1443+ if ( AbstractElement::addable ( parent ) ){
1444+ if ( !_tval.empty () ){
1445+ string watt = _ref->str (parent->textclass ());
1446+ if ( watt.empty () ){
1447+ string msg = " no matching 't' value found in the '<w>' refered by "
1448+ " <wref id=\" " + _ref->id () + " \" t=\" " + _tval
1449+ + " \" > for textclass '" + parent->textclass () + " '" ;
1450+ throw XmlError ( this , msg );
1451+ }
1452+ else if ( watt != _tval ){
1453+ string msg = " the 't' value of <wref id=\" " + _ref->id ()
1454+ + " \" t=\" " + _tval + " \" > for textclass '" + parent->textclass ()
1455+ + " ' doesn't match any value of the refered word for that class" ;
1456+ throw XmlError ( this , msg );
1457+ }
1458+ }
1459+ }
1460+ return true ;
1461+ }
1462+
13891463 FoliaElement* WordReference::parseXml ( const xmlNode *node ) {
13901464 // / parse a WordReference node at node
13911465 /* !
0 commit comments