/************************************ * file enc : ascii * author : wuyanyi09@gmail.com ************************************/ #ifndef CPPCOMMON_STR_FUNCTS_H #define CPPCOMMON_STR_FUNCTS_H #include #include #include #include #include #include #include #include #include #include #include #include "typedefs.h" #include #include namespace CPPCOMMON { using namespace std; string string_format(const string fmt, ...) ; string joinStr(const vector& source, const string& connector); vector splitStr(const string& source, const string& pattern = " \t\n"); bool splitStr(const string& source, vector& res, const string& pattern = " \t\n"); bool splitStrMultiPatterns( const string& strSrc, vector& outVec, const vector& patterns ); string upperStr(const string& str); string lowerStr(const string& str); string replaceStr(const string& strSrc, const string& oldStr, const string& newStr, int count = -1); string stripStr(const string& str, const string& patternstr = " \n\t"); std::string <rim(std::string &s) ; std::string &rtrim(std::string &s) ; std::string &trim(std::string &s) ; unsigned int countStrDistance(const string& A, const string& B); unsigned int countStrSimilarity(const string& A, const string& B); bool uniStrToVec(const string& str, Unicode& vec); string uniVecToStr(const Unicode& vec); inline uint16_t twocharToUint16(char high, char low) { return (((uint16_t(high) & 0x00ff ) << 8) | (uint16_t(low) & 0x00ff)); } inline pair uint16ToChar2(uint16_t in) { pair res; res.first = (in>>8) & 0x00ff; //high res.second = (in) & 0x00ff; //low return res; } inline void printUnicode(const Unicode& unicode) { cout< str.length()) { return false; } return 0 == str.compare(0, prefix.length(), prefix); } inline bool strEndsWith(const string& str, const string& suffix) { if(suffix.length() > str.length()) { return false; } return 0 == str.compare(str.length() - suffix.length(), suffix.length(), suffix); } } #endif