mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
update cppcommon
This commit is contained in:
parent
83a8474a1d
commit
4078887be5
@ -33,7 +33,7 @@ vec_functs.test: vec_functs.cpp vec_functs.h vec_functs.tcc
|
||||
g++ -o $@ $< -DTEST_VEC_FUNCTS
|
||||
|
||||
logger.ut: logger.cpp logger.h file_functs.cpp file_functs.h
|
||||
g++ -o $@ $< file_functs.cpp -DUNIT_TEST
|
||||
g++ -o $@ $< file_functs.cpp -DLOGGER_UT
|
||||
config.ut: config.cpp config.h
|
||||
g++ -o $@ $< -DCONFIG_UT $(CMLIB)
|
||||
|
||||
|
@ -32,7 +32,7 @@ namespace CPPCOMMON
|
||||
createDir(_logDir);
|
||||
}
|
||||
_logFile.open((string(_logDir) + string(_logName)).c_str(), ios::app);
|
||||
|
||||
|
||||
}
|
||||
bool Logger::Logging(unsigned int level, const string& msg, const string& fileName, const int& lineNo)
|
||||
{
|
||||
@ -47,7 +47,7 @@ namespace CPPCOMMON
|
||||
sprintf(_cStrBuf, _logFormat, timeStr.c_str(), fileName.c_str(), lineNo, _logLevel[level], msg.c_str());
|
||||
if(_isCoutOpen && level >= _logCoutLevel)
|
||||
{
|
||||
cout<<_cStrBuf<<endl;
|
||||
cerr<<_cStrBuf<<endl;
|
||||
}
|
||||
if(_logFile && level >= _logFileLevel)
|
||||
{
|
||||
@ -62,7 +62,7 @@ namespace CPPCOMMON
|
||||
}
|
||||
|
||||
|
||||
#ifdef UNIT_TEST
|
||||
#ifdef LOGGER_UT
|
||||
using namespace CPPCOMMON;
|
||||
int main()
|
||||
{
|
||||
|
@ -2,6 +2,29 @@
|
||||
|
||||
namespace CPPCOMMON
|
||||
{
|
||||
//http://stackoverflow.com/questions/2342162/stdstring-formatting-like-sprintf
|
||||
std::string string_format(const std::string fmt, ...)
|
||||
{
|
||||
int size = 100;
|
||||
std::string str;
|
||||
va_list ap;
|
||||
while (1) {
|
||||
str.resize(size);
|
||||
va_start(ap, fmt);
|
||||
int n = vsnprintf((char *)str.c_str(), size, fmt.c_str(), ap);
|
||||
va_end(ap);
|
||||
if (n > -1 && n < size) {
|
||||
str.resize(n);
|
||||
return str;
|
||||
}
|
||||
if (n > -1)
|
||||
size = n + 1;
|
||||
else
|
||||
size *= 2;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
string joinStr(const vector<string>& src, const string& connectorStr)
|
||||
{
|
||||
string res;
|
||||
@ -328,6 +351,7 @@ int main()
|
||||
// //cout<<strlen(utf8str);
|
||||
// cout<<utf8str<<endl;
|
||||
//}
|
||||
cout<<string_format("hehe%s11asd%dasf","[here]",2);
|
||||
ifstream ifile("testdata/dict.txt");
|
||||
string line;
|
||||
while(getline(ifile, line))
|
||||
|
@ -8,10 +8,13 @@
|
||||
#include <cctype>
|
||||
#include <map>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "typedefs.h"
|
||||
namespace CPPCOMMON
|
||||
{
|
||||
using namespace std;
|
||||
std::string string_format(const std::string fmt, ...) ;
|
||||
string joinStr(const vector<string>& source, const string& connector);
|
||||
vector<string> splitStr(const string& source, const string& pattern = " \t\n");
|
||||
void splitStr(const string& source, vector<string>& out_vec, const string& pattern = " \t\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user