예제 #1
0
void CCharsetConverter::utf8ToStringCharset(const CStdStringA& strSource, CStdStringA& strDest)
{
  if (m_iconvUtf8ToStringCharset == (iconv_t) - 1)
  {
    CStdString strCharset=g_langInfo.GetGuiCharSet();
    m_iconvUtf8ToStringCharset = iconv_open(strCharset.c_str(), UTF8_SOURCE);
  }

  if (m_iconvUtf8ToStringCharset != (iconv_t) - 1)
  {
    const char* src = strSource.c_str();
    size_t inBytes = strSource.length() + 1;

    char *dst = strDest.GetBuffer(inBytes);
    size_t outBytes = inBytes - 1;

    if (iconv_const(m_iconvUtf8ToStringCharset, &src, &inBytes, &dst, &outBytes) == (size_t) -1)
    {
      strDest.ReleaseBuffer();
      // For some reason it failed (maybe wrong charset?). Nothing to do but
      // return the original..
      strDest = strSource;
    }
    strDest.ReleaseBuffer();
  }
}
예제 #2
0
void CCharsetConverter::utf16BEtoUTF8(const CStdStringW& strSource, CStdStringA &strDest)
{
  if (m_iconvUtf16BEtoUtf8 == (iconv_t) - 1)
    m_iconvUtf16BEtoUtf8 = iconv_open("UTF-8", "UTF-16BE");

  if (m_iconvUtf16BEtoUtf8 != (iconv_t) - 1)
  {
    size_t inBytes  = (strSource.length() + 1) * sizeof(wchar_t);
    size_t outBytes = (strSource.length() + 1) * 4;
    const char *src = (const char*) strSource.c_str();
    char       *dst = strDest.GetBuffer(outBytes);

    if (iconv_const(m_iconvUtf16BEtoUtf8, &src, &inBytes, &dst, &outBytes))
    {
      CLog::Log(LOGERROR, "%s failed", __FUNCTION__);
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }

    if (iconv(m_iconvUtf16BEtoUtf8, NULL, NULL, &dst, &outBytes))
    {
      CLog::Log(LOGERROR, "%s failed cleanup", __FUNCTION__);
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }
    strDest.ReleaseBuffer();
  }
}
예제 #3
0
void CCharsetConverter::subtitleCharsetToW(const CStdStringA& strSource, CStdStringW& strDest)
{
  CStdStringA strFlipped;

  // No need to flip hebrew/arabic as mplayer does the flipping

  if (m_iconvSubtitleCharsetToW == (iconv_t) - 1)
  {
    CStdString strCharset=g_langInfo.GetSubtitleCharSet();
    m_iconvSubtitleCharsetToW = iconv_open(WCHAR_CHARSET, strCharset.c_str());
  }

  if (m_iconvSubtitleCharsetToW != (iconv_t) - 1)
  {
    const char* src = strSource.c_str();
    size_t inBytes = strSource.length() + 1;
    char *dst = (char*)strDest.GetBuffer(inBytes * sizeof(wchar_t));
    size_t outBytes = inBytes * sizeof(wchar_t);

    if (iconv_const(m_iconvSubtitleCharsetToW, &src, &inBytes, &dst, &outBytes))
    {
      strDest.ReleaseBuffer();
      // For some reason it failed (maybe wrong charset?). Nothing to do but
      // return the original..
      strDest = strSource;
    }
    strDest.ReleaseBuffer();
  }
}
예제 #4
0
CStdString DocReader::ReadASCIIString(int iOffset, int iCharCount)
{
	CStdStringA sResult;
	ReadIntoBufferIgnoringBitsInDeletedList(iOffset, iCharCount, sResult.GetBuffer(iCharCount + 1), iCharCount+2);
	sResult.ReleaseBuffer();
	return sResult;
}
예제 #5
0
bool DotNetRegistrar::RegisterItem()
{
	CStdString sFileName;
	CStdString sParams;
	CreateRegisterCommandString(sFileName, sParams);

	if(_taccess(GetNameOfErrorLogFile().c_str(), 00) == 0)
		_tremove(GetNameOfErrorLogFile().c_str());

    CFilePath exePath( GetDotNetRegistrationFileName() ); //this was retrieved in CreateRegisterCommandString, but we want one without enclosing quotes
    CStdStringA sCommand ;
    sCommand.Format("\"%s\" %s", CStdStringA(exePath.GetFileName()), CStdStringA( sParams ) );

    //Batch file will contain just the executable name, not path. Working directory is assumed 
    //by ExecuteAndWait to be the execution directory.

    CStdString sBatchFile = GetExecutionPath() + _T("\\Register.bat");
    _tremove( sBatchFile.c_str());
    CreateTextFile( sBatchFile, sCommand );
    ASSERT( CGeneral::FileExists( sBatchFile ));
	ExecuteAndWait(sBatchFile, _T(""));
    _tremove( sBatchFile.c_str());
    
	if (ErrorOccurred())
	{
		std::vector<CStdString> Errors = GetErrorsFromFile();
		std::vector<CStdString>::iterator it;
		for(it = Errors.begin(); it != Errors.end(); ++it)
		{
			ReportEvent(EVENTLOG_ERROR_TYPE, 0, *it);
		}
		return false;
	}
	return true;
}
예제 #6
0
void CCharsetConverter::utf32ToStringCharset(const unsigned long* strSource, CStdStringA& strDest)
{
  if (m_iconvUtf32ToStringCharset == (iconv_t) - 1)
  {
    CStdString strCharset=g_langInfo.GetGuiCharSet();
    m_iconvUtf32ToStringCharset = iconv_open(strCharset.c_str(), "UTF-32LE");
  }

  if (m_iconvUtf32ToStringCharset != (iconv_t) - 1)
  {
    const unsigned long* ptr=strSource;
    while (*ptr) ptr++;
    const char* src = (const char*) strSource;
    size_t inBytes = (ptr-strSource+1)*4;

    char *dst = strDest.GetBuffer(inBytes);
    size_t outBytes = inBytes;

    if (iconv_const(m_iconvUtf32ToStringCharset, &src, &inBytes, &dst, &outBytes))
    {
      strDest.ReleaseBuffer();
      // For some reason it failed (maybe wrong charset?). Nothing to do but
      // return the original..
      strDest = (const char *)strSource;
    }
    strDest.ReleaseBuffer();
  }
}
예제 #7
0
void CCharsetConverter::stringCharsetToUtf8(const CStdStringA& strSource, CStdStringA& strDest)
{
  if (m_iconvStringCharsetToUtf8 == (iconv_t) - 1)
  {
    CStdString strCharset=g_langInfo.GetGuiCharSet();
    m_iconvStringCharsetToUtf8 = iconv_open("UTF-8", strCharset.c_str());
  }

  if (m_iconvStringCharsetToUtf8 != (iconv_t) - 1)
  {
    const char* src = strSource.c_str();
    size_t inBytes = strSource.length() + 1;

    size_t outBytes = (inBytes * 4) + 1;
    char *dst = strDest.GetBuffer(outBytes);

    if (iconv_const(m_iconvStringCharsetToUtf8, &src, &inBytes, &dst, &outBytes) == (size_t) -1)
    {
      strDest.ReleaseBuffer();
      // For some reason it failed (maybe wrong charset?). Nothing to do but
      // return the original..
      strDest = strSource;
      return ;
    }

    strDest.ReleaseBuffer();
  }
}
예제 #8
0
void DocXDocumentStore::GetDocumentTexts(const CStdString& sFileName, std::vector<std::string>& vDocumentTexts) const
{
	vDocumentTexts.clear();

	CZipArchive zipArchive;
	zipArchive.Open(sFileName, CZipArchive::zipOpenReadOnly);
	if( !zipArchive.IsClosed() )
	{
		CZipWordArray ar;
		zipArchive.FindMatches( L"word\\\\*.xml", ar );
		for( int uIndex = 0; uIndex < ar.GetSize(); uIndex++ )
		{
			CZipFileHeader fhInfo;
			if( zipArchive.GetFileInfo( fhInfo, ar[uIndex] ) )
			{
				const CZipString fileName( fhInfo.GetFileName() );
				if( fileName.find_first_of( '\\' ) == fileName.find_last_of( '\\' ) )
				{
					C2007DocFile mf;
					zipArchive.ExtractFile( ar[uIndex], mf );			
					const CStdStringA sDocText = mf.GetWTInnerText();
					if( sDocText.size() > 0 )
						vDocumentTexts.push_back( sDocText );
				}
			}
		}
		zipArchive.Flush();
		zipArchive.Close();
	}
}
void ActivationContextLoader::LoadDll()
{
    // Get a handle to the DLL module.
 
	CPath dllPath;
	dllPath.Combine(GetModulePath(), WS_ACTIVATIONCONTEXTLOADER_DLL);
	
    m_hinstLib = LoadLibrary(dllPath); 
 
    // If the handle is valid, try to get the function address.
 
    if (m_hinstLib != NULL) 
    { 
		m_funcLAC = (LAC) GetProcAddress(m_hinstLib, WS_ACLOADFUNC); 
													 
		m_funcULAC = (ULAC) GetProcAddress(m_hinstLib, WS_ACUNLOADFUNC);

		m_funcIAAFM = (IAAFM) GetProcAddress(m_hinstLib, WS_ACALREADYACTIVEFUNC);
    } 
	else
	{
		CStdStringA msg;
		msg.Format("LoadLibrary on '%s'failed. Error code: %d.", WS_ACTIVATIONCONTEXTLOADER_DLL_A, GetLastError());
		throw std::exception(msg);
	}
}
예제 #10
0
CStdStringA RomanIndexFormatter::FormatThousands(int iValue)
{
	int iThousands = iValue / 1000;
	CStdStringA sResult;
	sResult.resize(iThousands, 'M');
	return sResult;
}
예제 #11
0
void CCharsetConverter::utf16LEtoUTF8(const void *strSource,
                                      CStdStringA &strDest)
{
  if (m_iconvUtf16LEtoUtf8 == (iconv_t) - 1)
    m_iconvUtf16LEtoUtf8 = iconv_open("UTF-8", "UTF-16LE");

  if (m_iconvUtf16LEtoUtf8 != (iconv_t) - 1)
  {
    size_t inBytes = 2;
    uint16_t *s = (uint16_t *)strSource;
    while (*s != 0)
    { 
      s++;
      inBytes += 2;
    }
    // UTF-8 is up to 4 bytes/character, or up to twice the length of UTF-16
    size_t outBytes = inBytes * 2;

    const char *src = (const char *)strSource;
    char *dst = strDest.GetBuffer(outBytes);
    if (iconv_const(m_iconvUtf16LEtoUtf8, &src, &inBytes, &dst, &outBytes) ==
        (size_t)-1)
    { // failed :(
      strDest.clear();
      strDest.ReleaseBuffer();
      return;
    }
    strDest.ReleaseBuffer();
  }
}
예제 #12
0
bool NetworkDriveHelper::ShareTestFolder()
{
	NET_API_STATUS	res;
	DWORD			parm_err = 0;
	wchar_t			netName[MAX_PATH];
	wchar_t			path[MAX_PATH];
	wchar_t			remarks[MAX_PATH];

	CStdStringA		sTestPath = ResolveSubstDriveInPath(GET_TEST_TEMP_PATH(_T("")));
	if (sTestPath.Right(1) == "\\")
		sTestPath	= sTestPath.Left( sTestPath.length() -1 );	// Remove last backslash.

	mbstowcs( netName, TESTSHARE, MAX_PATH );
	mbstowcs( path,    sTestPath, MAX_PATH );
	mbstowcs( remarks, "Workshare Local File Store testing share", MAX_PATH );

	SHARE_INFO_2	p;
	memset(&p, 0, sizeof(SHARE_INFO_2));
	p.shi2_netname		= netName;    
	p.shi2_type			= STYPE_DISKTREE;
	p.shi2_remark		= NULL;
	p.shi2_permissions	= 0;    
	p.shi2_max_uses		= -1;
	p.shi2_current_uses = 0;    
	p.shi2_path			= path;
	p.shi2_passwd		= NULL;

	res = NetShareAdd(NULL, 2, (LPBYTE) &p, &parm_err);

	if (res == NERR_DuplicateShare)	// Already shared.
		return true;

	ASSERT(res != NERR_UnknownDevDir);
	return res == 0;
}
예제 #13
0
CStdStringW RomanIndexFormatter::Render(int iValue)
{
	CStdStringA sResult = FormatThousands(iValue) + FormatDigit(iValue %1000 / 100, "MDC") + FormatDigit(iValue %100 / 10, "CLX") + FormatDigit(iValue%10, "XVI");
	if (m_bLowerCase)
		sResult.ToLower();

	return sResult;
}
예제 #14
0
CStdStringA localWideToUtf(LPCWSTR wstr)
{
  if (wstr == NULL)
    return "";
  int bufSize = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
  CStdStringA strA ("", bufSize);
  if ( bufSize == 0 || WideCharToMultiByte(CP_UTF8, 0, wstr, -1, strA.GetBuf(bufSize), bufSize, NULL, NULL) != bufSize )
    strA.clear();
  strA.RelBuf();
  return strA;
}
예제 #15
0
void TestSnapshotSaver::TestSaveBufferToTempFile()
{
    const CStdString sDestFileName( SnapshotSaver::SaveBufferToTempFile( _T("This is silly data") ) );
    CStdStringA sRtfBuffer;
    std::ifstream file( sDestFileName );
    file.get( sRtfBuffer.GetBuffer(100), 100 );
    sRtfBuffer.ReleaseBuffer();
    ::DeleteFile( sDestFileName.c_str() );

    assertTest( sRtfBuffer = _T("This is silly data") );
}
예제 #16
0
void ActivationContextLoader::UnloadDll()
{
	if(m_hinstLib)
	{
		if (FALSE == FreeLibrary(m_hinstLib))
		{
			CStdStringA msg;
			msg.Format("FreeLibrary on '%s'failed. Error code: %d.", WS_ACTIVATIONCONTEXTLOADER_DLL_A, GetLastError());
			throw std::exception(msg);
		}
	}
}
예제 #17
0
void CRTFTablePostProcessor::DebugDumpStructureToFile(int iSuffix, LPCSTR szContext)
{
	if (m_prtfFile->GetModality() == 0) 
		return;
	CStdStringA csFileName;
	csFileName.Format("c:\\BHTableDump%d%c.txt",iSuffix, m_prtfFile->GetModality() == 1 ? 'O' : 'M');
	if(FILE *fp = fopen(csFileName, "w"))
	{
		fprintf( fp, "%s - Starting at %d\n", szContext, m_iStart);
		m_pParentCollection->Dump(fp, true);
		fclose(fp);
	}
}
예제 #18
0
void ActivationContextLoader::LoadAC()
{
	if (m_funcLAC)
	{
		DWORD dwRet = (m_funcLAC)(m_sManifest, &m_cookie);
		if (ERROR_SUCCESS != dwRet)
		{
			CStdStringA msg;
			msg.Format("Loading Activation Context with manifest '%s' failed. Error code: %d", m_sManifest.c_str(), dwRet);
			throw std::exception(msg);
		}
	}
}
예제 #19
0
void ActivationContextLoader::UnloadAC()
{
	if (m_funcULAC && m_cookie != 0)
	{
		DWORD dwRet = (m_funcULAC)(m_cookie); 
		if (ERROR_SUCCESS != dwRet)
		{
			CStdStringA msg;
			msg.Format("Unloading Activation Context failed. Error code: %d", dwRet);
			throw std::exception(msg);
		}
	}
}
예제 #20
0
void CCharsetConverter::ucs2CharsetToStringCharset(const CStdStringW& strSource, CStdStringA& strDest, bool swap)
{
  if (m_iconvUcs2CharsetToStringCharset == (iconv_t) - 1)
  {
    CStdString strCharset=g_langInfo.GetGuiCharSet();
    m_iconvUcs2CharsetToStringCharset = iconv_open(strCharset.c_str(), "UTF-16LE");
  }

  if (m_iconvUcs2CharsetToStringCharset != (iconv_t) - 1)
  {
    CStdStringW strCopy = strSource;
    size_t inBytes  = (strCopy.length() + 1) * sizeof(wchar_t);
    size_t outBytes = (strCopy.length() + 1) * 4;
    const char *src = (const char*)strCopy.c_str();
    char       *dst = strDest.GetBuffer(inBytes);

    if (swap)
    {
      char* s = (char*) src;

      while (*s || *(s + 1))
      {
        char c = *s;
        *s = *(s + 1);
        *(s + 1) = c;

        s++;
        s++;
      }
    }

    if (iconv_const(m_iconvUcs2CharsetToStringCharset, &src, &inBytes, &dst, &outBytes) == (size_t)-1)
    {
      CLog::Log(LOGERROR, "%s failed", __FUNCTION__);
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }

    if (iconv_const(m_iconvUcs2CharsetToStringCharset, NULL, NULL, &dst, &outBytes) == (size_t)-1)
    {
      CLog::Log(LOGERROR, "%s failed cleanup", __FUNCTION__);
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }

    strDest.ReleaseBuffer();
  }
}
CStdString CWordBinaryMetadataDiscoveryWorker::ConvertPropertyFromUTF8(CStdStringA sData)
{
	CStdString sOut;
	int iIncrement = 0;
	int iPos = 0;
	unsigned char* p = (unsigned char *)sData.GetBuffer(-1);

	while (iPos < sData.GetLength())
	{	// *p z y x w v u
		if (*p <= 127)	// 1 byte
		{
			sOut += *p;
			iIncrement = 1;;
		}
		else if (*p >= 192 && *p <= 223)	// 2 bytes
		{	// (z-192)*64 + (y-128)
			sOut += (64 * (*p - 192)) + *(p+1) - 128;
			iIncrement = 2;
		}
		else if (*p >= 224 && *p <= 239)	// 3 bytes
		{	// (z-224)*4096 + (y-128)*64 + (x-128)
			sOut += (4096 * (*p - 224)) + (64 * (*(p+1) - 128)) + *(p+2) - 128;
			iIncrement = 3;
		}
		//else if (*p >= 240 && *p <= 247)	// 4 bytes
		//{	// (z-240)*262144 + (y-128)*4096 + (x-128)*64 + (w-128)
		//	sOut += (262144 * (*p - 240)) + (4096 * (*(p+1) - 128)) + (64 * (*(p+2) - 128)) + *(p+3) - 128;
		//	iIncrement = 4;
		//}
		//else if (*p >= 248 && *p <= 251)	// 5 bytes
		//{	// (z-248)*16777216 + (y-128)*262144 + (x-128)*4096 + (w-128)*64 + (v-128)
		//	sOut += (16777216 * (*p - 248)) + (262144 * (*(p+1) - 128)) + (4096 * (*(p+2) - 128)) + (64 * (*(p+3) - 128)) + *(p+4) - 128;
		//	iIncrement = 5;
		//}
		//else if (*p >= 252 && *p <= 253)	// 6 bytes
		//{	// (z-252)*1073741824 + (y-128)*16777216 + (x-128)*262144 + (w-128)*4096 + (v-128)*64 + (u-128)
		//	sOut += (1073741824 * (*p - 252)) + (16777216 * (*(p+1) - 128)) + (262144 * (*(p+2) - 128)) + (4096 * (*(p+3) - 128)) + (64 * (*(p+4) - 128)) + *(p+5) - 128;
		//	iIncrement = 6;
		//}
		else
		{
			// error - leave as was
			return sData;
		}
		p += iIncrement;
		iPos += iIncrement;
	}
	return sOut;
}
예제 #22
0
bool DotNetRegistrar::UnregisterItem()
{
	CStdString sFileName;
	CStdString sParams;
	CreateUnregisterCommandString(sFileName, sParams);

    CFilePath exePath( GetDotNetRegistrationFileName() ); //this was retrieved in CreateRegisterCommandString, but we want one without enclosing quotes
    CStdStringA sCommand ;
    sCommand.Format("\"%s\" %s", CStdStringA(exePath.GetFileName()), CStdStringA( sParams ) );

    CStdString sBatchFile = GetExecutionPath() + _T("\\Register.bat");
    _tremove( sBatchFile.c_str());
    CreateTextFile( sBatchFile, sCommand );
    ASSERT( CGeneral::FileExists( sBatchFile ));
	
    bool res = true;
    try
    {
	    CStdString cmdLine = sBatchFile;
	    STARTUPINFO si;
	    PROCESS_INFORMATION pi;
	    ZeroMemory(&si, sizeof(si));
	    si.cb = sizeof(si);
	    si.wShowWindow = SW_HIDE;
	    ZeroMemory(&pi, sizeof(pi));
	    if ( !CreateProcess( NULL, cmdLine.GetBuffer(MAX_PATH), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi) )
	    {
		    cmdLine.ReleaseBuffer();
		    res = false;

	    }
	    cmdLine.ReleaseBuffer();	
	    if ( res )
	    {
		    // Wait around for 15 seconds 
		    WaitForSingleObject(pi.hProcess, 15000);
		    CloseHandle(pi.hProcess);
		    CloseHandle(pi.hThread);
	    }
    }
    catch(...)
    {
        _tremove( sBatchFile.c_str());
        throw;
    }

    _tremove( sBatchFile.c_str());
	return res;
}
예제 #23
0
CStdStringA TerDateTimeFormatter::GetFormattedTime(SYSTEMTIME& st, const CStdStringA& sFormatPicture)
{
	CStdString sDate;
	int ir = GetTimeFormat(m_locale, 0, &st, sFormatPicture.c_str(), sDate.GetBuffer(MAX_PATH), MAX_PATH);
	sDate.ReleaseBuffer();

	return sDate;
}
예제 #24
0
// The bVisualBiDiFlip forces a flip of characters for hebrew/arabic languages, only set to false if the flipping
// of the string is already made or the string is not displayed in the GUI
void CCharsetConverter::utf8ToW(const CStdStringA& utf8String, CStdStringW &wString, bool bVisualBiDiFlip/*=true*/)
{
  CStdStringA strFlipped;
  const char* src;
  size_t inBytes;
  
  // Try to flip hebrew/arabic characters, if any
  if (bVisualBiDiFlip)
  {
    logicalToVisualBiDi(utf8String, strFlipped, FRIBIDI_CHAR_SET_UTF8);
    src = strFlipped.c_str();
    inBytes = strFlipped.length() + 1;
  }
  else
  {
    src = utf8String.c_str();
    inBytes = utf8String.length() + 1;
  }

  if (m_iconvUtf8toW == (iconv_t) - 1)
    m_iconvUtf8toW = iconv_open(WCHAR_CHARSET, UTF8_SOURCE);

  if (m_iconvUtf8toW != (iconv_t) - 1)
  {
    size_t outBytes = inBytes * sizeof(wchar_t);
    char      * dst = (char*)wString.GetBuffer(outBytes);

    if (iconv_const(m_iconvUtf8toW, &src, &inBytes, &dst, &outBytes) == (size_t)-1)
    {
      CLog::Log(LOGERROR, "%s failed", __FUNCTION__);
      wString.ReleaseBuffer();
      wString = utf8String;
      return;
    }

    if (iconv(m_iconvUtf8toW, NULL, NULL, &dst, &outBytes) == (size_t)-1)
    {
      CLog::Log(LOGERROR, "%s failed cleanup", __FUNCTION__);
      wString.ReleaseBuffer();
      wString = utf8String;
      return;
    }
    wString.ReleaseBuffer();
  }
}
예제 #25
0
void CCharsetConverter::stringCharsetToUtf8(const CStdStringA& strSourceCharset, const CStdStringA& strSource, CStdStringA& strDest)
{
  iconv_t iconvString=iconv_open("UTF-8", strSourceCharset.c_str());

  if (iconvString != (iconv_t) - 1)
  {
    size_t inBytes  = (strSource.length() + 1);
    size_t outBytes = (strSource.length() + 1) * 4;
    const char *src = strSource.c_str();
    char       *dst = strDest.GetBuffer(outBytes);

    if (iconv_const(iconvString, &src, &inBytes, &dst, &outBytes) == (size_t) -1)
    {
      CLog::Log(LOGERROR, "%s failed", __FUNCTION__);
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }

    if (iconv(iconvString, NULL, NULL, &dst, &outBytes) == (size_t)-1)
    {
      CLog::Log(LOGERROR, "%s failed cleanup", __FUNCTION__);
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }

    strDest.ReleaseBuffer();

    iconv_close(iconvString);
  }
}
예제 #26
0
int IntelligentDocInfo::GetHashCode(CStdStringA sDocId)
{
	if (sDocId.IsEmpty())
		return 0;
	DWORD dwLargeNumber(3929);
	DWORD dwMultiple(dwLargeNumber); // Some large number
	DWORD dwHash(0);
	unsigned int iSize = sDocId.GetLength();
	{
		for(unsigned int i = 1; i <= iSize; ++i)
		{
			char c = sDocId[i-1];
			dwHash += dwMultiple * i * c;
			dwMultiple *= dwLargeNumber;
		}
	}
	dwHash ^= m_iRehashCode;
	return dwHash;
}
예제 #27
0
void CCharsetConverter::utf16LEtoUTF8(const CStdStringW& strSource, CStdStringA &strDest)
{
  if (m_iconvUtf16LEtoUtf8 == (iconv_t) - 1)
    m_iconvUtf16LEtoUtf8 = iconv_open("UTF-8", "UTF-16LE");

  if (m_iconvUtf16LEtoUtf8 != (iconv_t) - 1)
  {
    const char* src = (const char*) strSource.c_str();
    size_t inBytes = (strSource.length() + 1)*sizeof(wchar_t);
    size_t outBytes = (inBytes + 1)*sizeof(wchar_t);  // UTF-8 is up to 4 bytes/character  
    char *dst = strDest.GetBuffer(outBytes);
    if (iconv_const(m_iconvUtf16LEtoUtf8, &src, &inBytes, &dst, &outBytes))
    { // failed :(
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }
    strDest.ReleaseBuffer();
  }
}
예제 #28
0
void CCharsetConverter::ucs2CharsetToStringCharset(const CStdStringW& strSource, CStdStringA& strDest, bool swap)
{
  if (m_iconvUcs2CharsetToStringCharset == (iconv_t) - 1)
  {
    CStdString strCharset=g_langInfo.GetGuiCharSet();
    m_iconvUcs2CharsetToStringCharset = iconv_open(strCharset.c_str(), "UTF-16LE");
  }

  if (m_iconvUcs2CharsetToStringCharset != (iconv_t) - 1)
  {
    const char* src = (const char*) strSource.c_str();
    size_t inBytes = (strSource.length() + 1) * sizeof(wchar_t);

    if (swap)
    {
      char* s = (char*) src;

      while (*s || *(s + 1))
      {
        char c = *s;
        *s = *(s + 1);
        *(s + 1) = c;

        s++;
        s++;
      }
    }

    char *dst = strDest.GetBuffer(inBytes);
    size_t outBytes = inBytes;

    if (iconv_const(m_iconvUcs2CharsetToStringCharset, &src, &inBytes, &dst, &outBytes))
    {
      strDest.ReleaseBuffer();
      // For some reason it failed (maybe wrong charset?). Nothing to do but
      // return the original..
      strDest = strSource;
    }
    strDest.ReleaseBuffer();
  }
}
예제 #29
0
void CCharsetConverter::wToUTF8(const CStdStringW& strSource, CStdStringA &strDest)
{
  if (m_iconvWtoUtf8 == (iconv_t) - 1)
    m_iconvWtoUtf8 = iconv_open("UTF-8", WCHAR_CHARSET);

  if (m_iconvWtoUtf8 != (iconv_t) - 1)
  {
    const char* src = (const char*) strSource.c_str();
    size_t inBytes = (strSource.length() + 1) * sizeof(wchar_t);
    size_t outBytes = (inBytes + 1)*sizeof(wchar_t);  // some free for UTF-8 (up to 4 bytes/char)
    char *dst = strDest.GetBuffer(outBytes);
    if (iconv_const(m_iconvWtoUtf8, &src, &inBytes, &dst, &outBytes))
    { // failed :(
      CLog::Log(LOGERROR, "CCharsetConverter::wToUTF8 failed for subtitle.");
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }
    strDest.ReleaseBuffer();
  }
}
예제 #30
0
// The bVisualBiDiFlip forces a flip of characters for hebrew/arabic languages, only set to false if the flipping
// of the string is already made or the string is not displayed in the GUI
void CCharsetConverter::utf8ToW(const CStdStringA& utf8String, CStdStringW &wString, bool bVisualBiDiFlip/*=true*/)
{
  CStdStringA strFlipped;
  const char* src;
  size_t inBytes;
  
  // Try to flip hebrew/arabic characters, if any
  if (bVisualBiDiFlip)
  {
    logicalToVisualBiDi(utf8String, strFlipped, FRIBIDI_CHAR_SET_UTF8);
    src = strFlipped.c_str();
    inBytes = strFlipped.length() + 1;
  }
  else
  {
    src = utf8String.c_str();
    inBytes = utf8String.length() + 1;
  }

  if (m_iconvUtf8toW == (iconv_t) - 1)
    m_iconvUtf8toW = iconv_open(WCHAR_CHARSET, UTF8_SOURCE);

  if (m_iconvUtf8toW != (iconv_t) - 1)
  {
    char *dst = new char[inBytes * sizeof(wchar_t)];
    size_t outBytes = inBytes * sizeof(wchar_t);
    char *outdst = dst;
    if (iconv_const(m_iconvUtf8toW, &src, &inBytes, &outdst, &outBytes))
    {
      // For some reason it failed (maybe wrong charset?). Nothing to do but
      // return the original..
      wString = utf8String;
    }
    else
    {
      wString = (WCHAR *)dst;
    }
    delete[] dst;
  }
}