MCPcopy Create free account
hub / github.com/Xtra-Computing/thundersvm / parseLine

Method parseLine

src/thundersvm/util/log.cpp:399–457  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

397 }
398
399 bool Configurations::Parser::parseLine(std::string* line, std::string* currConfigStr, std::string* currLevelStr,
400 Level* currLevel,
401 Configurations* conf) {
402 ConfigurationType currConfig = ConfigurationType::Unknown;
403 std::string currValue = std::string();
404 *line = base::utils::Str::trim(*line);
405 if (isComment(*line)) return true;
406 ignoreComments(line);
407 *line = base::utils::Str::trim(*line);
408 if (line->empty()) {
409 // Comment ignored
410 return true;
411 }
412 if (isLevel(*line)) {
413 if (line->size() <= 2) {
414 return true;
415 }
416 *currLevelStr = line->substr(1, line->size() - 2);
417 *currLevelStr = base::utils::Str::toUpper(*currLevelStr);
418 *currLevelStr = base::utils::Str::trim(*currLevelStr);
419 *currLevel = LevelHelper::convertFromString(currLevelStr->c_str());
420 return true;
421 }
422 if (isConfig(*line)) {
423 std::size_t assignment = line->find('=');
424 *currConfigStr = line->substr(0, assignment);
425 *currConfigStr = base::utils::Str::toUpper(*currConfigStr);
426 *currConfigStr = base::utils::Str::trim(*currConfigStr);
427 currConfig = ConfigurationTypeHelper::convertFromString(currConfigStr->c_str());
428 currValue = line->substr(assignment + 1);
429 currValue = base::utils::Str::trim(currValue);
430 std::size_t quotesStart = currValue.find("\"", 0);
431 std::size_t quotesEnd = std::string::npos;
432 if (quotesStart != std::string::npos) {
433 quotesEnd = currValue.find("\"", quotesStart + 1);
434 while (quotesEnd != std::string::npos && currValue.at(quotesEnd - 1) == '\\') {
435 currValue = currValue.erase(quotesEnd - 1, 1);
436 quotesEnd = currValue.find("\"", quotesEnd + 2);
437 }
438 }
439 if (quotesStart != std::string::npos && quotesEnd != std::string::npos) {
440 // Quote provided - check and strip if valid
441 ELPP_ASSERT((quotesStart < quotesEnd), "Configuration error - No ending quote found in ["
442 << currConfigStr << "]");
443 ELPP_ASSERT((quotesStart + 1 != quotesEnd), "Empty configuration value for [" << currConfigStr << "]");
444 if ((quotesStart != quotesEnd) && (quotesStart + 1 != quotesEnd)) {
445 // Explicit check in case if assertion is disabled
446 currValue = currValue.substr(quotesStart + 1, quotesEnd - 1);
447 }
448 }
449 }
450 ELPP_ASSERT(*currLevel != Level::Unknown, "Unrecognized severity level [" << *currLevelStr << "]");
451 ELPP_ASSERT(currConfig != ConfigurationType::Unknown, "Unrecognized configuration [" << *currConfigStr << "]");
452 if (*currLevel == Level::Unknown || currConfig == ConfigurationType::Unknown) {
453 return false; // unrecognizable level or config
454 }
455 conf->set(*currLevel, currConfig, currValue);
456 return true;

Callers

nothing calls this directly

Calls 3

setMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected