Exemplo n.º 1
0
void CCharsetConverter::utf16LEtoW(const char* strSource, CStdStringW &strDest)
{
  if (m_iconvUtf16LEtoW == (iconv_t) - 1)
    m_iconvUtf16LEtoW = iconv_open(WCHAR_CHARSET, "UTF-16LE");

  if (m_iconvUtf16LEtoW != (iconv_t) - 1)
  {
    size_t inBytes = 2;
    short* s = (short*) strSource;
    while (*s != 0)
    {
      s++;
      inBytes += 2;
    }
    size_t outBytes = (inBytes + 1)*sizeof(wchar_t);  // UTF-8 is up to 4 bytes/character  
    char *dst = (char*) strDest.GetBuffer(outBytes);
    if (iconv_const(m_iconvUtf16LEtoW, &strSource, &inBytes, &dst, &outBytes))
    { // failed :(
      strDest.ReleaseBuffer();
      strDest = strSource;
      return;
    }
    strDest.ReleaseBuffer();
  }
}
Exemplo n.º 2
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();
  }
}
Exemplo n.º 3
0
CStdStringW DocReader::ReadWideString(int iOffset, int iCharCount)
{
	CStdStringW sResult;
	ReadIntoBufferIgnoringBitsInDeletedList(iOffset, iCharCount*2, sResult.GetBuffer(iCharCount + 1), iCharCount*2 + 2);
	sResult.ReleaseBuffer();
	return sResult;
}
Exemplo n.º 4
0
	CStdStringW CFilename::MakePath()
	{
		CStdStringW res;
		_wmakepath(res.GetBuffer(MAX_PATH),
			drive.c_str(), dir.c_str(), fname.c_str(), ext.c_str());
		res.ReleaseBuffer();
		return res;
	}
Exemplo n.º 5
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();
  }
}
Exemplo n.º 6
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)
  {
    size_t inBytes  = (strSource.length() + 1);
    size_t outBytes = (strSource.length() + 1) * sizeof(wchar_t);
    const char *src = strSource.c_str();
    char       *dst = (char*)strDest.GetBuffer(outBytes);

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

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