@@ -138,7 +138,7 @@ int type_validator::compare(std::string_view a, std::string_view b) const
138
138
ra = selected_charconv<double >::from_chars (a.data (), a.data () + a.length (), da);
139
139
rb = selected_charconv<double >::from_chars (b.data (), b.data () + b.length (), db);
140
140
141
- if (not (bool )ra.ec and not (bool )rb.ec )
141
+ if (not (bool ) ra.ec and not (bool ) rb.ec )
142
142
{
143
143
auto d = da - db;
144
144
if (std::abs (d) > std::numeric_limits<double >::epsilon ())
@@ -232,7 +232,7 @@ bool item_validator::validate_value(std::string_view value, std::error_code &ec)
232
232
ec = make_error_code (validation_error::value_is_not_in_enumeration_list);
233
233
}
234
234
235
- return not (bool )ec;
235
+ return not (bool ) ec;
236
236
}
237
237
238
238
// --------------------------------------------------------------------
@@ -408,9 +408,7 @@ void validator::report_error(std::error_code ec, bool fatal) const
408
408
void validator::report_error (std::error_code ec, std::string_view category,
409
409
std::string_view item, bool fatal) const
410
410
{
411
- auto ex = item.empty () ?
412
- validation_exception (ec, category) :
413
- validation_exception (ec, category, item);
411
+ auto ex = item.empty () ? validation_exception (ec, category) : validation_exception (ec, category, item);
414
412
415
413
if (m_strict or fatal)
416
414
throw ex;
@@ -455,59 +453,71 @@ const validator &validator_factory::operator[](std::string_view dictionary_name)
455
453
}
456
454
457
455
// not found, add it
458
- auto data = load_resource (dictionary_name);
459
456
460
- if (not data and dictionary.extension ().string () != " .dic" )
461
- data = load_resource (dictionary.parent_path () / (dictionary.filename ().string () + " .dic" ));
457
+ validator v (dictionary_name);
462
458
463
- if (data)
464
- construct_validator (dictionary_name, *data);
465
- else
459
+ for (bool first = true ; auto part_name : cif::split (dictionary_name, " ;" , true ))
466
460
{
467
- std::error_code ec;
461
+ auto data = load_resource (part_name);
462
+ dictionary.assign (part_name.begin (), part_name.end ());
468
463
469
- // might be a compressed dictionary on disk
470
- std::filesystem::path p = dictionary;
471
- if (p.extension () == " .dic" )
472
- p = p.parent_path () / (p.filename ().string () + " .gz" );
473
- else
474
- p = p.parent_path () / (p.filename ().string () + " .dic.gz" );
464
+ if (not data and dictionary.extension ().string () != " .dic" )
465
+ data = load_resource (dictionary.parent_path () / (dictionary.filename ().string () + " .dic" ));
475
466
476
- #if defined(CACHE_DIR) or defined(DATA_DIR)
477
- if (not std::filesystem::exists (p, ec) or ec)
467
+ if (not data)
478
468
{
479
- for (const char *dir : {
469
+ std::error_code ec;
470
+
471
+ // might be a compressed dictionary on disk
472
+ std::filesystem::path p = dictionary;
473
+ if (p.extension () == " .dic" )
474
+ p = p.parent_path () / (p.filename ().string () + " .gz" );
475
+ else
476
+ p = p.parent_path () / (p.filename ().string () + " .dic.gz" );
477
+
478
+ #if defined(CACHE_DIR) or defined(DATA_DIR)
479
+ if (not std::filesystem::exists (p, ec) or ec)
480
+ {
481
+ for (const char *dir : {
480
482
# if defined(CACHE_DIR)
481
- CACHE_DIR,
483
+ CACHE_DIR,
482
484
# endif
483
485
# if defined(DATA_DIR)
484
486
DATA_DIR
485
487
# endif
486
- })
487
- {
488
- auto p2 = std::filesystem::path (dir) / p;
489
- if (std::filesystem::exists (p2, ec) and not ec)
488
+ })
490
489
{
491
- swap (p, p2);
492
- break ;
490
+ auto p2 = std::filesystem::path (dir) / p;
491
+ if (std::filesystem::exists (p2, ec) and not ec)
492
+ {
493
+ swap (p, p2);
494
+ break ;
495
+ }
493
496
}
494
497
}
495
- }
496
498
#endif
497
499
498
- if (std::filesystem::exists (p, ec) and not ec)
499
- {
500
- gzio::ifstream in (p);
500
+ if (std::filesystem::exists (p, ec) and not ec)
501
+ {
502
+ auto in = std::make_unique< gzio::ifstream> (p);
501
503
502
- if (not in. is_open ())
503
- throw std::runtime_error (" Could not open dictionary (" + p.string () + " )" );
504
+ if (not in-> is_open ())
505
+ throw std::runtime_error (" Could not open dictionary (" + p.string () + " )" );
504
506
505
- construct_validator (dictionary_name, in);
507
+ data.reset (in.release ());
508
+ }
509
+ else
510
+ throw std::runtime_error (" Dictionary not found or defined (" + dictionary.string () + " )" );
506
511
}
512
+
513
+ if (std::exchange (first, false ))
514
+ v = parse_dictionary (part_name, *data);
507
515
else
508
- throw std::runtime_error ( " Dictionary not found or defined ( " + dictionary. string () + " ) " );
516
+ extend_dictionary (v, *data );
509
517
}
510
518
519
+ m_validators.emplace_back (std::move (v));
520
+
511
521
return m_validators.back ();
512
522
}
513
523
catch (const std::exception &ex)
0 commit comments