예제 #1
0
inline void encode(Unicode::const_iterator begin, Unicode::const_iterator end, string& res) {
#ifdef CPPJIEBA_GBK
  gbkTrans(begin, end, res);
#else
  unicodeToUtf8(begin, end, res);
#endif
}
예제 #2
0
        inline bool encode(vector<uint16_t>::const_iterator begin, vector<uint16_t>::const_iterator end, string& res)
        {
#ifdef CPPJIEBA_GBK
            return gbkTrans(begin, end, res);
#else
            return unicodeToUtf8(begin, end, res);
#endif
        }
예제 #3
0
std::string et::libraryBaseFolder()
{
	wchar_t* path = nullptr;
	SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, nullptr, &path);

	if (path == nullptr) 
		return emptyString;

	std::string result = addTrailingSlash(unicodeToUtf8(path));
	CoTaskMemFree(path);
	return result;
}
예제 #4
0
파일: os_win.c 프로젝트: bazhenovc/nebula3
/*
** Convert multibyte character string to UTF-8.  Space to hold the
** returned string is obtained from sqliteMalloc().
*/
static char *mbcsToUtf8(const char *zFilename){
  char *zFilenameUtf8;
  WCHAR *zTmpWide;

  zTmpWide = mbcsToUnicode(zFilename);
  if( zTmpWide==0 ){
    return 0;
  }
  zFilenameUtf8 = unicodeToUtf8(zTmpWide);
  sqliteFree(zTmpWide);
  return zFilenameUtf8;
}
예제 #5
0
std::string et::documentsBaseFolder()
{
	wchar_t* path = nullptr;
	SHGetKnownFolderPath(FOLDERID_Documents, 0, nullptr, &path);

	if (path == nullptr) 
		return std::string();

	std::string result = addTrailingSlash(unicodeToUtf8(path));
	CoTaskMemFree(path);
	return result;
}
예제 #6
0
/*
** Convert multibyte character string to UTF-8.  Space to hold the
** returned string is obtained from malloc().
*/
char *sqlite3_win32_mbcs_to_utf8(const char *zFilename){
  char *zFilenameUtf8;
  WCHAR *zTmpWide;

  zTmpWide = mbcsToUnicode(zFilename);
  if( zTmpWide==0 ){
    return 0;
  }
  zFilenameUtf8 = unicodeToUtf8(zTmpWide);
  free(zTmpWide);
  return zFilenameUtf8;
}
예제 #7
0
char* lame_getenv(char const* var)
{
    char* str = 0;
    wchar_t* wvar = utf8ToUnicode(var);
    wchar_t* wstr = 0;
    if (wvar != 0) {
        wstr = _wgetenv(wvar);
        str = unicodeToUtf8(wstr);
    }
    free(wvar);
    free(wstr);
    return str;
}
예제 #8
0
파일: os_win.c 프로젝트: bazhenovc/nebula3
/*
** Create a temporary file name in zBuf.  zBuf must be big enough to
** hold at least SQLITE_TEMPNAME_SIZE characters.
*/
int sqlite3WinTempFileName(char *zBuf){
  static char zChars[] =
    "abcdefghijklmnopqrstuvwxyz"
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    "0123456789";
  int i, j;
  char zTempPath[SQLITE_TEMPNAME_SIZE];
  if( sqlite3_temp_directory ){
    strncpy(zTempPath, sqlite3_temp_directory, SQLITE_TEMPNAME_SIZE-30);
    zTempPath[SQLITE_TEMPNAME_SIZE-30] = 0;
  }else if( isNT() ){
    char *zMulti;
    WCHAR zWidePath[SQLITE_TEMPNAME_SIZE];
    GetTempPathW(SQLITE_TEMPNAME_SIZE-30, zWidePath);
    zMulti = unicodeToUtf8(zWidePath);
    if( zMulti ){
      strncpy(zTempPath, zMulti, SQLITE_TEMPNAME_SIZE-30);
      zTempPath[SQLITE_TEMPNAME_SIZE-30] = 0;
      sqliteFree(zMulti);
    }else{
      return SQLITE_NOMEM;
    }
  }else{
    char *zUtf8;
    char zMbcsPath[SQLITE_TEMPNAME_SIZE];
    GetTempPathA(SQLITE_TEMPNAME_SIZE-30, zMbcsPath);
    zUtf8 = mbcsToUtf8(zMbcsPath);
    if( zUtf8 ){
      strncpy(zTempPath, zUtf8, SQLITE_TEMPNAME_SIZE-30);
      zTempPath[SQLITE_TEMPNAME_SIZE-30] = 0;
      sqliteFree(zUtf8);
    }else{
      return SQLITE_NOMEM;
    }
  }
  for(i=strlen(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
  zTempPath[i] = 0;
  for(;;){
    sprintf(zBuf, "%s\\"TEMP_FILE_PREFIX, zTempPath);
    j = strlen(zBuf);
    sqlite3Randomness(15, &zBuf[j]);
    for(i=0; i<15; i++, j++){
      zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
    }
    zBuf[j] = 0;
    if( !sqlite3OsFileExists(zBuf) ) break;
  }
  TRACE2("TEMP FILENAME: %s\n", zBuf);
  return SQLITE_OK; 
}
예제 #9
0
int wmain(int argc, wchar_t* argv[])
{
  char **utf8_argv;
  int i, ret;

  utf8_argv = calloc(argc, sizeof(char*));
  for (i = 0; i < argc; ++i) {
    utf8_argv[i] = unicodeToUtf8(argv[i]);
  }
  ret = c_main(argc, utf8_argv);
  for (i = 0; i < argc; ++i) {
    free( utf8_argv[i] );
  }
  free( utf8_argv );
  return ret;
}
예제 #10
0
파일: DLsyn.cpp 프로젝트: DLive/npadBook
BOOL CDLsyn::getClass(LPVOID val)
{
	CString strFormData=_T("ac=getclass");
	char *tmpdata=unicodeToUtf8(strFormData.GetBuffer());
	BOOL result = m_pFile->SendRequest(m_strHeaders,(LPVOID)tmpdata,strlen(tmpdata));
	if(result == FALSE) return false;

	free(tmpdata);
	DWORD dwRet;
	m_pFile->QueryInfoStatusCode(dwRet);

	CStringA m_strHtml="";
	char szBuff[1024];
	UINT nRead;
	while ((nRead = m_pFile->Read(szBuff,1024))>0)
	{
		m_strHtml+=CStringA(szBuff,nRead);
		memset(szBuff,'\0',1024);
	}
	char *retdata=m_strHtml.GetBuffer();//UTF8ToUnicode(m_strHtml.GetBuffer());//"[{\"term_id\":\"1\",\"name\":\"\u672a\u5206\u7c7b\"},{\"term_id\":\"4\",\"name\":\"\u7f51\u7edc\u5b89\u5168\"}]";//unicodeToUtf8(m_strHtml.GetBuffer());
	Json::Reader reader; 
	//Json::Value value; 
	//reader.parse(m_strHtml.GetBuffer(), value);
	if(reader.parse(retdata,(*(Json::Value *)val)))
	{
		return TRUE;
		//std::string out = value["key1"].asString(); 
		//std::cout << out << std::endl; 
		//const Json::Value arrayObj = value["array"]; 
		//std::string abc;
		//for(int i=0; i<value.size(); i++) 
		//{ 
		//	string abc = value[i]["name"].asString(); 
		//	wstring test=UTF8ToUnicode(abc);
		//	
		//} 
	} 

	if (dwRet == HTTP_STATUS_OK)
	{
		return true;
	}
	return true;
}
예제 #11
0
int KCharset::to_utf8(const char** srcP, int* srclenP, char** dstP, int* dstlenP) const
{
	char* src = (char*)*srcP; char* dst = *dstP;
	size_t srclen = *srclenP, dstlen = *dstlenP;
#if defined(WIN32)
	unsigned int uchar = 0; char ctmp[8];
	while(src[0] && srclen > 0)
	{
		int n = this->to_uchar(src, (int)srclen, &uchar);
		if(n < 0)
		{
			*srcP = src; *srclenP = (int)srclen;
			*dstP = dst; *dstlenP = (int)dstlen;
			return -1;
		}
		int n2 = unicodeToUtf8(uchar, ctmp, sizeof(ctmp));
		if(n2 < 0)
		{
			*srcP = src; *srclenP = (int)srclen;
			*dstP = dst; *dstlenP = (int)dstlen;
			return -1;
		}
		if((int)dstlen < n2) break; memcpy(dst, ctmp, n2);
		src += n; srclen -= n; dst += n2; dstlen -= n2;
	}
	int wbytes = (int)(dst - *dstP); if(dstlen > 0) *dst = '\0';
	*srcP = src; *srclenP = (int)srclen; *dstP = dst; *dstlenP = (int)dstlen;
	return wbytes;
#else
	size_t n = iconv(m_iconv_utf8, &src, &srclen, dstP, &dstlen);
	if(n == -1)
	{
		*srcP = src;
		*srclenP = srclen;
		*dstlenP = dstlen;
		return -1;
	}
	if(dstlen > 0) (*dstP)[0] = '\0';
	*srcP = src; *srclenP = srclen; *dstlenP = dstlen;
	return (int)(*dstP - dst);
#endif
}
예제 #12
0
void CppSQLite3DB::open(const char* szFile)
{
	char *pPath;   
	WCHAR *wcPath;   
	wcPath = mbcsToUnicode(szFile);   
	pPath = unicodeToUtf8(wcPath);  

	int nRet = sqlite3_open(pPath, &mpDB);
	
	free(wcPath);
	free(pPath);

	if (nRet != SQLITE_OK)
	{
		const char* szError = sqlite3_errmsg(mpDB);
		throw CppSQLite3Exception(nRet, (char*)szError, DONT_DELETE_MSG);
	}

	setBusyTimeout(mnBusyTimeoutMs);
}
예제 #13
0
  std::string Path::getExecutablePath()
  {

    std::string epath = "UnknownExecutablePath";
#ifndef NTA_PLATFORM_win32
    char *buf = new char[1000];
    UInt32 bufsize = 1000;
    // sets bufsize to actual length. 
#if defined(NTA_PLATFORM_darwin86) || defined(NTA_PLATFORM_darwin64)
    _NSGetExecutablePath(buf, &bufsize);
    if (bufsize < 1000)
      buf[bufsize] = '\0';
  #else
    int count = readlink("/proc/self/exe", buf, bufsize);
    if (count < 0)
      NTA_THROW << "Unable to read /proc/self/exe to get executable name";
    if (count < 1000)
      buf[count] = '\0';
  #endif

    // make sure it's null-terminated
    buf[999] = '\0';
    epath = buf;
    delete[] buf;
#else
    // windows
    wchar_t *buf = new wchar_t[1000];
    GetModuleFileName(NULL, buf, 1000);
    // null-terminated string guaranteed unless length > 999
    buf[999] = '\0';
    std::wstring wpath(buf);
    delete[] buf;
    epath = unicodeToUtf8(wpath);
#endif

    return epath;
  }
예제 #14
0
파일: DLsyn.cpp 프로젝트: DLive/npadBook
bool CDLsyn::upFileToLoc(CStringArray &data){
	CConndb db;
	CString gsql;
	CString key;
	for(int j=0;j<data.GetCount();j++){
		key+=data.GetAt(j);
		key+=_T(",");
	}
	key.Delete(key.GetLength()-1,1);
	gsql.Format(_T("select uniquetag from articles where id IN(%s)"),key);
	db.search(gsql);
	if(db.m_query->eof())
	{
		return false;
	}
	int i=0;
	CString uniquetag,uniquetags;
	_variant_t var;
	while(!db.m_query->eof())
	{
		var=db.m_query->getStringField(_T("uniquetag"));
		if(var.vt!=VT_NULL)
			uniquetag=(LPCSTR)_bstr_t(var);
		uniquetags+=_T("'");
		uniquetags+=uniquetag;
		uniquetags+=_T("',");
		db.m_query->nextRow();
	}
	uniquetags.Delete(uniquetags.GetLength()-1,1);
	CString strFormData=_T("ac=upsome&uniques=");
	strFormData+=uniquetags;
	char *tmpdata=unicodeToUtf8(strFormData.GetBuffer());
	BOOL result = m_pFile->SendRequest(m_strHeaders,(LPVOID)tmpdata,strlen(tmpdata));
	if(result == FALSE) return false;
	
	free(tmpdata);
	DWORD dwRet;
	m_pFile->QueryInfoStatusCode(dwRet);
	//返回错误没处理! 哈哈
	CStringA m_strHtml="";
	char szBuff[1024];
	UINT nRead;
	while ((nRead = m_pFile->Read(szBuff,1024))>0)
	{
		m_strHtml+=CStringA(szBuff,nRead);
		memset(szBuff,'\0',1024);
	}
	char *retdata=m_strHtml.GetBuffer();//UTF8ToUnicode(m_strHtml.GetBuffer());//"[{\"term_id\":\"1\",\"name\":\"\u672a\u5206\u7c7b\"},{\"term_id\":\"4\",\"name\":\"\u7f51\u7edc\u5b89\u5168\"}]";//unicodeToUtf8(m_strHtml.GetBuffer());
	Json::Reader reader; 
	Json::Value value; 
	//reader.parse(m_strHtml.GetBuffer(), value);
	if(reader.parse(retdata, value)) 
	{ 
		
		CString sql;
		std::string tmpvalue;
		for(int i=0; i<value.size(); i++) 
		{
			tmpvalue = value[i]["post_title"].asString(); 
			wstring titlename=UTF8ToUnicode(tmpvalue);
			tmpvalue = value[i]["post_content"].asString(); 
			CString contenttext=UTF8ToUnicode(tmpvalue).c_str();
			//tmpvalue = value[i]["name"].asString(); 
			//wstring rclassid=UTF8ToUnicode(tmpvalue);
			//tmpvalue = value[i]["name"].asString(); 
			//wstring data=UTF8ToUnicode(tmpvalue);
			tmpvalue = value[i]["uniquetag"].asString(); 
			wstring uniquetag=UTF8ToUnicode(tmpvalue);
			tmpvalue = value[i]["post_date"].asString(); 
			wstring post_date=UTF8ToUnicode(tmpvalue);
			//tmpvalue = value[i]["name"].asString(); 
			//wstring artype=UTF8ToUnicode(tmpvalue);
			//tmpvalue = value[i]["name"].asString(); 
			//wstring m_keyword=UTF8ToUnicode(tmpvalue);
			contenttext.Replace(_T("'"),_T("''"));

			sql.Format(_T("update articles set title='%s',content='%s',addtime='%s' where uniquetag=%s"),
				titlename.c_str(),contenttext.GetBuffer(),post_date.c_str(),uniquetag.c_str());
			db.excuteSql(sql);
		} 
	} 

	if (dwRet == HTTP_STATUS_OK)
	{
		return true;
	}
	return true;
}
예제 #15
0
파일: DLsyn.cpp 프로젝트: DLive/npadBook
BOOL CDLsyn::upClassFileToLocal(CString cid){
	CConndb db;
	CString gsql;
	gsql.Format(_T("select distancecid from class where id=%s"),cid);
	db.search(gsql);
	if(db.m_query->eof())
		return false;
	int i=0;
	_variant_t var;
	CString rid;
	while(!db.m_query->eof())
	{
		var=db.m_query->getStringField(_T("distancecid"));
		if(var.vt!=VT_NULL)
			rid=(LPCSTR)_bstr_t(var);
		db.m_query->nextRow();
	}
	CString strFormData=_T("ac=upclasstoloc&cid=");
	strFormData+=rid;
	char *tmpdata=unicodeToUtf8(strFormData.GetBuffer());
	BOOL result = m_pFile->SendRequest(m_strHeaders,(LPVOID)tmpdata,strlen(tmpdata));
	if(result == FALSE) return false;
	free(tmpdata);
	DWORD dwRet;
	m_pFile->QueryInfoStatusCode(dwRet);
	//返回错误没处理! 哈哈
	CStringA m_strHtml="";
	char szBuff[1024];
	UINT nRead;
	while ((nRead = m_pFile->Read(szBuff,1024))>0)
	{
		m_strHtml+=CStringA(szBuff,nRead);
		memset(szBuff,'\0',1024);
	}
	char *retdata=m_strHtml.GetBuffer();//UTF8ToUnicode(m_strHtml.GetBuffer());//"[{\"term_id\":\"1\",\"name\":\"\u672a\u5206\u7c7b\"},{\"term_id\":\"4\",\"name\":\"\u7f51\u7edc\u5b89\u5168\"}]";//unicodeToUtf8(m_strHtml.GetBuffer());
	Json::Reader reader; 
	Json::Value value; 
	//reader.parse(m_strHtml.GetBuffer(), value);
	if(reader.parse(retdata, value)) 
	{ 
		CString sql;
		std::string tmpvalue;
		for(int i=0; i<value.size(); i++) 
		{
			tmpvalue = value[i]["post_title"].asString(); 
			wstring titlename=UTF8ToUnicode(tmpvalue);
			tmpvalue = value[i]["post_content"].asString(); 
			CString contenttext=UTF8ToUnicode(tmpvalue).c_str();
			//tmpvalue = value[i]["name"].asString(); 
			//wstring rclassid=UTF8ToUnicode(tmpvalue);
			//tmpvalue = value[i]["name"].asString(); 
			//wstring data=UTF8ToUnicode(tmpvalue);
			tmpvalue = value[i]["uniquetag"].asString(); 
			wstring uniquetag=UTF8ToUnicode(tmpvalue);
			tmpvalue = value[i]["post_date"].asString(); 
			wstring post_date=UTF8ToUnicode(tmpvalue);
			//tmpvalue = value[i]["name"].asString(); 
			//wstring artype=UTF8ToUnicode(tmpvalue);
			//tmpvalue = value[i]["name"].asString(); 
			//wstring m_keyword=UTF8ToUnicode(tmpvalue);
			contenttext.Replace(_T("'"),_T("''"));
			if(uniquetag.empty()){
				SYSTEMTIME sysTime;
				GetLocalTime(&sysTime);
				CTime m_tTime(sysTime);
				time_t unixTime = m_tTime.GetTime();
				CString utag;
				utag.Format(_T("%d"),unixTime);
				sql.Format(_T("insert into articles (title,content,addtime,classid,artitletype,uniquetag) values ('%s','%s','%s','%s','txt','%s')"),
					titlename.c_str(),contenttext.GetBuffer(),post_date.c_str(),cid,utag);
				//db.excuteSql(sql);
				db.insert(sql);
			}else{
				sql.Format(_T("update articles set title='%s',content='%s',addtime='%s' where uniquetag=%s"),
					titlename.c_str(),contenttext.GetBuffer(),post_date.c_str(),uniquetag.c_str());
				db.excuteSql(sql);
			}
			
		} 
	} 

	if (dwRet == HTTP_STATUS_OK)
	{
		return true;
	}
	return true;
}