Exemplo n.º 1
0
string GetKeyValueStrUnescape(const string& line, const string& key)
{
	vector<string> vecstrs;
	YL_StringUtil::Tokenize(line, vecstrs, "&");
	for(vector<string>::iterator iter = vecstrs.begin(); iter != vecstrs.end(); iter++)
	{
		string::size_type bpos = (*iter).find("=");
		if (bpos == string::npos)
			continue;
		string str = (*iter).substr(0, bpos);
		if(str == key)
		{
			string strval = (*iter).substr(bpos+1, (*iter).length()-bpos-1);
			return UTF8ToGB( YL_URLEncoder::decode((char*)strval.c_str()) );
		}
	}
	return "";
}
Exemplo n.º 2
0
string CDBRecordset::FieldVal(int nField)
{
	if(!m_bIsOpen) {
		return false;
	}

	string strResult = "";
	try
	{
		strResult = UTF8ToGB(m_query.fieldValue(nField));
	}
	catch (CppSQLite3Exception& e)
	{
		strResult = "";
		char szSource[1024]={0};
		_snprintf(szSource, sizeof(szSource), "MoveLast");
		CDBConnection::PrintError(e, szSource);
	}
	return strResult;
}
Exemplo n.º 3
0
bool CDBRecordset::FieldVal(char* pResult, const char* szField, UINT iMaxLength)
{
	if(!m_bIsOpen) {
		return false;
	}

	bool bRet = true;
	try
	{
		string strResult = UTF8ToGB(m_query.fieldValue(szField));
		strncpy(pResult, strResult.c_str(), iMaxLength);
	}
	catch (CppSQLite3Exception& e)
	{
		bRet = false;
		char szSource[1024]={0};
		_snprintf(szSource, sizeof(szSource), "MoveLast");
		CDBConnection::PrintError(e, szSource);
	}
	return bRet;
}
Exemplo n.º 4
0
void CVcardView::OnExportTxt() 
{
	// TODO: Add your command handler code here

    CVcardDoc* pDoc = GetDocument();  //获取文档对象指针,通过该指针来访问文档类的成员
	CString file_name = pDoc->file_path;  //获取文件名
	CStdioFile vcf_file;

	//以文本模式打开txt文件,默认是以二进制模式打开
	//以二进制打开读取时换行是0D 0A两个字符
	//此时程序中的换行和文本中比较会出现问题,程序中的是0A
	//设置读取模式只能是CFile的派生类(CStdioFile)使用
    //要不然设置成文本模式程序会崩溃
    if (vcf_file.Open(file_name, CStdioFile::modeRead|CStdioFile::typeText) == 0)  
 	{
 		AfxMessageBox("打开文件失败.");
		return;
 	}
     
	////////////////////////////vcf固定格式///////////////////////////////////
	const char* vcard_head = "BEGIN:VCARD\n";
    const char* vcard_end = "END:VCARD\n";
	
    const char* f_name_title = "FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:";
    const char*  mobile_number_title = "TEL;CELL:";
    const char*  home_number_title = "TEL;HOME:";
   //////////////////////////////////////////////////////////////////////////

    char name[512] = "";
    char mobile_number[64] = "";
    char home_number[64] = ""; // 可以存移动短号

	// 读取文件到内存
    size_t file_size = vcf_file.GetLength();  //获取文件大小
	char* inbuf = new char[file_size + 1];
	vcf_file.Read(inbuf, file_size);

    char* vcard_text = new char[8 * 1024];
    memset(vcard_text, 0, 8 * 1024);
    size_t offset = 0;
	
    const char* vps = inbuf;
    size_t count = file_size;
	// 判断是否是vcf文件,如果是则将记录写入vcard_text
    bool is_vcard = MemSearchVcard(vps, count, vcard_head, vcard_end,  vcard_text, &offset);
    if (!is_vcard)  //不是vcf文件
	{
		AfxMessageBox("文件格式错误,不是vcf格式");
		return;
	}
	
	CFileDialog vcard_dlg(FALSE, "txt", file_name);
	vcard_dlg.m_ofn.lpstrFilter = "txt files(*.txt)|*.txt||";
	vcard_dlg.m_ofn.lpstrTitle = "导出成txt文件";
	if (vcard_dlg.DoModal() == IDOK)
	{
		CFile txt_file;
		if (txt_file.Open(vcard_dlg.GetFileName(), CFile::modeWrite|CFile::modeCreate) == 0)
		{
			AfxMessageBox("转换失败");
			return;
		}
		CString title = "姓名\t移动电话\t家庭电话\n";
		txt_file.Write(title, title.GetLength());
        while (is_vcard)
		{
			const char* ps = vcard_text;
			const char* ps2 = vcard_text;
			size_t len = strlen(vcard_text);
			
			ps = MemoryFind(vcard_text, f_name_title, len);		
			if (ps != NULL)
			{
				// 搜索解码姓名
				ps2 = MemoryFind(ps, "\n", len - (ps - vcard_text));
				std::string str(ps + strlen(f_name_title), ps2);
				strcpy(name, str.c_str());
				QpDecode(name);
				UTF8ToGB(name, name, strlen(name));
				txt_file.Write(name, strlen(name));  //姓名写入文件
				txt_file.Write("\t", 1);
				
				// 获得电话号码
				ps = MemoryFind(vcard_text, mobile_number_title, len);
				if (ps != NULL)
				{
					ps2 = MemoryFind(ps, "\n", len - (ps - vcard_text));
					std::string str(ps + strlen(mobile_number_title), ps2);
					strcpy(mobile_number, str.c_str());
					txt_file.Write(mobile_number, strlen(mobile_number));
					txt_file.Write("\t", 1);
				}
				
				// 获得家庭电话
				ps = MemoryFind(vcard_text, home_number_title, len);
				if (ps != NULL)
				{
					ps2 = MemoryFind(ps, "\n", len - (ps - vcard_text));
					std::string str(ps + strlen(home_number_title), ps2);
					strcpy(home_number, str.c_str());
					txt_file.Write(home_number, strlen(home_number));
				}
				txt_file.Write("\n", 1);
			}
			
			// 移动到下一个 搜索区间
			count = file_size - offset;
			vps = inbuf + offset;
			is_vcard = MemSearchVcard(vps, count, vcard_head, vcard_end,  vcard_text, &offset);
		}
		
		// 释放内存和关闭文件
		delete[]  vcard_text;
		delete[]  inbuf;
        txt_file.Close();
		vcf_file.Close();
		AfxMessageBox("转换成功");
	}    
}