Esempio n. 1
0
void CCaHtmlParse::__GetPriceAndRamainTicket(UINT *pPrice, UINT *pRemainTicket, const TidyDoc & tdoc, const TidyNode & tdNode)
{
	CStringA straRet;
	*pPrice = 0;
	*pRemainTicket = 0;

	TidyBuffer text = {0};
	tidyBufInit(&text);
	TidyNodeType type = tidyNodeGetType(tdNode);
	tidyNodeGetText(tdoc, tdNode, &text);
	straRet.Format("%s",text.bp);
	straRet.TrimLeft();

	CStringA straKey("</font>");
	int iPos = straRet.Find(straKey);
	int iEndPos = straRet.Find("</strong>");
	int iStartPos = iPos+straKey.GetLength();
	CStringA straPrice = straRet.Mid(iStartPos, iEndPos-iStartPos);
	straPrice.Remove(0x0d);//去掉回车
	straPrice.Remove(0x0a);//去掉换行
	*pPrice = atoi(straPrice.GetBuffer(0));
	straPrice.ReleaseBuffer();

	//剩余座位
	straKey = ":";
	iPos = straRet.Find(straKey);
	iEndPos = straRet.Find("</td>");
	iStartPos = iPos+straKey.GetLength();
	CStringA straRemainSeat = straRet.Mid(iStartPos, iEndPos-iStartPos);
	*pRemainTicket = atoi(straRemainSeat.GetBuffer(0));
	straRemainSeat.ReleaseBuffer();

	tidyBufFree(&text);
}
Esempio n. 2
0
int CGit::GetRemoteList(STRING_VECTOR &list)
{
	if (this->m_IsUseLibGit2)
	{
		git_repository *repo = NULL;

		CStringA gitdir = CUnicodeUtils::GetMulti(CTGitPath(m_CurrentDir).GetGitPathString(), CP_UTF8);
		if (git_repository_open(&repo, gitdir.GetBuffer()))
		{
			gitdir.ReleaseBuffer();
			return -1;
		}
		gitdir.ReleaseBuffer();

		git_strarray remotes;

		if (git_remote_list(&remotes, repo))
		{
			git_repository_free(repo);
			return -1;
		}

		for (size_t i = 0; i < remotes.count; i++)
		{
			CStringA remote(remotes.strings[i]);
			list.push_back(CUnicodeUtils::GetUnicode(remote));
		}

		git_strarray_free(&remotes);

		git_repository_free(repo);

		std::sort(list.begin(), list.end());

		return 0;
	}
	else
	{
		int ret;
		CString cmd, output;
		cmd=_T("git.exe remote");
		ret = Run(cmd, &output, NULL, CP_UTF8);
		if(!ret)
		{
			int pos=0;
			CString one;
			while( pos>=0 )
			{
				one=output.Tokenize(_T("\n"),pos);
				if (!one.IsEmpty())
					list.push_back(one);
			}
		}
		return ret;
	}
}
Esempio n. 3
0
CGitHash CGit::GetHash(TCHAR* friendname)
{
	// no need to parse a ref if it's already a 40-byte hash
	if (CGitHash::IsValidSHA1(friendname))
	{
		CString sHash(friendname);
		return CGitHash(sHash);
	}

	if (m_IsUseLibGit2)
	{
		git_repository *repo = NULL;
		CStringA gitdirA = CUnicodeUtils::GetMulti(CTGitPath(m_CurrentDir).GetGitPathString(), CP_UTF8);
		if (git_repository_open(&repo, gitdirA.GetBuffer()))
		{
			gitdirA.ReleaseBuffer();
			return CGitHash();
		}
		gitdirA.ReleaseBuffer();

		CStringA refnameA = CUnicodeUtils::GetMulti(friendname, CP_UTF8);

		git_object * gitObject = NULL;
		if (git_revparse_single(&gitObject, repo, refnameA.GetBuffer()))
		{
			refnameA.ReleaseBuffer();
			git_repository_free(repo);
			return CGitHash();
		}
		refnameA.ReleaseBuffer();

		const git_oid * oid = git_object_id(gitObject);
		if (oid == NULL)
		{
			git_object_free(gitObject);
			git_repository_free(repo);
			return CGitHash();
		}

		CGitHash hash((char *)oid->id);

		git_object_free(gitObject); // also frees oid
		git_repository_free(repo);

		return hash;
	}
	else
	{
		CString cmd;
		CString out;
		cmd.Format(_T("git.exe rev-parse %s" ),FixBranchName(friendname));
		Run(cmd, &out, NULL, CP_UTF8);
		return CGitHash(out.Trim());
	}
}
Esempio n. 4
0
BSTR CBoxEncoding::Base64Encode(VARIANT& var)
{
	CBoxBinPtr varPtr(var);
	CStringA str;
	LPSTR pstr;
	int strSize;
	int nPos, i;

	strSize = ((varPtr.m_nSize + 2) / 3) * 4;
	strSize += (strSize / 64) * 2;
	pstr = str.GetBuffer(strSize);

	for(i = 0, nPos = 0; i < varPtr.m_nSize; i += 48)
		if(varPtr.m_nSize - i > 48)
		{
			EVP_EncodeBlock((unsigned char*)pstr + nPos, (unsigned char*)varPtr + i, 48);
			nPos += 64;
			pstr[nPos ++] = '\r';
			pstr[nPos ++] = '\n';
		}else
			EVP_EncodeBlock((unsigned char*)pstr + nPos, (unsigned char*)varPtr + i, varPtr.m_nSize - i);

	str.ReleaseBuffer(strSize);
	return str.AllocSysString();
}
Esempio n. 5
0
bool CStringUtils::ReadStringFromTextFile(const CString& path, CString& text)
{
	if (!PathFileExists(path))
		return false;
	try
	{
		CStdioFile file;
		// w/o typeBinary for some files \r gets dropped
		if (!file.Open(path, CFile::typeBinary | CFile::modeRead | CFile::shareDenyWrite))
			return false;

		CStringA filecontent;
		UINT filelength = (UINT)file.GetLength();
		int bytesread = (int)file.Read(filecontent.GetBuffer(filelength), filelength);
		filecontent.ReleaseBuffer(bytesread);
		text = CUnicodeUtils::GetUnicode(filecontent);
		file.Close();
	}
	catch (CFileException* pE)
	{
		text.Empty();
		pE->Delete();
	}
	return true;
}
Esempio n. 6
0
/**
 * Returns the .git-path (if .git is a file, read the repository path and return it)
 * adminDir always ends with "\"
 */
