QString VisualLog::MessageInfo::expand(const QString &pattern) const{ QString base = ""; QDateTime dt = stamp(); QString::const_iterator it = pattern.begin(); while ( it != pattern.end() ){ if ( *it == QChar('%') ){ ++it; if ( it != pattern.end() ){ char c = it->toLatin1(); switch(c){ case 'p': { if ( m_location && !m_location->remote.isEmpty() ) base += m_location->remote + "> "; base += QString().sprintf( "%0*d-%0*d-%0*d %0*d:%0*d:%0*d.%0*d %s %s@%d: ", 4, dt.date().year(), 2, dt.date().month(), 2, dt.date().day(), 2, dt.time().hour(), 2, dt.time().minute(), 2, dt.time().second(), 3, dt.time().msec(), qPrintable(levelToString(m_level).toLower()), qPrintable(sourceFunctionName()), sourceLineNumber() ); break; } case 'r': base += sourceRemoteLocation(); break; case 'F': base += sourceFileName(); break; case 'N': base += extractFileNameSegment(sourceFileName()); break; case 'U': base += sourceFunctionName(); break; case 'L': base += QString::number(sourceLineNumber()); break; case 'V': base += levelToString(m_level); break; case 'v': base += levelToString(m_level).toLower(); break; case 'w': base += QDate::shortDayName(dt.date().dayOfWeek()); break; case 'W': base += QDate::longDayName(dt.date().dayOfWeek()); break; case 'b': base += QDate::shortMonthName(dt.date().month()); break; case 'B': base += QDate::longMonthName(dt.date().month()); break; case 'd': base += QString().sprintf("%0*d", 2, dt.date().day() ); break; case 'e': base += QString().sprintf("%d", dt.date().day() ); break; case 'f': base += QString().sprintf("%*d", 2, dt.date().day() ); break; case 'm': base += QString().sprintf("%0*d", 2, dt.date().month() ); break; case 'n': base += QString().sprintf("%d", dt.date().month() ); break; case 'o': base += QString().sprintf("%*d", 2, dt.date().month() ); break; case 'y': base += QString().sprintf("%0*d", 2, dt.date().year() % 100 ); break; case 'Y': base += QString().sprintf("%0*d", 4, dt.date().year() ); break; case 'H': base += QString().sprintf("%0*d", 2, dt.time().hour() ); break; case 'I': { int hour = dt.time().hour(); base += QString().sprintf("%0*d", 2, (hour < 1 ? 12 : (hour > 12 ? hour - 12 : hour))); break; } case 'a': base += QString().sprintf(dt.time().hour() < 12 ? "am" : "pm" ); break; case 'A': base += QString().sprintf(dt.time().hour() < 12 ? "AM" : "PM" ); break; case 'M': base += QString().sprintf("%0*d", 2, dt.time().minute()); break; case 'S': base += QString().sprintf("%0*d", 2, dt.time().second() ); break; case 's': base += QString().sprintf("%0*d.%0*d", 2, dt.time().second(), 3, dt.time().msec() ); break; case 'i': base += QString().sprintf("%0*d", 3, dt.time().msec() ); break; case 'c': base += QString().sprintf("%d", dt.time().msec() / 100 ); break; default: base += *it; } } } else { base += *it; } ++it; } return base; }
Arguments::Arguments( const QString &a ) { _arguments.clear(); QString current_arg; bool between_arguments = false; bool quoted_argument = false; bool escape = false; for( QString::const_iterator itChar = a.begin(); itChar != a.end(); ++itChar ) { if ( between_arguments ) { switch ( itChar->toLatin1() ) { case '"': quoted_argument = true; between_arguments = false; current_arg.clear(); break; case ' ': case '\r': case '\n': case '\t': break; default: quoted_argument = false; between_arguments = false; current_arg = *itChar; break; } } else { if ( escape ) { escape = false; current_arg += *itChar; } else { switch ( itChar->toLatin1() ) { case '"': quoted_argument = !quoted_argument; break; case ' ': case '\r': case '\n': case '\t': if ( quoted_argument ) current_arg += *itChar; else { _arguments << current_arg; between_arguments = true; } break; case '\\': escape = true ; break; default: current_arg += *itChar; break; } } } } if ( !between_arguments ) _arguments << current_arg; calcArguments(); }