diff --git a/demo/keywordext_demo.cpp b/demo/keywordext_demo.cpp index b2e86c8..f3d71f0 100644 --- a/demo/keywordext_demo.cpp +++ b/demo/keywordext_demo.cpp @@ -15,6 +15,11 @@ void testKeyWordExt(const char * dictPath, const char * filePath) cerr<<__FILE__<<__LINE__< res; string line; diff --git a/src/cppcommon/Makefile b/src/cppcommon/Makefile index 422f612..88720e4 100644 --- a/src/cppcommon/Makefile +++ b/src/cppcommon/Makefile @@ -29,6 +29,8 @@ io_functs.test: io_functs.cpp io_functs.h g++ -o $@ $< -DTEST_IO_FUNCTS str_functs.ut: str_functs.cpp str_functs.h g++ -o $@ $< -DTEST_STR_FUNCTS +argv_functs.ut: argv_functs.cpp str_functs.cpp argv_functs.h + g++ -o $@ argv_functs.cpp str_functs.cpp -DARGV_FUNCTS_UT encoding.ut: encoding.cpp str_functs.cpp str_functs.h encoding.h g++ -o $@ encoding.cpp str_functs.cpp -DENCODING_UT vec_functs.test: vec_functs.cpp vec_functs.h vec_functs.tcc diff --git a/src/cppcommon/argv_functs.cpp b/src/cppcommon/argv_functs.cpp new file mode 100644 index 0000000..504fa61 --- /dev/null +++ b/src/cppcommon/argv_functs.cpp @@ -0,0 +1,42 @@ +#include "argv_functs.h" + +namespace CPPCOMMON +{ + bool getArgvMap(int argc, char** argv, map& mpss) + { + mpss.clear(); + for(int i = 0; i < argc; i++) + { + if(strStartsWith(argv[i], "--")) + { + if(i + 1 < argc && !strStartsWith(argv[i+1], "--")) + { + mpss[argv[i]] = argv[i+1]; + i++; + } + else + { + return false; + } + } + } + return true; + } + + +} + + +#ifdef ARGV_FUNCTS_UT + +using namespace CPPCOMMON; + +int main(int argc, char** argv) +{ + map argvMap; + getArgvMap(argc, argv, argvMap); + PRINT_MAPSS(argvMap); + return 0; +} + +#endif diff --git a/src/cppcommon/argv_functs.h b/src/cppcommon/argv_functs.h new file mode 100644 index 0000000..a7e18c8 --- /dev/null +++ b/src/cppcommon/argv_functs.h @@ -0,0 +1,18 @@ +/************************************ + * file enc : ascii + * author : wuyanyi09@gmail.com +************************************/ + +#ifndef CPPCOMMON_ARGV_FUNCTS_H +#define CPPCOMMON_ARGV_FUNCTS_H + +#include "str_functs.h" +#include "map_functs.h" + +namespace CPPCOMMON +{ + using namespace std; + bool getArgvMap(int argc, char** argv, map& mpss); +} + +#endif diff --git a/src/cppcommon/headers.h b/src/cppcommon/headers.h index a242a9d..3190b71 100644 --- a/src/cppcommon/headers.h +++ b/src/cppcommon/headers.h @@ -9,5 +9,7 @@ #include "config.h" #include "typedefs.h" #include "str_functs.h" +#include "map_functs.h" +#include "arfv_functs.h" #endif diff --git a/src/cppcommon/map_functs.h b/src/cppcommon/map_functs.h new file mode 100644 index 0000000..833da38 --- /dev/null +++ b/src/cppcommon/map_functs.h @@ -0,0 +1,18 @@ +/************************************ + * file enc : ascii + * author : wuyanyi09@gmail.com +************************************/ + + +#ifndef CPPCOMMON_MAP_FUNCTS_H +#define CPPCOMMON_MAP_FUNCTS_H + +#define PRINT_MAPSS(mpss) \ +{\ + for(map::const_iterator it = mpss.begin(); it != mpss.end(); it++)\ + {\ + cout<first<<' '<second< tmp; //tmp.push_back("1"); ////tmp.push_back("2"); @@ -476,6 +481,12 @@ int main() // s = utf8ToGbk(s); // cout<& source, const string& connector); vector splitStr(const string& source, const string& pattern = " \t\n"); void splitStr(const string& source, vector& out_vec, const string& pattern = " \t\n"); @@ -67,6 +67,7 @@ namespace CPPCOMMON cout<