bool GitAdminDir::GetAdminDirPath(const CString& projectTopDir, CString& adminDir, bool* isWorktree)
{
	CString wtAdminDir;
	if (!GetWorktreeAdminDirPath(projectTopDir, wtAdminDir))
		return false;

	CString pathToCommonDir = wtAdminDir + L"commondir";
	if (!PathFileExists(pathToCommonDir))
	{
		adminDir = wtAdminDir;
		if (isWorktree)
			*isWorktree = false;
		return true;
	}

	CAutoFILE pFile = _wfsopen(pathToCommonDir, L"rb", SH_DENYWR);
	if (!pFile)
		return false;

	int size = 65536;
	CStringA commonDirA;
	int length = (int)fread(commonDirA.GetBufferSetLength(size), sizeof(char), size, pFile);
	commonDirA.ReleaseBuffer(length);
	CString commonDir = CUnicodeUtils::GetUnicode(commonDirA);
	commonDir.TrimRight(L"\r\n");
	commonDir.Replace(L'/', L'\\');
	if (PathIsRelative(commonDir))
		adminDir = CPathUtils::BuildPathWithPathDelimiter(wtAdminDir + commonDir);
	else
		adminDir = CPathUtils::BuildPathWithPathDelimiter(commonDir);
	if (isWorktree)
		*isWorktree = true;
	return true;
}
BOOL CRichEditSpellCheck::GetWord(const CHARRANGE& cr, CStringA& sWord) const
{
	if (cr.cpMax > cr.cpMin)
	{
		static CStringA sWord;

		TEXTRANGE tr;
		tr.chrg = cr;

#if defined(UNICODE) || defined(_UNICODE)
		CString strTemp;
		tr.lpstrText = strTemp.GetBuffer(cr.cpMax - cr.cpMin);
		m_re.SendMessage(EM_GETTEXTRANGE, 0, (LPARAM)&tr);
		strTemp.ReleaseBuffer();
		sWord = ATL::CT2A(strTemp);
#else
		tr.lpstrText = sWord.GetBuffer(cr.cpMax - cr.cpMin);
		m_re.SendMessage(EM_GETTEXTRANGE, 0, (LPARAM)&tr);
		sWord.ReleaseBuffer();
#endif   // UNICODE || _UNICODE
	}
	else
	{
		sWord.Empty();
	}

	// else
	return !sWord.IsEmpty();
}
Esempio n. 8
0
BOOL CSxSParser::ParseFile(LPCTSTR szFilePath)
{
    CPEResource res;
    if(!res.Open(szFilePath))
        return FALSE;

    LPVOID pData = NULL;
    DWORD dwLength = 0;
    if(!res.GetManifest(pData, dwLength))
        return FALSE;

    if(pData == NULL)
        return TRUE;

    CStringA strManifest;
    LPSTR pManifest = strManifest.GetBufferSetLength(dwLength);
    memcpy(pManifest, pData, dwLength);
    strManifest.ReleaseBuffer();

    int nStart = 0;
    CStringA strAssembly = Util::GetToken(strManifest, "<dependentAssembly>", "</dependentAssembly>", nStart);
    for(; !strAssembly.IsEmpty(); strAssembly = Util::GetToken(strManifest, "<dependentAssembly>", "</dependentAssembly>", nStart))
    {
        CSxSItem item;

        if(!ParseAssembly(strAssembly, item))
            return FALSE;

        item.listFiles.Add(szFilePath);
        AddAssemblyItem(item);
    }

    return TRUE;
}
Esempio n. 9
0
CStringW DecodeDoubleEncodedUtf8(LPCWSTR pszFileName)
{
    size_t nChars = wcslen(pszFileName);

    // Check if all characters are valid for UTF-8 value range
    //
    for (UINT i = 0; i < nChars; i++) {
        if ((_TUCHAR)pszFileName[i] > 0xFFU)
            return pszFileName; // string is already using Unicode character value range; return original
    }

    // Transform Unicode string to UTF-8 byte sequence
    //
    CStringA strA;
#pragma warning(disable : 4267)
    LPSTR pszA = strA.GetBuffer(nChars);

    for (UINT i = 0; i < nChars; i++)
        pszA[i] = (CHAR)pszFileName[i];
    strA.ReleaseBuffer(nChars);

    // Decode the string with UTF-8
    //
    CStringW strW;
    LPWSTR pszW = strW.GetBuffer(nChars);
    int iNewChars = utf8towc(strA, nChars, pszW, nChars);
#pragma warning(disable : 4267)
    if (iNewChars < 0) {
        strW.ReleaseBuffer(0);
        return pszFileName;		// conversion error (not a valid UTF-8 string); return original
    }
    strW.ReleaseBuffer(iNewChars);

    return strW;
}
Esempio n. 10
0
int ProjectProperties::GetStringProps(CString &prop, const CString &key)
{
	ATLASSERT(gitconfig);

	CStringA keyA = CUnicodeUtils::GetUTF8(key);
	const char * value = nullptr;
	if (git_config_get_string(&value, gitconfig, keyA.GetBuffer()))
	{
		keyA.ReleaseBuffer();
		return -1;
	}
	keyA.ReleaseBuffer();

	prop = CUnicodeUtils::GetUnicode(value);

	return 0;
}
Esempio n. 11
0
int ProjectProperties::GetBOOLProps(BOOL &b, const CString &key)
{
	ATLASSERT(gitconfig);

	CStringA keyA = CUnicodeUtils::GetUTF8(key);
	int value = FALSE;
	if (git_config_get_bool(&value, gitconfig, keyA.GetBuffer()))
	{
		keyA.ReleaseBuffer();
		return -1;
	}
	keyA.ReleaseBuffer();

	b = value;

	return 0;
}
Esempio n. 12
0
BOOL CSNMP::Init(LPCWSTR pAddress, LPCWSTR pCommunity, INT nTimeoutMilliSec, INT nRetry)
{
	if (!pAddress)
		return FALSE;

	if (!pCommunity)
		return FALSE;

	CStringA strAddress = XLibS::StringCode::ConvertWideStrToAnsiStr(pAddress);
	CStringA strCommunity = XLibS::StringCode::ConvertWideStrToAnsiStr(pCommunity);

	m_SnmpSession = 
		::SnmpMgrOpen(strAddress.GetBuffer(), strCommunity.GetBuffer(), nTimeoutMilliSec, nRetry);
	strAddress.ReleaseBuffer();
	strCommunity.ReleaseBuffer();

	return m_SnmpSession != NULL;
}
CString CSettingGitCredential::Load(CString key)
{
	CString cmd;

	if (m_strUrl.IsEmpty())
		cmd.Format(_T("credential.%s"), key);
	else
		cmd.Format(_T("credential.%s.%s"), m_strUrl, key);

	git_config * config;
	git_config_new(&config);
	int sel = m_ctrlConfigType.GetCurSel();
	if (sel == ConfigType::Local)
	{
		CStringA projectConfigA = CUnicodeUtils::GetUTF8(g_Git.GetGitLocalConfig());
		git_config_add_file_ondisk(config, projectConfigA.GetBuffer(), GIT_CONFIG_LEVEL_LOCAL, FALSE);
		projectConfigA.ReleaseBuffer();
	}
	else if (sel == ConfigType::Global)
	{
		CStringA globalConfigA = CUnicodeUtils::GetUTF8(g_Git.GetGitGlobalConfig());
		git_config_add_file_ondisk(config, globalConfigA.GetBuffer(), GIT_CONFIG_LEVEL_GLOBAL, FALSE);
		globalConfigA.ReleaseBuffer();
		CStringA globalXDGConfigA = CUnicodeUtils::GetUTF8(g_Git.GetGitGlobalXDGConfig());
		git_config_add_file_ondisk(config, globalXDGConfigA.GetBuffer(), GIT_CONFIG_LEVEL_XDG, FALSE);
		globalXDGConfigA.ReleaseBuffer();
	}
	else if (sel == ConfigType::System)
	{
		CStringA systemConfigA = CUnicodeUtils::GetUTF8(g_Git.GetGitSystemConfig());
		git_config_add_file_ondisk(config, systemConfigA.GetBuffer(), GIT_CONFIG_LEVEL_SYSTEM, FALSE);
		systemConfigA.ReleaseBuffer();
	}
	
	CStringA cmdA = CUnicodeUtils::GetUTF8(cmd);
	CStringA valueA;
	const git_config_entry *entry;
	if (!git_config_get_entry(&entry, config, cmdA))
		valueA = CStringA(entry->value);
	cmdA.ReleaseBuffer();
	git_config_free(config);

	return CUnicodeUtils::GetUnicode(valueA);
}
Esempio n. 14
0
CStringA Util::String::UnicodeToGBK( CStringW unicode )
{
	CStringA strGBK = "";
	DWORD dwMinSize = 0;
	dwMinSize = WideCharToMultiByte(936, NULL, unicode, unicode.GetLength(),NULL, 0, NULL, FALSE);
	strGBK.GetBufferSetLength(dwMinSize);
	LPSTR lpszStr =  strGBK.GetBuffer();
	INT ok = WideCharToMultiByte(936, NULL, unicode, unicode.GetLength(), lpszStr, dwMinSize, NULL, FALSE);
	strGBK.ReleaseBuffer();
	return strGBK;
}
Esempio n. 15
0
static CStringW Unzip_GetCurentFilePath(unzFile uf, FILETIME& ftLocal)
{
    unz_file_info file_info;
    CStringA pathA;
    const int pathLen = 256;
    if (UNZ_OK != unzGetCurrentFileInfo(uf, &file_info, pathA.GetBuffer(pathLen), pathLen, NULL, 0, NULL, 0))
        throw runtime_error("failed to unzGetCurrentFileInfo");
    pathA.ReleaseBuffer(-1);
    DosDateTimeToFileTime((WORD)(file_info.dosDate>>16), (WORD)file_info.dosDate, &ftLocal);
    return CStringW(pathA);
}
Esempio n. 16
0
CStringA netbios_name::GetANSIName() const
{
	CStringA sName;
	LPSTR szName = sName.GetBuffer( NCBNAMSZ );
	CopyMemory( szName, (LPCSTR)netbiosed.name, NCBNAMSZ - 1 );
	szName[ NCBNAMSZ - 1 ] = 0;
	sName.ReleaseBuffer();
	sName.Trim();
	sName.OemToAnsi();
	return sName;
}
Esempio n. 17
0
MAP_STRING_STRING GetBranchDescriptions()
{
	MAP_STRING_STRING descriptions;
	git_config * config;
	git_config_new(&config);
	CStringA projectConfigA = CUnicodeUtils::GetMulti(g_Git.GetGitLocalConfig(), CP_UTF8);
	git_config_add_file_ondisk(config, projectConfigA.GetBuffer(), 3);
	projectConfigA.ReleaseBuffer();
	git_config_foreach_match(config, "branch\\..*\\.description", GetBranchDescriptionsCallback, &descriptions);
	git_config_free(config);
	return descriptions;
}
Esempio n. 18
0
CStringA CUnicodeUtils::GetMulti(const CStringW& string,int acp)
{
	char * buf;
	CStringA retVal;
	int len = string.GetLength();
	if (len==0)
		return retVal;
	buf = retVal.GetBuffer(len*4 + 1);
	int lengthIncTerminator = WideCharToMultiByte(acp, 0, string, -1, buf, len * 4, nullptr, nullptr);
	retVal.ReleaseBuffer(lengthIncTerminator-1);
	return retVal;
}
Esempio n. 19
0
bool CStrUtil::EncodeBase64(const BYTE *buf,int buflen,CString &outString)
{
	CStringA strA;
	int outlen = buflen*2;
	if(Base64Encode(buf,buflen,strA.GetBuffer(outlen),&outlen, ATL_BASE64_FLAG_NONE))
	{
		strA.ReleaseBuffer(outlen);
		outString = CA2T(strA);
		return true;
	}
	return false;
}
Esempio n. 20
0
CString CFileDataIO::ReadString(bool bOptUTF8, UINT uRawSize)
{
#ifdef _UNICODE
	const UINT uMaxShortRawSize = SHORT_RAW_ED2K_UTF8_STR;
	if (uRawSize <= uMaxShortRawSize)
	{
		char acRaw[uMaxShortRawSize];
		Read(acRaw, uRawSize);
		if (uRawSize >= 3 && (UCHAR)acRaw[0] == 0xEFU && (UCHAR)acRaw[1] == 0xBBU && (UCHAR)acRaw[2] == 0xBFU)
		{
			WCHAR awc[uMaxShortRawSize];
			int iChars = ByteStreamToWideChar(acRaw + 3, uRawSize - 3, awc, ARRSIZE(awc));
			if (iChars >= 0)
				return CStringW(awc, iChars);
		}
		else if (bOptUTF8)
		{
			WCHAR awc[uMaxShortRawSize];
			//int iChars = ByteStreamToWideChar(acRaw, uRawSize, awc, ARRSIZE(awc));
			int iChars = utf8towc(acRaw, uRawSize, awc, ARRSIZE(awc));
			if (iChars >= 0)
				return CStringW(awc, iChars);
		}
		return CStringW(acRaw, uRawSize); // use local codepage
	}
	else
	{
		Array<char> acRaw(uRawSize);
		Read(acRaw, uRawSize);
		if (uRawSize >= 3 && (UCHAR)acRaw[0] == 0xEFU && (UCHAR)acRaw[1] == 0xBBU && (UCHAR)acRaw[2] == 0xBFU)
		{
			Array<WCHAR> awc(uRawSize);
			int iChars = ByteStreamToWideChar(acRaw + 3, uRawSize - 3, awc, uRawSize);
			if (iChars >= 0)
				return CStringW(awc, iChars);
		}
		else if (bOptUTF8)
		{
			Array<WCHAR> awc(uRawSize);
			//int iChars = ByteStreamToWideChar(acRaw, uRawSize, awc, uRawSize);
			int iChars = utf8towc(acRaw, uRawSize, awc, uRawSize);
			if (iChars >= 0)
				return CStringW(awc, iChars);
		}
		return CStringW(acRaw, uRawSize); // use local codepage
	}
#else
	CStringA strA;
	Read(strA.GetBuffer(uRawSize), uRawSize);
	strA.ReleaseBuffer(uRawSize);
	return strA;
#endif
}
Esempio n. 21
0
void DLrtfhtml::openfile(CString filename)
{
	CStdioFile rtf;
	rtf.Open(_T("F:\\\\itbook2.tit"),CStdioFile::modeRead);
	int len=rtf.GetLength();
	rtf.SeekToBegin();
	CStringA content;
	rtf.Read(content.GetBuffer(len),len);
	content.ReleaseBuffer();
	rtf.Close();

	char* str,*strd;
	str=strd=new char[len+1];
	memset(str,'\0',sizeof(str));
	int bg,end;
	bg=end=0;
	char* p;
	while((end=content.Find("\\\'",end))>=0)
	{
		if(end==0 || content.GetAt(end-1)!='\\')
		{//转汉字
			CStringA s;
			if(end!=bg)
			{
				strcpy(str,(LPSTR)(LPCSTR)content.Mid(bg,end-bg));
				str+=(end-bg);
			}
			*str=strtol(content.Mid(end+2,2),&p,16);
			str++;
			bg=end+4;
		}
		else
		{// \\' 去斜杆
			if(end!=bg)
			{
				strcpy(str,(LPSTR)(LPCSTR)content.Mid(bg,end-bg-1)); //   '之前还有两个" \ "
				str+=(end-bg-1);
			}
			strcpy(str,(LPSTR)(LPCSTR)content.Mid(end,2));
			str+=2;
			bg=end+2;
		}
		end++;
	}
	int leng=content.GetLength();
	if((content.GetLength()-bg)>2)//如果再最后两个字符找到\'则会=2  当然根据rtf文档绝对不会这样。
		strcpy(str,(LPSTR)(LPCSTR)content.Mid(bg));
	//}
	int  unicodeLen = ::MultiByteToWideChar( CP_ACP,0,strd,-1,NULL,0);  
	MultiByteToWideChar(CP_ACP,0,strd,-1,(LPWSTR)destcon.GetBuffer(unicodeLen),unicodeLen);
	destcon.ReleaseBuffer();
}
Esempio n. 22
0
File: main.cpp Progetto: CCJY/coliru
CStringA ConvertUTF16ToUTF8( __in LPCWSTR pszTextUTF16, size_t wlen = 0 ) {
    if (pszTextUTF16 == NULL) return "";

    int utf8len = WideCharToMultiByte(CP_UTF8, 0, pszTextUTF16, wlen, 
        NULL, 0, NULL, NULL );

    CStringA result;
    WideCharToMultiByte(CP_UTF8, 0, pszTextUTF16, wlen, 
        result.GetBuffer(utf8len), utf8len, 0, 0 );
    result.ReleaseBuffer();

    return result;
}
Esempio n. 23
0
CStringA CUnicodeUtils::GetUTF8(const CStringW& string)
{
	char * buf;
	CStringA retVal;
	int len = string.GetLength();
	if (len==0)
		return retVal;
	buf = retVal.GetBuffer(len*4 + 1);
//	SecureZeroMemory(buf, (string.GetLength()*4 + 1)*sizeof(char));
	int lengthIncTerminator = WideCharToMultiByte(CP_UTF8, 0, string, -1, buf, len*4, NULL, NULL);
	retVal.ReleaseBuffer(lengthIncTerminator-1);
	return retVal;
}
Esempio n. 24
0
//To convert escaped characters back to their original values.
CString CStrUtil::DecodeURL(const CString& strSour)
{
	CStringA strDestination;

//#ifdef _UNICODE
//	WCHAR* pBuf = DecodeFromUTF8(FilterMultiBytes(strSour));
//	strDestination = pBuf;
//	delete []pBuf;
//#else	
//	DWORD dwLength = strSour.GetLength();
//	//TCHAR *pBuff = new TCHAR[dwLength + 1];
//	strDestination.GetBufferSetLength(dwLength);
//	if (AtlUnescapeUrl(strSour, strDestination.GetBuffer(), &dwLength, dwLength + 1))
//	{
//		strDestination.ReleaseBuffer();
//	}		
//	else
//	{
//		strDestination.ReleaseBuffer(0);
//	}
//#endif		

	CString strTemp = FilterMultiBytes(strSour);
	CStringA strA = CT2A(strTemp,CP_UTF8);
	DWORD dwLength = strA.GetLength();
	//TCHAR *pBuff = new TCHAR[dwLength + 1];
	strDestination.GetBufferSetLength(dwLength);
	if (AtlUnescapeUrl(strA, strDestination.GetBuffer(), &dwLength, dwLength + 1))
	{
		strDestination.ReleaseBuffer();
	}		
	else
	{
		strDestination.ReleaseBuffer(0);
	}

	strTemp = CA2T(strDestination,CP_UTF8);
	return strTemp;	
}
Esempio n. 25
0
BOOL LoadIDs(LPCTSTR szFilename)
{
	BOOL bSuccess = FALSE;

	FILE* pFile = NULL;
	if ( _tfopen_s( &pFile, szFilename, _T("rb") ) == 0 )
	{
		for (;;)
		{
			CStringA sLine;
			CHAR* res = fgets( sLine.GetBuffer( 4096 ), 4096, pFile );
			sLine.ReleaseBuffer();
			if ( ! res )
				break;		// End of file
			sLine.Trim( " \t\r\n" );
			if ( sLine.IsEmpty() || sLine.GetAt( 0 ) != '#' )
				continue;		// Skip empty lines
			int nPos = sLine.FindOneOf( " \t" );
			if ( nPos == -1 || sLine.Left( nPos ) != "#define" )
				continue;		// Skip unknown line
			sLine = sLine.Mid( nPos + 1 ).TrimLeft( " \t" );
			nPos = sLine.FindOneOf( " \t" );
			if ( nPos == -1 )
				continue;		// Skip unknown line
			CStringA sID = sLine.Left( nPos );
			sLine = sLine.Mid( nPos + 1 ).TrimLeft( " \t" );
			UINT nID = 0;
			if ( sLine.Left( 2 ).CompareNoCase( "0x" ) == 0 )
			{
				if ( sscanf_s( sLine, "%x", &nID ) != 1 )
					continue;	// Skip unknown line
			}
			else
			{
				if ( sscanf_s( sLine, "%u", &nID ) != 1 )
					continue;	// Skip unknown line
			}
			if ( g_oIDs.Lookup( sID, nID ) )
			{
				_tprintf( _T("Error: Duplicate ID %hs\n"), sID );
				continue;
			}
			g_oIDs.SetAt( sID, nID );
			bSuccess = TRUE;
		}
		fclose( pFile );
	}

	return bSuccess;
}
Esempio n. 26
0
BOOL CStdioFileEx::ReadAnsiString(CStringA& rString)
{
   _ASSERTE(m_pStream);
   rString = "";      // empty string without deallocating
   
   if(!m_bIsUnicodeText)
   {
      const int nMaxSize = 128;
      LPSTR lpsz = rString.GetBuffer(nMaxSize);
      LPSTR lpszResult;
      int nLen = 0;
      for (;;)
      {
         lpszResult = fgets(lpsz, nMaxSize+1, m_pStream);
         rString.ReleaseBuffer();
         
         // handle error/eof case
         if (lpszResult == NULL && !feof(m_pStream))
         {
            Afx_clearerr_s(m_pStream);
            AfxThrowFileException(CFileException::genericException, _doserrno,
               m_strFileName);
         }
         
         // if string is read completely or EOF
         if (lpszResult == NULL ||
            (nLen = (int)lstrlenA(lpsz)) < nMaxSize ||
            lpsz[nLen-1] == '\n')
            break;
         
         nLen = rString.GetLength();
         lpsz = rString.GetBuffer(nMaxSize + nLen) + nLen;
      }
      //remove crlf if exist.
      nLen = rString.GetLength();
      if (nLen > 1 && rString.Mid(nLen-2) == "\r\n")
      {
         rString.GetBufferSetLength(nLen-2);
      }
      return rString.GetLength() > 0;
   }
   else
   {
      CStringW wideString;
      BOOL bRetval = ReadWideString(wideString);
      //setlocale(LC_ALL, "chs_chn.936");//no need
      rString = wideString;
      return bRetval;
   }
}
Esempio n. 27
0
CString GetErrorMessage(pj_status_t status)
{
	CStringA str;
	char *buf = str.GetBuffer(PJ_ERR_MSG_SIZE-1);
	pj_strerror(status, buf, PJ_ERR_MSG_SIZE);
	str.ReleaseBuffer();
	int i = str.ReverseFind( '(' );
	if (i!=-1) {
		str = str.Left(i-1);
	}
	if (str == "Invalid Request URI" || str == "Invalid URI") {
		str = "Invalid number";
	}
	return Translate(CString(str).GetBuffer());
}
Esempio n. 28
0
CString ScintillaEditor::GetWord()
{
	int savePos = GetCurrentPos();
	SendEditor(SCI_WORDLEFT);
	DWORD startPos = GetCurrentPos();
	SendEditor(SCI_WORDRIGHTEXTEND);
	DWORD endPos = GetCurrentPos();
	CStringA str;
	LPSTR buf = str.GetBufferSetLength(endPos - startPos);
	GetSelText(buf);
	str.ReleaseBuffer(endPos - startPos);
	SendEditor(SCI_SETCURRENTPOS, savePos);

	return CString(str);
}
Esempio n. 29
0
void CLocalServer::LocalPingClient(INT_PTR nIndex)
{
	CComputerInfo& computer = ComputerList.GetComputer(nIndex);

	CStringA strTmp = CW2A(computer.GetTerminalID());

	NET_HEAD_MAN head = {0};

	head.Version = COM_VER;
	head.Length = strTmp.GetLength();
	head.Cmd = C_MANAGER_PING_CLIENT;

	SendBuffer(&head, strTmp.GetBuffer());
	strTmp.ReleaseBuffer();
}
Esempio n. 30
0
//##ModelId=474D3064004F
HGLOBAL CHTMLFormatAggregator::GetHGlobal()
{
	CHTMFormatStruct HtmlData;
	HtmlData.SetFragment(m_csNewText);
	HtmlData.SetURL(m_csSourceURL);
	HtmlData.SetVersion(m_csVersion);

	CStringA csHtmlFormat;
	HtmlData.Serialize(csHtmlFormat);

	long lLen = csHtmlFormat.GetLength();
	HGLOBAL hGlobal = NewGlobalP(csHtmlFormat.GetBuffer(lLen), lLen+sizeof(char));
	csHtmlFormat.ReleaseBuffer();

	return hGlobal;
}