cppstring GTextUtils::ConvertNarrowStringToWide(const narrowstring sNarrow) { // input a narrow (ASCII )string ... it will not be multibyte // convert to wide if USE_WIDE_CHARS #ifdef USE_WIDE_CHARS cppstring sResult(sNarrow.c_str()); #else cppstring sResult(sNarrow); // the types are the same... does nothing #endif return sResult; }
void GPageLoadRequestManager::ProcessRequest(GUpdateCurrentPageRequest* pRequest) { LOG_LEVEL4("ProcessRequest(GUpdateCurrentPageRequest)"); QString sResult("discarded"); if( m_oPreSetManager.IsActive() && m_oPreSetManager.CanProcessRequest(pRequest) ) { m_oPreSetManager.ProcessRequest(pRequest); sResult = "completed"; } if( m_oNonPreSetManager.IsActive() && m_oNonPreSetManager.CanProcessRequest(pRequest) ) { m_oNonPreSetManager.ProcessRequest(pRequest); sResult = "completed"; } static QString const strTemp("(GUpdateCurrentPageRequest): RequestId(%1), has been completed with result (%2) for (%3)."); LOG_LEVEL4(QString(strTemp) . arg(pRequest->GetRequestId()) . arg(sResult) . arg(GetSessionName(pRequest->GetSessionId()))); if( pRequest->IsSynchronize() ) { GAbsView::SignalSynchronize( (sResult=="completed")?(true):(false) ); } delete pRequest; }
std::string UriDecode(const std::string& sSrc) { // Note from RFC1630: "Sequences which start with a percent sign // but are not followed by two hexadecimal characters (0-9, A-F) are reserved // for future extension" const unsigned char *pSrc = (const unsigned char *)sSrc.c_str(); const int SRC_LEN = sSrc.length(); const unsigned char *const SRC_END = pSrc + SRC_LEN; const unsigned char *const SRC_LAST_DEC = SRC_END - 2; // last decodable '%' char *const pStart = new char[SRC_LEN]; char *pEnd = pStart; while (pSrc < SRC_LAST_DEC) { if (*pSrc == '%') { char dec1, dec2; if ((-1 != (dec1 = HEX2DEC[*(pSrc + 1)])) && (-1 != (dec2 = HEX2DEC[*(pSrc + 2)]))) { *pEnd++ = (dec1 << 4) + dec2; pSrc += 3; continue; } } *pEnd++ = *pSrc++; } // the last 2- chars while (pSrc < SRC_END) *pEnd++ = *pSrc++; std::string sResult(pStart, pEnd); delete [] pStart; return sResult; }
std::string GetAppPath() { ERROR_OUTPUT(__func__); char result[PATH_MAX] = {0}; ssize_t count = readlink("/proc/self/exe", result, PATH_MAX); if (count <= 0) { ERROR_OUTPUT("Could not get program directory!"); return ""; } for(size_t i = count - 1; i > 0; i--) { if(result[i] == '/') { result[i] = '\0'; break; } } std::string sResult(result); size_t pos = sResult.find_last_of('/'); // we actually want one folder above where we are due to executable being in desura/bin/ sResult = sResult.substr(0, pos); ERROR_OUTPUT(sResult.c_str()); return sResult; }
void C4GameOverDlg::SetNetResult(const char *szResultString, C4RoundResults::NetResult eResultType, size_t iPendingStreamingData, bool fIsStreaming) { // add info about pending streaming data StdStrBuf sResult(szResultString); if (fIsStreaming) { sResult.AppendChar('|'); sResult.AppendFormat("[!]Transmitting record to league server... (%d kb remaining)", int(iPendingStreamingData/1024)); } // message linebreak into box StdStrBuf sBrokenResult; C4GUI::GetRes()->TextFont.BreakMessage(sResult.getData(), pNetResultLabel->GetBounds().Wdt, &sBrokenResult, true); pNetResultLabel->SetText(sBrokenResult.getData(), false); // all done? if (eResultType != C4RoundResults::NR_None && !fIsStreaming) { // a final result is determined and all streaming data has been transmitted fIsNetDone = true; } // network error? if (eResultType == C4RoundResults::NR_NetError) { // disconnected. Do not show winners/losers for (int32_t i=0; i<iPlrListCount; ++i) ppPlayerLists[i]->SetMode(C4PlayerInfoListBox::PILBM_EvaluationNoWinners); } }
std::string Utf16ToUtf8( const wchar_t* const szSource, const _U32 uiSize ) { static std::string sWrongString = "\"String::Utf16ToUtf8 Conversion Failed\""; if ( uiSize == 0 ) { return std::string(); } const int iRequiredLength = WideCharToMultiByte( CP_UTF8, 0, szSource, uiSize, NULL, 0, NULL, NULL ); if ( iRequiredLength == 0 ) { //ALOGE( gLogRoot, "Failed to determine length of the converted UTF-8 string: %d", GetLastError() ); return sWrongString; } std::string sResult( iRequiredLength, '\0' ); const int iConvertResult = WideCharToMultiByte( CP_UTF8, 0, szSource, uiSize, const_cast<char*>( sResult.data() ), iRequiredLength, NULL, NULL ); if ( iConvertResult != iRequiredLength ) { //ALOGE( gLogRoot, "Failed to convert UTF-16 string to UTF-8 string: %d", GetLastError() ); return sWrongString; } return sResult; }
std::string UriEncode(const std::string & sSrc) { const char DEC2HEX[16 + 1] = "0123456789ABCDEF"; const unsigned char * pSrc = (const unsigned char *)sSrc.c_str(); const int SRC_LEN = sSrc.length(); unsigned char * const pStart = new unsigned char[SRC_LEN * 3]; unsigned char * pEnd = pStart; const unsigned char * const SRC_END = pSrc + SRC_LEN; for (; pSrc < SRC_END; ++pSrc) { if (SAFE[*pSrc]) *pEnd++ = *pSrc; else { // escape this char *pEnd++ = '%'; *pEnd++ = DEC2HEX[*pSrc >> 4]; *pEnd++ = DEC2HEX[*pSrc & 0x0F]; } } std::string sResult((char *)pStart, (char *)pEnd); delete [] pStart; return sResult; }
std::string UriDecode(const std::string & sSrc) { const unsigned char * pSrc = (const unsigned char *)sSrc.c_str(); const long SRC_LEN = sSrc.length(); const unsigned char * const SRC_END = pSrc + SRC_LEN; const unsigned char * const SRC_LAST_DEC = SRC_END - 2; char * const pStart = new char[SRC_LEN]; char * pEnd = pStart; while (pSrc < SRC_LAST_DEC) { if (*pSrc == '%') { char dec1, dec2; if (-1 != (dec1 = HEX2DEC[*(pSrc + 1)]) && -1 != (dec2 = HEX2DEC[*(pSrc + 2)])) { *pEnd++ = (dec1 << 4) + dec2; pSrc += 3; continue; } } *pEnd++ = *pSrc++; } while (pSrc < SRC_END) *pEnd++ = *pSrc++; std::string sResult(pStart, pEnd); delete [] pStart; return sResult; }
std::string MultiByteToUtf8( const char* const szSource, const _U32 uiSize ) { static std::string sWrongString = "\"String::MultiByteToUtf8 Conversion Failed\""; if ( uiSize == 0 ) { return std::string(); } const int iRequiredLength = MultiByteToWideChar( CP_ACP, MB_ERR_INVALID_CHARS, szSource, uiSize, NULL, 0 ); if ( iRequiredLength == 0 ) { //ALOGE( gLogRoot, "Failed to determine length of converted UTF-8 string: %d", GetLastError() ); return sWrongString; } std::wstring sResult( iRequiredLength, L'\0' ); const int iConvertResult = MultiByteToWideChar( CP_ACP, MB_ERR_INVALID_CHARS, szSource, uiSize, const_cast<wchar_t*>( sResult.data() ), iRequiredLength ); if ( iConvertResult != iRequiredLength ) { //ALOGE( gLogRoot, "Failed to convert MultiByte string to UTF-8 string: %d", GetLastError() ); return sWrongString; } return Utf16ToUtf8( sResult ); }
eString Mid(const eString &str, const unsigned int start, const unsigned int length) { unsigned int len = length; unsigned int sPos = start; char *lpszResult; // Error Checking if (sPos > 0) sPos--; if (sPos < 0) return ""; if (sPos >= str.eStr_Len) return ""; if (len == 0) len = str.eStr_Len; if (len > str.eStr_Len) len = str.eStr_Len; if ((sPos + len) > str.eStr_Len) len = (str.eStr_Len - sPos); lpszResult = new char [(len + 1)]; strncpy(lpszResult, (&(str.eStr_Str[sPos])), len); lpszResult[len] = 0; eString sResult(lpszResult); delete [] lpszResult; return sResult; }
std::string Utf8ToMultiByte( const char* const szSource, const _U32 uiSize ) { static std::string sWrongString = "\"String::MultiByteToUtf8 Conversion Failed\""; if ( uiSize == 0 ) { return std::string(); } std::wstring wsTemp = String::Utf8ToUtf16( szSource, uiSize ); const int iRequiredLength = WideCharToMultiByte( CP_ACP, 0, wsTemp.c_str(), (_U32)( wsTemp.length() ), NULL, 0, NULL, NULL ); if ( iRequiredLength == 0 ) { //ALOGE( gLogRoot, "Failed to determine length of the converted MultiByte string: %d", GetLastError() ); return sWrongString; } std::string sResult( iRequiredLength, '\0' ); const int iConvertResult = WideCharToMultiByte( CP_ACP, 0, wsTemp.c_str(), (_U32)( wsTemp.length() ), const_cast<char*>( sResult.data() ), iRequiredLength, NULL, NULL ); if ( iConvertResult != iRequiredLength ) { //ALOGE( gLogRoot, "Failed to convert UTF-8 string to MultiByte string: %d", GetLastError() ); return sWrongString; } return sResult; }
// /// <summary> // /// Get string array from ptr // /// </summary> // internal static string[] GetStringArrayFromPtrLA(IntPtr pointer, int nLength) // { // IntPtr[] rawRows = new IntPtr[nLength]; // string[] oResult = new string[nLength]; // Marshal.Copy(pointer, rawRows, 0, nLength); // // for (int i = 0; i < nLength; i++) // { // oResult[i] = Marshal.PtrToStringAnsi(rawRows[i]); // } // for (int) // // LA.FreeMatrix(pointer, nLength); // return oResult; // } // GetStringArrayFromPtrLA(pointer, nLength) // /// <summary> /// Get string from ptr /// </summary> string GetStringFromPtr(IntPtr &pointer, int nLength) { char* oneString = (char*) pointer; // string sResult = Marshal.PtrToStringAnsi(pointer, nLength); // StructAnalysis.FreeVector(pointer); string sResult(oneString); return sResult; }
CString CString::ToLower() const { CString sResult(* this); for (T_ULONG i = 0; i < sResult.m_Length; i++) { if ((sResult.m_String[i] >= 65) && (sResult.m_String[i] <= 90)) { sResult.m_String[i] = sResult.m_String[i] + 32; } } return (sResult); } // ToLower
CString CString::ToUpper() const { CString sResult(* this); for (T_ULONG i = 0; i < sResult.m_Length; i++) { if ((sResult.m_pString[i] >= 97) && (sResult.m_pString[i] <= 122)) { sResult.m_pString[i] = sResult.m_pString[i] - 32; } } return (sResult); } // ToLower
/** Format a string by performing substitution * It is mainly intended for formatting Configuration names such as "'$(Configuration)|$(Platform)'=='Debug|Win32'" * \param sString : the string to format * \return the formatted string */ wxString MSVC10Loader::SubstituteConfigMacros(const wxString& sString) { wxString sResult(sString); sResult.Replace(_T("$(Configuration)"), _T("")); sResult.Replace(_T("$(Platform)"), _T("")); sResult.Replace(_T("=="), _T("")); sResult.Replace(_T("\'"), _T("")); sResult.Replace(_T("|"), _T(" ")); sResult.Trim(false); return sResult; }
CString CString::operator+(const CString & tString) const { CString sResult((T_CHAR *)NULL); sResult.m_Length = m_Length + tString.m_Length; if (sResult.m_Length != 0) { sResult.m_pString = (T_CHAR *)malloc((sResult.m_Length + 1) * sizeof(T_CHAR)); STATIC_strcpy(sResult.m_pString, m_pString, m_Length); STATIC_strcpy(sResult.m_pString + m_Length, tString.m_pString, tString.m_Length); sResult.m_pString[sResult.m_Length] = '\0'; } return (sResult); } // operator+
/********************************************//** * Safe encode URL ***********************************************/ std::string CE2STBUtils::URLEncodeInline(const std::string& strURL) { const char SAFE[256] = { /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ /* 0 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 3 */1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 4 */0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 5 */1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 6 */0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 7 */1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 8 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 9 */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* B */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* D */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* E */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* F */0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; const char DEC2HEX[16 + 1] = "0123456789ABCDEF"; const unsigned char * pSrc = (const unsigned char *) strURL.c_str(); const int SRC_LEN = strURL.length(); unsigned char * const pStart = new unsigned char[SRC_LEN * 3]; unsigned char * pEnd = pStart; const unsigned char * const SRC_END = pSrc + SRC_LEN; for (; pSrc < SRC_END; ++pSrc) { if (SAFE[*pSrc]) { *pEnd++ = *pSrc; } else { // escape this char *pEnd++ = '%'; *pEnd++ = DEC2HEX[*pSrc >> 4]; *pEnd++ = DEC2HEX[*pSrc & 0x0F]; } } std::string sResult((char *) pStart, (char *) pEnd); delete[] pStart; return sResult; }
AVSINLINE const CStringA Encoding::wstring2string(const CStringW &sLine, const unsigned int unCodePage) { const int nSize = WideCharToMultiByte( unCodePage, 0, sLine.GetString(), sLine.GetLength(), NULL, 0, NULL, NULL ); char *sTemp = new char[nSize]; if ( !sTemp ) return ""; WideCharToMultiByte( unCodePage, 0, sLine.GetString(), sLine.GetLength(), sTemp, nSize, NULL, NULL ); CStringA sResult( sTemp ); delete []sTemp; return sResult; }
CString CPath::AddBackSlash(LPCTSTR szFolderPath, BOOL bInverted) { CString sResult(szFolderPath); int nLastChar = sResult.GetLength() - 1; if(nLastChar >= 0) { if((sResult[nLastChar] != _T('\\')) && (sResult[nLastChar] != _T('/'))) { sResult += bInverted ? _T('/') : _T('\\'); } } return(sResult); }
/*--------------------------------------------------------------------------------------------- Name : RemoveBackSlash(LPCTSTR szFolderPath) Purpose : Removes a trailing back slash (or normal slash) if found at the end of szFolderPath Parameters : LPCTSTR szFolderPath - Source path Return : CString - new path Globals Modified : None. --------------------------------------------------------------------------------------------*/ CString CPath::RemoveBackSlash(LPCTSTR szFolderPath) { CString sResult(szFolderPath); int nLastChar = sResult.GetLength() - 1; if(nLastChar >= 0) { if((sResult[nLastChar] == _T('\\')) || (sResult[nLastChar] == _T('/'))) { sResult = sResult.Left(nLastChar); } } return(sResult); }
AVSINLINE const CStringW Encoding::string2wstring(const CStringA &sLine, const unsigned int unCodePage) { const int nSize = MultiByteToWideChar( unCodePage, 0, sLine.GetString(), sLine.GetLength(), NULL, 0 ); wchar_t *sTemp = new wchar_t[nSize]; if ( !sTemp ) return _T(""); MultiByteToWideChar( unCodePage, 0, sLine.GetString(), sLine.GetLength(), sTemp, nSize ); CStringW sResult( sTemp ); delete []sTemp; return sResult; }
QString UPnpCDSExtension::RemoveToken( const QString &sToken, const QString &sStr, int num ) { QString sResult( "" ); int nPos = -1; for (int nIdx=0; nIdx < num; nIdx++) { if ((nPos = sStr.findRev( sToken, nPos )) == -1) break; } if (nPos > 0) sResult = sStr.left( nPos ); return sResult; }
void GPageLoadRequestManager::Notify(GLoadersManagerRequestNotify &oNotify) throw(GException) { LOG_LEVEL4("Notify()"); QMutexLocker oLocker(&m_qmInternalMutex); GAbsPageLoadRequest* pRequest(0); for( int i = 0; i < m_qlsReqs.size(); ++i ) { if( m_qlsReqs.at(i)->GetRequestId() == oNotify.GetRequest()->GetRequestId() ) { pRequest = oNotify.GetRequest(); m_qlsReqs.removeAt(i); break; } } if( pRequest != 0 ) { QString sResult("Timeout"); if( oNotify.GetNofifyType() == GLoadersManagerRequestNotify::eContentLoadComplete ) { m_pMainView->setPage(oNotify.GetWebPage()); sResult = "Completed"; SetAsActive(oNotify.GetLoadersManagerId()); } static QString const strTemp("RequestId(%1), has been completed with result (%2) for (%3)."); LOG_LEVEL4(QString(strTemp) . arg(pRequest->GetRequestId()) . arg(sResult) . arg(GetSessionName(pRequest->GetSessionId()))); if( pRequest->IsSynchronize() ) { GAbsView::SignalSynchronize( (sResult=="Completed")?(true):(false) ); } delete pRequest; ProcessNewRequest(); return; } throw(GException("Cannot found the request in the internal queue.")); }
/** decodes a URI encoded string into a normal string. */ static std::string uriDecode(const std::string & sSrc) { // Note from RFC1630: "Sequences which start with a percent // sign but are not followed by two hexadecimal characters // (0-9, A-F) are reserved for future extension" const unsigned char * pSrc = (const unsigned char *)sSrc.c_str(); const int SRC_LEN = sSrc.length(); const unsigned char * const SRC_END = pSrc + SRC_LEN; // last decodable '%' const unsigned char * const SRC_LAST_DEC = SRC_END - 2; char * const pStart = new char[SRC_LEN]; char * pEnd = pStart; while (pSrc < SRC_LAST_DEC) { if (*pSrc == '%') // replace %2A with corresponding ASCII character { char dec1, dec2; unsigned char c1=*(pSrc+1); unsigned char c2=*(pSrc+2); if (-1 != (dec1 = HEX2DEC(c1)) && -1 != (dec2 = HEX2DEC(c2))) { *pEnd++ = (dec1 << 4) + dec2; pSrc += 3; continue; } } else if (*pSrc == '+') // replace '+' with space { *pEnd++ = ' '; pSrc++; continue; } *pEnd++ = *pSrc++; } // the last 2- chars while (pSrc < SRC_END) *pEnd++ = *pSrc++; std::string sResult(pStart, pEnd); delete [] pStart; return sResult; }
//把宽字符串转换成字符串,输出使用 AINIKU_API string wstring2string(wstring sToMatch) { #ifdef _A_LINUX int iLen = wcstombs(NULL, sToMatch.c_str(), 0); // 计算转换后字符串的长度。(不包含字符串结束符) char *lpsz = new char[iLen + 1]; int i = wcstombs(lpsz, sToMatch.c_str(), iLen); // 转换。(没有结束符) lpsz[iLen] = '/0'; string sResult(lpsz); delete[]lpsz; #else string sResult; int iLen = WideCharToMultiByte(CP_ACP, NULL, sToMatch.c_str(), -1, NULL, 0, NULL, FALSE); // 计算转换后字符串的长度。(包含字符串结束符) char *lpsz = new char[iLen]; WideCharToMultiByte(CP_OEMCP, NULL, sToMatch.c_str(), -1, lpsz, iLen, NULL, FALSE); // 正式转换。 sResult.assign(lpsz, iLen - 1); // 对string对象进行赋值。 delete[]lpsz; #endif return sResult; }
//--------------------------------------------------------- //--------------------------------------------------------- std::string URLDecode(const std::string& instrSrc) { // Note from RFC1630: "Sequences which start with a percent // sign but are not followed by two hexadecimal characters // (0-9, A-F) are reserved for future extension" const unsigned char* pSrc = (const unsigned char*)instrSrc.c_str(); const u32 udwSourceLength = static_cast<u32>(instrSrc.length()); const unsigned char* const pSourceEnd = pSrc + udwSourceLength; // last decodable '%' const unsigned char* const pSourceLastDecode = pSourceEnd - 2; char* const pStart = new char[udwSourceLength]; char* pEnd = pStart; while(pSrc < pSourceLastDecode) { if(*pSrc == '%') { char dec1 = static_cast<char>(Utils::HexToDec((pSrc + 1))); char dec2 = static_cast<char>(Utils::HexToDec((pSrc + 2))); if(-1 != dec1 && -1 != dec2) { *pEnd++ = (dec1 << 4) + dec2; pSrc += 3; continue; } } *pEnd++ = *pSrc++; } // the last 2- chars while(pSrc < pSourceEnd) { *pEnd++ = *pSrc++; } std::string sResult(pStart, pEnd); delete [] pStart; return sResult; }
CString CPathFinder::RemoveBackSlash(LPCTSTR szFolderPath) { /* CString sResult(szFolderPath); int nLastChar = sResult.GetLength() - 1; if (nLastChar >= 0) { if ((sResult[nLastChar] == '\\') || (sResult[nLastChar] == '/')) sResult = sResult.Left(nLastChar); } return sResult; */ CString sResult(szFolderPath); sResult.TrimRight('\\'); return sResult; }
CString CPathFinder::AddBackSlash(LPCTSTR szFolderPath, BOOL bInverted) { /* CString sResult(szFolderPath); int nLastChar = sResult.GetLength() - 1; if (nLastChar >= 0) { if ((sResult[nLastChar] != '\\') && (sResult[nLastChar] != '/')) sResult += bInverted ? '/' : '\\'; } return sResult; */ CString sResult(szFolderPath); sResult.TrimRight('\\'); sResult += '\\'; return sResult; }
// // Handler // INT_32 FnMBSubstring::Handler(CDT * aArguments, const UINT_32 iArgNum, CDT & oCDTRetVal, Logger & oLogger) { // Check number of parameters if (iArgNum == 0) { oCDTRetVal = ""; return 0; } // substr('foobar', 2) -> 'obar' if (iArgNum == 2) { const UINT_32 iOffset = UINT_32(aArguments[0].GetInt()); const STLW::string sResult = aArguments[1].GetString(); CCHAR_P szStart = sResult.data(); CCHAR_P szEnd = sResult.data() + sResult.size(); INT_32 iPos = 0; UINT_32 iCharPos = 0; for(;;) { INT_32 iCharLen = utf_charlen(szStart + iPos, szEnd); if (iCharLen == -3) { break; } // Check character length if (iCharLen < 0) { iCharLen = 1; } // Skip errors else { ++iCharPos; } iPos += iCharLen; if (iCharPos >= iOffset) { break; } } if (iCharPos < iOffset) { oCDTRetVal = ""; } else { oCDTRetVal = sResult.substr(iPos); } return 0; } // substr('foobar', 2, 3) -> 'oba' if (iArgNum == 3) { const UINT_32 iBytes = UINT_32(aArguments[0].GetInt()); const UINT_32 iOffset = UINT_32(aArguments[1].GetInt()); const STLW::string sResult = aArguments[2].GetString(); CCHAR_P szStart = sResult.data(); CCHAR_P szEnd = sResult.data() + sResult.size(); INT_32 iPos = 0; UINT_32 iCharOffset = 0; UINT_32 iCharPos = 0; for(;;) { INT_32 iCharLen = utf_charlen(szStart + iPos, szEnd); if (iCharLen == -3) { break; } // Check character length if (iCharLen < 0) { iCharLen = 1; } // Skip errors else { ++iCharPos; } iPos += iCharLen; if (iCharPos == iOffset) { iCharOffset = iPos; } if (iCharPos == iOffset + iBytes) { break; } } if (sResult.size() < iCharOffset) { oCDTRetVal = ""; } else { oCDTRetVal = sResult.substr(iCharOffset, iPos - iCharOffset); } return 0; } // substr('foobar', 2, 3, '1234567') -> 'fo1234567r' if (iArgNum == 4) { STLW::string sReplacement = aArguments[0].GetString(); const UINT_32 iBytes = UINT_32(aArguments[1].GetInt()); const UINT_32 iOffset = UINT_32(aArguments[2].GetInt()); const STLW::string sTMP = aArguments[3].GetString(); CCHAR_P szStart = sTMP.data(); CCHAR_P szEnd = sTMP.data() + sTMP.size(); UINT_32 iPos = 0; UINT_32 iCharOffset = 0; UINT_32 iCharPos = 0; for(;;) { INT_32 iCharLen = utf_charlen(szStart + iPos, szEnd); if (iCharLen == -3) { break; } // Check character length if (iCharLen < 0) { iCharLen = 1; } // Skip errors else { ++iCharPos; } iPos += iCharLen; if (iCharPos == iOffset) { iCharOffset = iPos; } if (iCharPos == iOffset + iBytes) { break; } } if (sTMP.size() < iCharOffset) { oCDTRetVal = ""; return 0; } STLW::string sResult(sTMP, 0, iCharOffset); sResult.append(sReplacement); if (iPos == sTMP.size()) { oCDTRetVal = sResult; return 0; } sResult.append(sTMP, iPos, STLW::string::npos); oCDTRetVal = sResult; return 0; } oLogger.Emerg("Usage: MB_SUBSTR(x, offset[, bytes[, y]]])"); return -1; }
CString Login(CString strUser,CString strPswod,CString strIp,CString strbForce) { HRESULT hr = ::CoInitialize(NULL); CString sResult(""); try { ProcessClientServicesLib::IRpcCallHelperPtr piClientHelper(__uuidof(ProcessClientServicesLib::RpcCallHelper)); _bstr_t bstrUser(strUser); _bstr_t bstrPassword(strPswod); _bstr_t bstrIp(strIp); _bstr_t bstrForce(strbForce); sResult = (LPCTSTR)_bstr_t(piClientHelper->ERMDoLogin(bstrUser, bstrPassword,bstrIp,bstrForce)); if (sResult.Find("ticket-proxy=") == -1) { if (sResult.Compare("-2") == 0) { printf("系统错误,请确认服务器工作正常\n"); } else if (sResult.Compare("-6") == 0) { printf("用户不存在\n"); } else if (sResult.Compare("-7") == 0) { printf("密码错误\n"); } else if (sResult.Compare("-8") == 0) { printf( "用户被锁定\n"); } else if (sResult.Compare("-9") == 0) { printf("用户被删除\n"); } else if (sResult.Compare("-10") == 0) { printf("用户被禁用\n"); } else { printf("登录失败,请确认服务器工作正常\n"); } } } catch (_com_error e) { CString strErrorMsg = e.ErrorMessage(); ZTools::WriteZToolsFormatLog("RPC组件调用异常,%s", strErrorMsg); return ""; } catch (COleException* e) { TCHAR szCause[255]; CString strFormatted; e->GetErrorMessage(szCause, 255); ZTools::WriteZToolsFormatLog("PRC组件调用异常,%s", szCause); return ""; } catch (CException* e) { TCHAR szCause[255]; CString strFormatted; e->GetErrorMessage(szCause, 255); ZTools::WriteZToolsFormatLog("RPC组件调用异常,%s", szCause); return ""; } if (SUCCEEDED(hr)) { ::CoUninitialize(); } return sResult; }