123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964 |
- // Util.cpp : 实现文件
- //
-
- #include "stdafx.h"
- #include "Util.h"
- #include <odbcinst.h>
- #include <comdef.h>
- #include <afxdb.h>
- #include <regex>
- typedef basic_string<char>::size_type S_T;
- wstring strA2W(const string &str)
- {
- int len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0);
- wchar_t *wstr = new wchar_t[len + 2];
- memset(wstr, 0, (2 + len)*sizeof(wchar_t));
- MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, wstr, len);
- wstring cstrDestW = wstr;
- delete[] wstr;
- return cstrDestW;
- }
- string strW2A(const wstring &wstr)
- {
- int len = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, NULL, 0, NULL, NULL);
- char *str = new char[len + 2];
- memset(str, 0, len + 2);
- WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, str, len, NULL, NULL);
- string cstrDestA = str;
- delete[] str;
- return cstrDestA;
- }
- string strWtoUTF8(const wstring &src)
- {
- string result="";
- int n = WideCharToMultiByte( CP_UTF8, 0, src.c_str(), -1, 0, 0, 0, 0 );
- result.resize(n);
- ::WideCharToMultiByte( CP_UTF8, 0, src.c_str(), -1, (char*)result.c_str(), result.length(), 0, 0 );
- return result;
- }
- wstring strUTF8toW(const string& src)
- {
- wstring result=L"";
- int n = MultiByteToWideChar( CP_UTF8, 0, src.c_str(), -1, NULL, 0 ) + 1 ;
- result.resize(n + 1);
- ::MultiByteToWideChar( CP_UTF8, 0, src.c_str(), -1, (LPWSTR)result.c_str(), result.length());
- result[n] = L'\0';
- return result;
- }
- bool IsLeap(int year)
- {
- if((year%4==0&&year%100!=0)||year%400==0)
- return true;
- else
- return false;
- }
- bool IsWeekEnd(int year, int month, int day)
- {
- struct tm stTime = {0};
- struct tm *ptr = NULL;
- time_t time;
- stTime.tm_year = year - 1900;
- stTime.tm_mon = month - 1;
- stTime.tm_mday = day;
- time = mktime(&stTime);
- ptr = localtime(&time);
- return (ptr->tm_wday == 0 || ptr->tm_wday == 6);
- }
- char* PBQ_TrimLeftA(char *pTarget)
- {
- char buf[] = " \t";
- return PBQ_TrimLeftMA(pTarget, buf);
- }
- char* PBQ_TrimRightA(char *pTarget)
- {
- char buf[] = " \t";
- return PBQ_TrimRightMA(pTarget, buf);
- }
- char* PBQ_TrimLeftMA(char *pTarget, char* pChars)
- {
- char *ptr = pTarget;
- if(pTarget != NULL && pChars != NULL)
- {
- for (; ptr != NULL && *ptr != '\0'; ptr++)
- {
- if(NULL == strchr(pChars, *ptr))
- {
- break;
- }
- }
- strcpy(pTarget, ptr);
- }
- return pTarget;
- }
- char* PBQ_TrimRightMA(char *pTarget, char* pChars)
- {
- char *pEnd = NULL;
- if (pTarget != NULL)
- {
- pEnd = pTarget + strlen(pTarget) - 1;
- for (; pEnd >= pTarget; pEnd--)
- {
- if(NULL != strchr(pChars, *pEnd))
- {
- *pEnd = 0;
- }
- else
- {
- break;
- }
- }
- }
- return pTarget;
- }
- void Full2Half(wchar_t* str)
- {
- if(str != NULL)
- {
- int len = wcslen(str);
- int i = 0;
- wchar_t space[] = L" ";
- for(; i<len; i++)
- {
- if(str[i] == space[0])//对空格特殊处理
- {
- str[i] = ' ';
- }
- else if(str[i] >= 65281 && str[i] <= 65374)
- {
- str[i] -= (65281 - 33);
- }
- }
- }
- }
- bool split(const string& src, string delimit,vector<string> &v, string null_subst)
- {
- if(src.empty() || delimit.empty())
- return false;
- S_T deli_len = delimit.size();
- long index = -1,last_search_position = 0;
- while( (index=src.find(delimit,last_search_position))!=-1 )
- {
- if(index==last_search_position)
- v.push_back(null_subst);
- else
- v.push_back( src.substr(last_search_position, index-last_search_position) );
- last_search_position = index + deli_len;
- }
- string last_one = src.substr(last_search_position);
- v.push_back( last_one.empty()? null_subst:last_one );
- return true;
- }
- bool split(const wstring& src, wstring delimit, vector<wstring> &v, wstring null_subst)
- {
- if (src.empty() || delimit.empty())
- return false;
- S_T deli_len = delimit.size();
- long index = -1, last_search_position = 0;
- while ((index = src.find(delimit, last_search_position)) != -1)
- {
- if (index == last_search_position)
- v.push_back(null_subst);
- else
- v.push_back(src.substr(last_search_position, index - last_search_position));
- last_search_position = index + deli_len;
- }
- wstring last_one = src.substr(last_search_position);
- v.push_back(last_one.empty() ? null_subst : last_one);
- return true;
- }
- vector<string> splitEx(const string& src, string separate_character)
- {
- vector<string> strs;
- int separate_characterLen = separate_character.size();//分割字符串的长度,这样就可以支持如“,,”多字符串的分隔符
- int lastPosition = 0, index = -1;
- while (-1 != (index = src.find(separate_character, lastPosition)))
- {
- strs.push_back(src.substr(lastPosition, index - lastPosition));
- lastPosition = index + separate_characterLen;
- }
- string lastString = src.substr(lastPosition);//截取最后一个分隔符后的内容
- if (!lastString.empty())
- strs.push_back(lastString);//如果最后一个分隔符后还有内容就入队
- return strs;
- }
- int GB2312_2_UTF8(char* buf, int buf_len, const char* src, int src_len)
- {
- int i = 0, j = 0;
- if (0 == src_len)
- {
- src_len = strlen(src);
- }
- for (i = 0; i < src_len;)
- {
- if (j >= buf_len - 1)
- break;
- if (src[i] >= 0)
- {
- buf[j++] = src[i++];
- }
- else
- {
- unsigned short w_c = 0;
- char tmp[4] = "";
- Gb2312_2_Unicode(&w_c, src + i);
- Unicode_2_UTF8(tmp, &w_c);
- buf[j+0] = tmp[0];
- buf[j+1] = tmp[1];
- buf[j+2] = tmp[2];
- i += 2;
- j += 3;
- }
- }
- buf[j] = '\0';
- return j;
- }
- void Gb2312_2_Unicode(unsigned short* dst, const char* src)
- {
- MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, src, 2, (LPWSTR)dst, 1);
- }
- void Unicode_2_UTF8(char* dst, unsigned short* src)
- {
- char *pchar = (char *)src;
- dst[0] = (0xE0 | ((pchar[1] & 0xF0) >> 4));
- dst[1] = (0x80 | ((pchar[1] & 0x0F) << 2)) + ((pchar[0] & 0xC0) >> 6);
- dst[2] = (0x80 | ( pchar[0] & 0x3F));
- }
- string ConvertUTF8toGB2312(const char *pData, size_t size)
- {
- size_t n = MultiByteToWideChar(CP_UTF8, 0, pData, (int)size, NULL, 0);
- WCHAR *pChar = new WCHAR[n+1];
- n = MultiByteToWideChar(CP_UTF8, 0, pData, (int)size, pChar, n);
- pChar[n]=0;
- n = WideCharToMultiByte(CP_ACP, 0, pChar, -1, 0, 0, 0, 0);
- char *p = new char[n+1];
- n = WideCharToMultiByte(CP_ACP, 0, pChar, -1, p, (int)n, 0, 0);
- string result(p);
- delete []pChar;
- delete []p;
- return result;
- }
- char* ConvertGB2312toUTF8(const char *pData)
- {
- int len = MultiByteToWideChar(CP_ACP, 0, pData, -1, NULL, 0);
- wchar_t* wstr = new wchar_t[len+1];
- memset(wstr, 0, len+1);
- MultiByteToWideChar(CP_ACP, 0, pData, -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;
- }
- wstring UTF8ToUnicode(const char* szU8)
- {
- wstring str;
- if (szU8 == NULL)
- {
- return str;
- }
- //预转换,得到所需空间的大小;
- int wcsLen = ::MultiByteToWideChar(CP_UTF8, NULL, szU8, strlen(szU8), NULL, 0);
- if (wcsLen <= 0) return str;
- //分配空间要给'\0'留个空间,MultiByteToWideChar不会给'\0'空间
- wchar_t* pWStr = (wchar_t*)calloc(wcsLen + 1, sizeof(wchar_t));
- //转换
- ::MultiByteToWideChar(CP_UTF8, NULL, szU8, strlen(szU8), pWStr, wcsLen);
- pWStr[wcsLen] = L'\0';
- str = pWStr;
- if (pWStr) free(pWStr);
- return str;
- }
- int CalcWord(const char *ps, const size_t length)
- {
- ASSERT(0 < length);
- ASSERT(NULL != ps);
- int nRealLen(0);
- int nFlag(0);
- while (nFlag <= length && 0 != ps[nRealLen])
- {
- if (IsChinese(ps[nRealLen]))
- {
- nRealLen++;
- if (0 != ps[nRealLen])
- nRealLen++;
- else
- break;
- }
- else
- nRealLen++;
- nFlag++;
- }
- return nRealLen;
- }
- void Int64DateToStr(const __int64& llDate, string& out)
- {
- int nYear = llDate / 10000000000L;
- int nMode = llDate % 10000000000L;
- int nMon = nMode / 100000000;
- nMode %= 100000000;
- int nDay = nMode / 1000000;
- nMode %= 1000000;
- int nHour = nMode / 10000;
- nMode %= 10000;
-
- int nMin = nMode / 100;
- int nSec = nMode % 100;
- char buf[20];
- memset(buf, 0, 20);
- sprintf(buf, "%04d-%02d-%02d %02d:%02d:%02d", nYear,nMon,nDay,nHour,nMin,nSec);
-
- out = buf;
- }
- void Int64DateToYMDStr(const __int64& llDate, string& out)
- {
- int nYear = llDate / 10000000000L;
- int nMode = llDate % 10000000000L;
- int nMon = nMode / 100000000;
- nMode %= 100000000;
- int nDay = nMode / 1000000;
- nMode %= 1000000;
- char buf[20];
- memset(buf, 0, 20);
- sprintf(buf, "%04d-%02d-%02d", nYear,nMon,nDay);
-
- out = buf;
- }
- void Int64DateToHMStr(const __int64& llDate, string& out)
- {
- int nYear = llDate / 10000000000L;
- int nMode = llDate % 10000000000L;
- int nMon = nMode / 100000000;
- nMode %= 100000000;
- int nDay = nMode / 1000000;
- nMode %= 1000000;
- int nHour = nMode / 10000;
- nMode %= 10000;
-
- int nMin = nMode / 100;
- char buf[20];
- memset(buf, 0, 20);
- sprintf(buf, "%02d:%02d", nHour,nMin);
-
- out = buf;
- }
- unsigned char ToHex(unsigned char x)
- {
- return x > 9 ? x + 55 : x + 48;
- }
- unsigned char FromHex(unsigned char x)
- {
- unsigned char y;
- if (x >= 'A' && x <= 'Z') y = x - 'A' + 10;
- else if (x >= 'a' && x <= 'z') y = x - 'a' + 10;
- else if (x >= '0' && x <= '9') y = x - '0';
- return y;
- }
- std::string UrlEncode(const std::string& str)
- {
- std::string strTemp = "";
- size_t length = str.length();
- for (size_t i = 0; i < length; i++)
- {
- if (isalnum((unsigned char)str[i]) ||
- (str[i] == '-') ||
- (str[i] == '_') ||
- (str[i] == '.') ||
- (str[i] == '~'))
- strTemp += str[i];
- else if (str[i] == ' ')
- strTemp += "+";
- else
- {
- strTemp += '%';
- strTemp += ToHex((unsigned char)str[i] >> 4);
- strTemp += ToHex((unsigned char)str[i] % 16);
- }
- }
- return strTemp;
- }
- std::string UrlDecode(const std::string& str)
- {
- std::string strTemp = "";
- size_t length = str.length();
- for (size_t i = 0; i < length; i++)
- {
- if (str[i] == '+') strTemp += ' ';
- else if (str[i] == '%')
- {
- unsigned char high = FromHex((unsigned char)str[++i]);
- unsigned char low = FromHex((unsigned char)str[++i]);
- strTemp += high*16 + low;
- }
- else strTemp += str[i];
- }
- return strTemp;
- }
- void DeleteDirectory(CString source)
- {
- CFileFind finder;
- CString path;
- if(PathFileExists(source))
- {
- path.Format(_T("%s/*.*"),source);
- bool bWorking = finder.FindFile(path);
- while(bWorking){
- bWorking = finder.FindNextFile();
- if(finder.IsDirectory() && !finder.IsDots()){ //是文件夹 而且 名称不含 . 或 ..
- DeleteDirectory(finder.GetFilePath()); //递归创建文件夹+"/"+finder.GetFileName()
- }
- else{ //是文件 则直接删除
- DeleteFile(finder.GetFilePath());
- }
- }
- RemoveDirectory(source);
- }
- }
- void RecursiveDirectory(CString cstrDir) // 递归创建目录
- {
- if (cstrDir.GetLength() <= 3)//是根目录,无需创建目录
- {
- return;
- }
- if (cstrDir[cstrDir.GetLength()-1] == '\\') // 将路径改为目录
- {
- cstrDir.Delete(cstrDir.GetLength()-1, 1);
- }
- // 修改文件属性
- WIN32_FIND_DATA wfd;
- HANDLE hFind = FindFirstFile(cstrDir, &wfd); // 查找
- if (hFind != INVALID_HANDLE_VALUE)
- {
- FindClose(hFind);
- if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
- return;
- }
- // 创建当前目录的地目录失败
- if (CreateDirectory(cstrDir,NULL) == false)
- {// 退到上一级目录
- CString wstrNewDir = cstrDir;
- int n = wstrNewDir.ReverseFind('\\');
- wstrNewDir = cstrDir.Left(n);
- // 递归进入
- RecursiveDirectory(wstrNewDir); // 递归本函数,再创建目录
- // 递归退出后创建之前失败的目录
- CreateDirectory(cstrDir,NULL); // 递归返回,在存在的目录上再建目录
- }// 多级目录创建成功
- }
- void toUpper(char *szDestination, const char *szSource)
- {
- if (szDestination == NULL || szSource == NULL || strlen(szSource) == 0)
- return;
- while (*szSource != 0)
- {
- if (*szSource >= 'a' && *szSource <= 'z')
- *szDestination++ = 'A' + (*szSource++ - 'a');
- else
- *szDestination++ = *szSource++;
- }
- *szDestination = 0;
- }
- void FormatPrice(char *szDes, const double dSource)
- {
- sprintf(szDes, "%.9lf", dSource);
- int i(0);
- int nLen(strlen(szDes));
- for (; i < nLen; i++)
- {
- if (szDes[i] == '.')
- break;
- }
- for (int j = nLen - 1; j > i + 2; j--)
- {
- if (szDes[j] == '0')
- szDes[j] = 0;
- else
- break;
- }
- }
- bool CombinationVolRemark(string &strDes, const char *szVol, const char *szRemark)
- {
- vector<string> vctVol;
- vector<string> vctRemark;
- bool bRet(true);
- if (!split(szVol, "|", vctVol))
- bRet = false;
- if (!split(szRemark, "|", vctRemark))
- bRet = false;
- if (vctVol.size() != vctRemark.size())
- bRet = false;
- if (!bRet)
- {
- if (!split(szVol, "+", vctVol))
- bRet = false;
- else
- bRet = true;
- if (!split(szRemark, "+", vctRemark))
- bRet = false;
- else
- bRet = true;
- if (vctVol.size() != vctRemark.size())
- bRet = false;
- }
- if (!bRet)
- return bRet;
- for (int i = 0; i < vctVol.size(); i++)
- {
- if (i != 0)
- strDes.append("+");
- if (vctVol[i].empty())
- strDes.append("--");
- else
- strDes.append(vctVol[i]);
- if (!vctRemark[i].empty())
- {
- strDes.append("(");
- strDes.append(vctRemark[i]);
- strDes.append(")");
- }
- }
- return true;
- }
- bool CombinationQuoteData(string &strDes, const char *szVol, const char *szRemark/* = NULL*/
- , const char *szDanger/* = NULL*/, const char *szOCO/* = NULL*/, const char *szPACK/* = NULL*/)
- {
- if (szVol == NULL)
- return false;
- vector<const char*> vctData;
- vctData.push_back(szVol);
- if (szDanger != NULL)
- {
- vctData.push_back(szDanger);
- }
- if (szOCO != NULL)
- {
- vctData.push_back(szOCO);
- }
- if (szPACK != NULL)
- {
- vctData.push_back(szPACK);
- }
- if (szRemark != NULL && strlen(szRemark) > 0 && strcmp(szRemark, "--") != 0)
- {
- vctData.push_back(szRemark);
- }
- const char* arrSeparators[2] = {"|", "+"};
- bool bMulti(false);
- int nIdx(0);
- for (int i = 0; i < 2; i++)
- {
- if (strstr(szVol, arrSeparators[i]) != NULL)
- {
- nIdx = i;
- bMulti = true;
- break;
- }
- }
- if (bMulti)
- {
- vector<vector<string>> vctSplit;
- for (int i = 0; i < vctData.size(); i++)
- {
- vector<string> vct;
- if (!split(vctData[i], arrSeparators[nIdx], vct))
- {
- return false;
- }
- vctSplit.push_back(vct);
- }
- int nCount(vctSplit[0].size());
- for (int i = 1; i < vctSplit.size(); i++)
- {
- if (nCount != vctSplit[i].size())
- return false;
- }
- for (int i = 0; i < nCount; i++)
- {
- if (i != 0)
- strDes.append("+");
-
- if (strlen((vctSplit[0])[i].c_str()) == 0)
- strDes.append("--");
- else
- {
- strDes.append((vctSplit[0])[i]);
- }
- string strTemp;
- for (int j = 1; j < vctSplit.size(); j++)
- {
- if (strlen((vctSplit[j])[i].c_str()) != 0)
- {
- strTemp.append((vctSplit[j])[i]);
- strTemp.append(",");
- }
- }
- if (!strTemp.empty())
- {
- if (strTemp[strTemp.size() - 1] == ',')
- {
- strTemp = string(strTemp.c_str(), strTemp.size() - 1);
- }
- }
- if (!strTemp.empty())
- {
- strDes.append("(");
- strDes.append(strTemp);
- strDes.append(")");
- }
- }
- }
- else
- {
- if (strlen(szVol) == 0)
- {
- strDes.append("--");
- }
- else
- {
- strDes.append(szVol);
- }
-
- string strTemp;
- for (int i = 1; i < vctData.size(); i++)
- {
- if (strlen(vctData[i]) != 0)
- {
- strTemp.append(vctData[i]);
- strTemp.append(",");
- }
- }
- if (!strTemp.empty())
- {
- if (strTemp[strTemp.size() - 1] == ',')
- {
- strTemp = string(strTemp.c_str(), strTemp.size() - 1);
- }
- }
- if (!strTemp.empty())
- {
- strDes.append("(");
- strDes.append(strTemp);
- strDes.append(")");
- }
- }
- return true;
- }
- //获取ODBC中Excel驱动函数
- CString GetExcelDriverInfo()
- {
- TCHAR szBuf[2001];
- WORD cbBufMax = 2000;
- WORD cbBufOut;
- TCHAR *pszBuf = szBuf;
- CString sDriver=L"";
- // 获取已安装驱动的名称(涵数在odbcinst.h里)
- if (!SQLGetInstalledDrivers(szBuf, cbBufMax, &cbBufOut))
- return L"";
- // 检索已安装的驱动是否有Excel...
- do
- {
- if (StrStrW(pszBuf, L"Excel") != 0)
- {
- //发现 !
- CString temp(pszBuf);
- //if(sDriver.GetLength() < temp.GetLength())
- sDriver = temp;
- break;
- }
- pszBuf = StrStrW(pszBuf, L'\0') + 1;
- }
- while (pszBuf[1] != L'\0');
- return sDriver;
- }
- __int64 StringToInt64(const char *szSource)
- {
- __int64 ret(0);
- if (strlen(szSource) == 0)
- return ret;
- const char *pTemp = szSource + strlen(szSource) - 1;
- __int64 nRight(1);
- bool bNegative(false);
- if ('-' == szSource[0])
- bNegative = true;
- do
- {
- if (*pTemp >= '0' && *pTemp <= '9')
- {
- ret += nRight * (0 + (*pTemp - '0'));
- nRight *= 10;
- }
- }
- while(pTemp-- != szSource);
- if (bNegative)
- ret = -ret;
- return ret;
- }
- string GetRequestByKey(const string& strKey, const string& strReuest)
- {
- try
- {
- smatch result;
- if (regex_search(strReuest.cbegin(), strReuest.cend(), result, regex(strKey + "=(.*?)&")))
- {
- return result[1];
- }
- else if (regex_search(strReuest.cbegin(), strReuest.cend(), result, regex(strKey + "=(.*)")))
- {
- return result[1];
- }
- else
- {
- return string();
- }
- }
- catch (...)
- {
- return string();
- }
- return string();
- }
- void GetKeysByUrl(const string & strUrl, vector<string> & vctKey)
- {
- vector<string> vctSearch;
- split(strUrl, "?", vctSearch);
- if (vctSearch.size() != 2 && vctSearch.size() != 1)
- {
- return;
- }
- string strTemp;
- if (vctSearch.size() == 1)
- {
- strTemp = vctSearch[0];
- }
- else if (vctSearch.size() == 2)
- {
- strTemp = vctSearch[1];
- }
- vctSearch.clear();
- split(strTemp, "&", vctSearch);
- if (vctSearch.size() <= 0)
- {
- return;
- }
- for (int i = 0; i < vctSearch.size(); i++)
- {
- strTemp = vctSearch[i];
- vector<string> vct;
- split(strTemp, "=", vct);
- if (vct.size() == 2)
- {
- vctKey.push_back(vct[0]);
- }
- }
- }
- __int64 GetCharNumber(char* szText, size_t n)
- {
- __int64 nDest;
- if (n == 0)
- {
- return -1;
- }
- for (nDest = 0; n--; szText++)
- {
- if (*szText < '0' || *szText > '9')
- {
- continue; //继续获取下一个字符
- }
- /*
- 1、当前字符值 *line的ascii码,减去字符0的ascii码,得出个位数字
- 2、原计算的value值 乘以10,向上提升一位
- 3、二者相加得到新的十进制数值
- */
- nDest = nDest * 10 + (*szText - '0');
- }
- if (nDest < 0)
- {
- return -1;
- }
- else
- {
- return nDest;
- }
- }
- CStringW CStrA2W(const CStringA &cstrSrcA)
- {
- int len = MultiByteToWideChar(CP_ACP, 0, LPCSTR(cstrSrcA), -1, NULL, 0);
- wchar_t *wstr = new wchar_t[len];
- memset(wstr, 0, len*sizeof(wchar_t));
- MultiByteToWideChar(CP_ACP, 0, LPCSTR(cstrSrcA), -1, wstr, len);
- CStringW cstrDestW = wstr;
- delete[] wstr;
- return cstrDestW;
- }
- CStringA CStrW2A(const CStringW &cstrSrcW)
- {
- int len = WideCharToMultiByte(CP_ACP, 0, LPCWSTR(cstrSrcW), -1, NULL, 0, NULL, NULL);
- char *str = new char[len];
- memset(str, 0, len);
- WideCharToMultiByte(CP_ACP, 0, LPCWSTR(cstrSrcW), -1, str, len, NULL, NULL);
- CStringA cstrDestA = str;
- delete[] str;
- return cstrDestA;
- }
- bool RegexStdMatch(string src, string regular)
- {
- regex pattern(regular.c_str());
- if (!regex_match(src, pattern))
- {
- return false;
- }
- return true;
- }
- bool RegexStdMatch(wstring src, wstring regular)
- {
- char* pre = setlocale(LC_ALL, "");
- setlocale(LC_ALL, "chs");
- std::wregex pattern(regular.c_str());
- if (!regex_match(src, pattern))
- {
- return false;
- }
- return true;
- }
- string replace_all(string& str, const string& old_value, const string& new_value)
- {
- while (true)
- {
- string::size_type pos(0);
- if ((pos = str.find(old_value)) != string::npos)
- str.replace(pos, old_value.length(), new_value);
- else break;
- }
- return str;
- }
- void sync_system_time(ULONGLONG time)
- {
- time_t _time = time;
- struct tm *tim = localtime(&_time);
- SYSTEMTIME system_time = {0}; //先获取本地时间
- system_time.wYear = tim->tm_year+1900;
- system_time.wMonth =tim->tm_mon+1;
- system_time.wDay = tim->tm_mday;
- system_time.wHour = tim->tm_hour;
- system_time.wMinute = tim->tm_min;
- system_time.wSecond = tim->tm_sec;
- SetLocalTime(&system_time);
- }
|