373 static std::vector<FormatInstruction>
compile(
const std::string& pattern) {
374 std::cout <<
"-1" << std::endl;
376 std::vector<FormatInstruction> instructions;
378 buffer.reserve(pattern.size());
379 bool strip_ansi =
false;
381 for (
size_t i = 0; i < pattern.size(); ++i) {
385 if (!buffer.empty()) {
391 bool left_align =
false;
392 bool center_align =
false;
393 bool truncate =
false;
397 while ((i + 1) < pattern.size() && (
398 std::isdigit(pattern[i + 1]) ||
399 pattern[i + 1] ==
'-' ||
400 pattern[i + 1] ==
'=')) {
401 char next = pattern[++i];
404 }
else if (next ==
'=') {
406 }
else if (std::isdigit(next)) {
407 width = width * 10 + (next -
'0');
411 if ((i + 1) < pattern.size() && pattern[i + 1] ==
'!') {
418 if ((i + 1) < pattern.size()) {
419 char next = pattern[++i];
423 instructions.emplace_back(FormatType::Year, width, left_align, center_align, truncate, strip_ansi);
426 if ((i + 1) < pattern.size() && pattern[i + 1] ==
's') {
427 instructions.emplace_back(FormatType::MilliSecondTimeStamp, width, left_align, center_align, truncate, strip_ansi);
431 instructions.emplace_back(FormatType::Month, width, left_align, center_align, truncate, strip_ansi);
434 instructions.emplace_back(FormatType::Day, width, left_align, center_align, truncate, strip_ansi);
437 instructions.emplace_back(FormatType::Hour, width, left_align, center_align, truncate, strip_ansi);
440 instructions.emplace_back(FormatType::Minute, width, left_align, center_align, truncate, strip_ansi);
443 if ((i + 1) < pattern.size() && pattern[i + 1] ==
'C') {
448 instructions.emplace_back(FormatType::Second, width, left_align, center_align, truncate, strip_ansi);
451 if ((i + 1) < pattern.size() && pattern[i + 1] ==
'c') {
456 instructions.emplace_back(FormatType::Millisecond, width, left_align, center_align, truncate, strip_ansi);
459 instructions.emplace_back(FormatType::TwoDigitYear, width, left_align, center_align, truncate, strip_ansi);
462 instructions.emplace_back(FormatType::DateTime, width, left_align, center_align, truncate, strip_ansi);
465 instructions.emplace_back(FormatType::ShortDate, width, left_align, center_align, truncate, strip_ansi);
469 instructions.emplace_back(FormatType::TimeISO8601, width, left_align, center_align, truncate, strip_ansi);
472 instructions.emplace_back(FormatType::DateISO8601, width, left_align, center_align, truncate, strip_ansi);
475 if ((i + 1) < pattern.size() && pattern[i + 1] ==
'c') {
481 if ((i + 1) < pattern.size() && pattern[i + 1] ==
'C') {
486 instructions.emplace_back(FormatType::TimeStamp, width, left_align, center_align, truncate, strip_ansi);
491 if ((i + 1) < pattern.size() && pattern[i + 1] ==
's') {
492 instructions.emplace_back(FormatType::FileName, width, left_align, center_align, truncate, strip_ansi);
496 instructions.emplace_back(FormatType::AbbreviatedMonthName, width, left_align, center_align, truncate, strip_ansi);
499 instructions.emplace_back(FormatType::FullMonthName, width, left_align, center_align, truncate, strip_ansi);
502 instructions.emplace_back(FormatType::AbbreviatedWeekdayName, width, left_align, center_align, truncate, strip_ansi);
505 instructions.emplace_back(FormatType::FullWeekdayName, width, left_align, center_align, truncate, strip_ansi);
510 instructions.emplace_back(FormatType::LogLevel, width, left_align, center_align, truncate, strip_ansi);
513 instructions.emplace_back(FormatType::ShortLogLevel, width, left_align, center_align, truncate, strip_ansi);
518 instructions.emplace_back(FormatType::ThreadId, width, left_align, center_align, truncate, strip_ansi);
523 if ((i + 1) < pattern.size() && pattern[i + 1] ==
'f' && (i + 2) < pattern.size() && pattern[i + 2] ==
'n') {
524 instructions.emplace_back(FormatType::FullFileName, width, left_align, center_align, truncate, strip_ansi);
528 if ((i + 1) < pattern.size() && pattern[i + 1] ==
'n') {
529 instructions.emplace_back(FormatType::FileName, width, left_align, center_align, truncate, strip_ansi);
533 instructions.emplace_back(FormatType::FileName, width, left_align, center_align, truncate, strip_ansi);
536 instructions.emplace_back(FormatType::FullFileName, width, left_align, center_align, truncate, strip_ansi);
539 instructions.emplace_back(FormatType::SourceFileAndLine, width, left_align, center_align, truncate, strip_ansi);
542 instructions.emplace_back(FormatType::LineNumber, width, left_align, center_align, truncate, strip_ansi);
545 instructions.emplace_back(FormatType::FunctionName, width, left_align, center_align, truncate, strip_ansi);
550 instructions.emplace_back(FormatType::StartColor, 0,
false,
false,
false, strip_ansi);
553 instructions.emplace_back(FormatType::EndColor, 0,
false,
false,
false, strip_ansi);
558 instructions.emplace_back(FormatType::Message, width, left_align, center_align, truncate, strip_ansi);
573 if (!buffer.empty()) {