#include "util.h" void split(std::string s, const char* delim, std::vector* ret) { size_t last = 0; size_t index = s.find(delim, last); int size=strlen(delim); while (index != std::string::npos) { ret->push_back(s.substr(last, index - last)); last = index + size; index = s.find(delim, last); } if (index - last > 0) { ret->push_back(s.substr(last, index - last)); } } bool isTypeOf(tag_t objtag, const char * type_name) { tag_t type = NULLTAG; TCTYPE_ask_object_type(objtag, &type); tag_t item_type = NULLTAG; TCTYPE_find_type(type_name, "", &item_type); bool is_type = false; if (item_type != NULLTAG) { logical isok = FALSE; TCTYPE_is_type_of(type, item_type, &isok); if (isok) { is_type = true; } } return is_type; } void vecToArray(vector &vec,char ***arr) { (*arr)=(char **)MEM_alloc(vec.size()*sizeof(char *)); for(auto i=0;itm_year + 1900 << '-'; if (local->tm_mon < 9) ss << "0"; ss << local->tm_mon + 1 << '-'; if (local->tm_mday < 9) ss << "0"; ss << local->tm_mday << ' '; if (local->tm_hour < 10) ss << "0"; if (local->tm_min < 10) ss << "0"; ss << local->tm_min; if(local->tm_sec<10) ss<<"0"; ss<tm_sec; return ss.str(); } string getTime() { stringstream ss; time_t t = time(0); tm* local = localtime(&t); ss << local->tm_year + 1900 << '-'; if (local->tm_mon < 9) ss << "0"; ss << local->tm_mon + 1 << '-'; if (local->tm_mday < 9) ss << "0"; ss << local->tm_mday << ' '; if (local->tm_hour < 10) ss << "0"; ss << local->tm_hour << ':'; if (local->tm_min < 10) ss << "0"; ss << local->tm_min<<':'; if(local->tm_sec<10) ss<<"0"; ss<tm_sec; return ss.str(); } char* G2U(const char* gb2312) { int len = MultiByteToWideChar(CP_ACP, 0, gb2312, -1, NULL, 0); wchar_t* wstr = new wchar_t[len + 1]; memset(wstr, 0, len + 1); MultiByteToWideChar(CP_ACP, 0, gb2312, -1, wstr, len); len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL); char* str = new char[len + 1]; memset(str, 0, len + 1); WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL); if (wstr) delete[] wstr; return str; } char* U2G(const char* utf8) { int len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0); wchar_t* wstr = new wchar_t[len + 1]; memset(wstr, 0, len + 1); MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wstr, len); len = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL); char* str = new char[len + 1]; memset(str, 0, len + 1); WideCharToMultiByte(CP_ACP, 0, wstr, -1, str, len, NULL, NULL); if (wstr) delete[] wstr; return str; } string WStringToString(const wstring& ws) { string curLocale = setlocale(LC_ALL, NULL); // curLocale = "C"; setlocale(LC_ALL, "chs"); const wchar_t* _Source = ws.c_str(); size_t _Dsize = 2 * ws.size() + 1; char *_Dest = new char[_Dsize]; memset(_Dest,0,_Dsize); wcstombs(_Dest,_Source,_Dsize); string result = _Dest; delete []_Dest; setlocale(LC_ALL, curLocale.c_str()); result = G2U(result.c_str()); return result; } wstring StringToWString(const string s) { setlocale(LC_ALL, "chs"); const char* _Source = s.c_str(); size_t _Dsize = s.size() + 1; wchar_t *_Dest = new wchar_t[_Dsize]; wmemset(_Dest, 0, _Dsize); mbstowcs(_Dest,_Source,_Dsize); wstring result = _Dest; delete []_Dest; setlocale(LC_ALL, "C"); return result; } std::string string_To_UTF8(const std::string str) { int nwLen = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0); wchar_t * pwBuf = new wchar_t[nwLen + 1];//一定要加1,不然会出现尾巴 ZeroMemory(pwBuf, nwLen * 2 + 2); ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), pwBuf, nwLen); int nLen = ::WideCharToMultiByte(CP_UTF8, 0, pwBuf, -1, NULL, NULL, NULL, NULL); char * pBuf = new char[nLen + 1]; ZeroMemory(pBuf, nLen + 1); ::WideCharToMultiByte(CP_UTF8, 0, pwBuf, nwLen, pBuf, nLen, NULL, NULL); std::string retStr(pBuf); delete []pwBuf; delete []pBuf; pwBuf = NULL; pBuf = NULL; return retStr; } double stringToNum( string str) { istringstream iss(str); double num; iss >> num; return num; } void trim(std::string &s) { if (s.empty()) { return; } s.erase(0,s.find_first_not_of(" ")); s.erase(s.find_last_not_of(" ") + 1); } void getLatest(tag_t item,tag_t *rev) { int cnt,rel_cnt; tag_t *tags,*rels; ITEM_list_all_revs(item,&cnt,&tags); for(auto i=cnt-1;i>=0;i--) { AOM_ask_value_tags(tags[i],"release_status_list",&rel_cnt,&rels); if(rel_cnt) { *rev=tags[i]; return; } } *rev=NULLTAG; } string get_excel_data(libxl::Book *book, libxl::Sheet *sheet, int row, int col) { string result; double temp; try { libxl::CellType cell_type = sheet->cellType(row, col); switch (cell_type) { case libxl::CELLTYPE_STRING: result = WStringToString(sheet->readStr(row, col)); break; case libxl::CELLTYPE_BLANK: result = ""; break; case libxl::CELLTYPE_EMPTY: result = ""; break; case libxl::CELLTYPE_NUMBER: temp = sheet->readNum(row, col); if (sheet->isDate(row, col)) { int year = 0, month = 0, day = 0, hour = 0, min = 0, second = 0; book->dateUnpack(temp, &year, &month, &day, &hour, &min, &second); date_t d; d.year = year; d.month = month-1; d.day = day; d.hour = hour; d.minute = min; d.second = second; char *date_str, *date_format; DATE_default_date_format(&date_format); DATE_date_to_string(d, date_format, &date_str); result = date_str; } else { result = temp == (int)temp ? to_string((int)temp) : to_string(temp); } break; case libxl::CELLTYPE_BOOLEAN: result = to_string(sheet->readBool(row, col)); break; case libxl::CELLTYPE_ERROR: result = ""; break; } } catch (exception e) { // LERROR<<"col num"<