void message_handler(QtMsgType type, const QMessageLogContext & context, const QString & message) { QString formated_message; QString (*formater)(const QString & message_type, const QMessageLogContext & context, const QString & message); // formater = format_log; #ifdef ANDROID formater = format_log; #else formater = format_log_with_ansi; #endif switch (type) { case QtDebugMsg: formated_message = formater(QLatin1Literal("Debug"), context, message); break; case QtInfoMsg: formated_message = formater(QLatin1Literal("Info"), context, message); break; case QtWarningMsg: formated_message = formater(QLatin1Literal("Warning"), context, message); break; case QtCriticalMsg: formated_message = formater(QLatin1Literal("Critical"), context, message); break; case QtFatalMsg: formated_message = formater(QLatin1Literal("Fatal"), context, message); } // stderr fprintf(stdout, formated_message.toStdString().c_str()); // # QByteArray local_message = message.toLocal8Bit(); if (type == QtFatalMsg) abort(); }
TEST_F(OutputFormatterTest, OtherCharacterAfterBackslashInFormatString) { std::wstring format_str(L"%p\\d %p"); OutputFormatter formater(&input, format_str); auto res = formater.Format(); EXPECT_TRUE((*res)[0] == std::wstring(L"my_file1\\d my_file1")); EXPECT_TRUE((*res)[1] == std::wstring(L"my_file2\\d my_file2")); }
TEST_F(OutputFormatterTest, HorizontalTabInFormatString) { std::wstring format_str(L"%p\\t%p"); OutputFormatter formater(&input, format_str); auto res = formater.Format(); EXPECT_TRUE((*res)[0] == std::wstring(L"my_file1 my_file1")); EXPECT_TRUE((*res)[1] == std::wstring(L"my_file2 my_file2")); }
TEST_F(OutputFormatterTest, EscapedBackslashInFormatString) { std::wstring format_str(L"%p\\\\%p\\\\"); OutputFormatter formater(&input, format_str); auto res = formater.Format(); EXPECT_TRUE((*res)[0] == std::wstring(L"my_file1\\my_file1\\")); EXPECT_TRUE((*res)[1] == std::wstring(L"my_file2\\my_file2\\")); }
std::string CategoryMusicCache::file() const { boost::format formater("%s%s%s%d%s%d%s"); formater % _dir % constant::config::catsong % "_" % _catid % "_" % _page % ".json"; return formater.str(); }
int main (int argc, char *argv[]) { struct queryopt opt; struct ofields *fields; struct select_doc *s_doc; struct query_doc *qu_doc; struct db_connect *db_conn; struct output *out; struct db_cursor *db_c; struct results *res; opt.e_skip = 0; // standard opt.e_ret = 0; // standard opt.bsever = 0; opt.blevel = 0; opt.bdate = 0; opt.bdateu = 0; opt.bdatef = 0; opt.bmsg = 0; opt.bskip = 0; opt.bsys = 0; getoptions(argc, argv, &opt); qu_doc = create_query(&opt); // crate query s_doc = create_select(); db_conn = create_conn(); // create connection out = launch_query(&opt, s_doc, qu_doc, db_conn); // launch the query db_c = open_cursor(db_conn, out); // open cursor while (cursor_next(db_c)) { res = read_data(db_c); fields = get_data(res); formater(fields); // formate output free(fields); free(res); } free_cursor(db_c); close_conn(db_conn); free(out); free(s_doc); free(qu_doc); return (0); }
std::string ScanSong(std::string fileName, bool doReplayGain) { BassSource bassSource; AvSource avSource; bool bassLoaded = bassSource.Load(fileName, true); bool avLoaded = bassLoaded ? false : avSource.Load(fileName); uint32_t channels = 0; std::string type; double length = 0; uint32_t samplerate = 0; uint32_t bitrate = 0; Machine* decoder = 0; if (bassLoaded) { channels = bassSource.Channels(); type = bassSource.CodecType(); length = bassSource.Duration(); samplerate = bassSource.Samplerate(); bitrate = bassSource.Bitrate(); decoder = static_cast<Machine*>(&bassSource); } if (avLoaded) { channels = avSource.Channels(); type = avSource.CodecType(); samplerate = avSource.Samplerate(); bitrate = avSource.Bitrate(); decoder = static_cast<Machine*>(&avSource); } if (!avLoaded && !bassLoaded) logror::Fatal("unknown format"); if (samplerate == 0) logror::Fatal("samplerate is zero"); if (channels < 1 || channels > 2) logror::Fatal("unsupported number of channels"); uint64_t frameCounter = 0; RG_SampleFormat format = {samplerate, RG_FLOAT_32_BIT, channels, FALSE}; RG_Context* context = RG_NewContext(&format); AudioStream stream; if (doReplayGain || avLoaded) while (!stream.endOfStream) { decoder->Process(stream, 48000); float* buffers[2] = {stream.Buffer(0), channels == 2 ? stream.Buffer(1) : NULL}; if (doReplayGain) RG_Analyze(context, buffers, stream.Frames()); frameCounter += stream.Frames(); } double replayGain = RG_GetTitleGain(context); RG_FreeContext(context); if (avLoaded) length = static_cast<double>(frameCounter) / samplerate; std::string msg = "type:%1%\nlength:%2%\n"; if (doReplayGain) msg.append("replay gain:%3%\n"); if (bassSource.IsModule()) msg.append("loopiness:%6%"); else msg.append("bitrate:%4%\nsamplerate:%5%"); boost::format formater(msg); formater.exceptions(boost::io::no_error_bits); return str(formater % type % length % replayGain % bitrate % samplerate % bassSource.Loopiness()); }