@@ -322,7 +322,7 @@ namespace rdf4cpp::parser::json_ld {
322322 if (t.value ().get (v) != simdjson::SUCCESS || v != keyword_set) {
323323 return make_error (ParsingError::Type::BadSyntax, " keyword redefinition (@type invalid @container)" );
324324 }
325- p.term .container_mapping . emplace_back (keyword_set) ;
325+ p.term .container_mapping |= ContainerMapping::Set ;
326326 any = true ;
327327 } else if (k == keyword_protected) {
328328 bool v;
@@ -504,7 +504,7 @@ namespace rdf4cpp::parser::json_ld {
504504 return make_error (ParsingError::Type::BadSyntax, " invalid reverse property" );
505505 }
506506 if (v_cont.is_null ()) {
507- p.term .container_mapping . clear () ;
507+ p.term .container_mapping = ContainerMapping::None ;
508508 } else {
509509 std::string_view cont;
510510 if (v_cont.get (cont) != simdjson::SUCCESS ) {
@@ -513,8 +513,7 @@ namespace rdf4cpp::parser::json_ld {
513513 if (cont != keyword_set && cont != keyword_index) {
514514 return make_error (ParsingError::Type::BadSyntax, " invalid reverse property" );
515515 }
516- p.term .container_mapping .clear ();
517- p.term .container_mapping .emplace_back (cont);
516+ p.term .container_mapping = keyword_to_container_mapping (cont);
518517 }
519518 }
520519
@@ -592,72 +591,63 @@ namespace rdf4cpp::parser::json_ld {
592591 }
593592 }
594593 }
595- auto container_contains = [&](std::string_view x) {
596- return std::ranges::find (p.term .container_mapping , x) != p.term .container_mapping .end ();
597- };
598594 { // 19
599595 auto [c, v] = try_get_field<simdjson::ondemand::value>(ob, keyword_container);
600596 if (c != simdjson::NO_SUCH_FIELD ) {
601- auto is_valid_keyword = [](std::string_view v) {
602- static constexpr std::array valid = {keyword_graph, keyword_id, keyword_index, keyword_language, keyword_list, keyword_set, keyword_type};
603- return std::ranges::any_of (valid, [v](std::string_view a) {
604- return a == v;
605- });
606- };
607597 if (v.is_string ()) {
608- auto d = static_cast <std::string_view>(v);
609- if (! is_valid_keyword (d) ) {
598+ auto d = keyword_to_container_mapping ( static_cast <std::string_view>(v) );
599+ if (d == ContainerMapping::None ) {
610600 return make_error (ParsingError::Type::BadSyntax, " invalid container mapping" );
611601 }
612- p.term .container_mapping .clear ();
613- p.term .container_mapping .emplace_back (d);
602+ p.term .container_mapping = d;
614603 } else {
615604 simdjson::ondemand::array a;
616605 if (v.get (a) != simdjson::SUCCESS ) {
617606 return make_error (ParsingError::Type::BadSyntax, " invalid container mapping" );
618607 }
619- p.term .container_mapping . clear () ;
608+ p.term .container_mapping = ContainerMapping::None ;
620609 for (auto w : a) {
621610 std::string_view x;
622611 if (w.get (x) != simdjson::SUCCESS ) {
623612 return make_error (ParsingError::Type::BadSyntax, " invalid container mapping" );
624613 }
625- if (!is_valid_keyword (x)) {
614+ auto container_mapping = keyword_to_container_mapping (x);
615+ if (container_mapping == ContainerMapping::None) {
626616 return make_error (ParsingError::Type::BadSyntax, " invalid container mapping" );
627617 }
628- p.term .container_mapping . emplace_back (x) ;
618+ p.term .container_mapping |= container_mapping ;
629619 }
630620 }
631- if (p.term .container_mapping . empty () ) {
621+ if (p.term .container_mapping == ContainerMapping::None ) {
632622 return make_error (ParsingError::Type::BadSyntax, " invalid container mapping" );
633623 }
634- if (p.term .container_mapping . size () > 1 ) {
635- auto only = [&](std::initializer_list<std::string_view > x) {
636- return std::ranges::all_of (p. term . container_mapping , [&](std::string_view d) {
637- return std::ranges::any_of (x, [&](std::string_view a ) {
638- return a == d ;
639- });
640- }) ;
624+ if (p.term .container_mapping_size () > 1 ) {
625+ auto only = [&](std::initializer_list<ContainerMapping > x) {
626+ ContainerMapping check = ContainerMapping::None;
627+ for ( auto e : x ) {
628+ check |= e ;
629+ }
630+ return (p. term . container_mapping & ~check) == ContainerMapping::None ;
641631 };
642- bool graph = container_contains (keyword_graph );
632+ bool graph = p. term . has_container_mapping (ContainerMapping::Graph );
643633 if (graph) {
644- auto id = container_contains (keyword_id );
645- auto index = container_contains (keyword_index );
634+ auto id = p. term . has_container_mapping (ContainerMapping::Id );
635+ auto index = p. term . has_container_mapping (ContainerMapping::Index );
646636 if (index == id) { // xor
647637 graph = false ;
648638 } else {
649- graph = only ({keyword_graph, keyword_id, keyword_index, keyword_set });
639+ graph = only ({ContainerMapping::Graph, ContainerMapping::Id, ContainerMapping::Index, ContainerMapping::Set });
650640 }
651641 }
652- bool set = container_contains (keyword_set );
642+ bool set = p. term . has_container_mapping (ContainerMapping::Set );
653643 if (set) {
654- set = only ({keyword_set, keyword_index, keyword_graph, keyword_id, keyword_type, keyword_language });
644+ set = only ({ContainerMapping::Set, ContainerMapping::Index, ContainerMapping::Graph, ContainerMapping::Id, ContainerMapping::Type, ContainerMapping::Language });
655645 }
656646 if (!set && !graph) {
657647 return make_error (ParsingError::Type::BadSyntax, " invalid container mapping" );
658648 }
659649 }
660- if (container_contains (keyword_type )) {
650+ if (p. term . has_container_mapping (ContainerMapping::Type )) {
661651 if (!p.term .type_mapping .has_value ()) {
662652 p.term .type_mapping = keyword_id;
663653 }
@@ -673,7 +663,7 @@ namespace rdf4cpp::parser::json_ld {
673663 if (c != simdjson::SUCCESS ) {
674664 return make_error (ParsingError::Type::BadSyntax, " invalid term definition" );
675665 }
676- if (!container_contains (keyword_index )) {
666+ if (!p. term . has_container_mapping (ContainerMapping::Index )) {
677667 return make_error (ParsingError::Type::BadSyntax, " invalid term definition" );
678668 }
679669 params::ParseContextIRIExpansionParams p_ctx{
0 commit comments