Example #1
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;
}
CString OptUtf8ToStr(const CStringA& rastr)
{
	CStringW wstr;
	int iMaxWideStrLen = rastr.GetLength();
	LPWSTR pwsz = wstr.GetBuffer(iMaxWideStrLen);
	int iWideChars = utf8towc(rastr, rastr.GetLength(), pwsz, iMaxWideStrLen);
	if (iWideChars <= 0)
	{
		// invalid UTF8 string...
		wstr.ReleaseBuffer(0);
		wstr = rastr;				// convert with local codepage
	}
	else
		wstr.ReleaseBuffer(iWideChars);
	return wstr;					// just return the string
}
CString OptUtf8ToStr(LPCSTR psz, int iLen)
{
	CStringW wstr;
	int iMaxWideStrLen = iLen;
	LPWSTR pwsz = wstr.GetBuffer(iMaxWideStrLen);
	int iWideChars = utf8towc(psz, iLen, pwsz, iMaxWideStrLen);
	if (iWideChars <= 0)
	{
		// invalid UTF8 string...
		wstr.ReleaseBuffer(0);
		wstr = psz;				// convert with local codepage
	}
	else
		wstr.ReleaseBuffer(iWideChars);
	return wstr;					// just return the string
}
Example #4
0
CStringW InformApp::GetProfileString(LPCSTR section, LPCWSTR entry, LPCWSTR defaultValue)
{
  if (theOS.IsWindows9X())
  {
    CString entryA(entry), defaultValueA(defaultValue);
    return CStringW(CWinApp::GetProfileString(section,entryA,defaultValueA));
  }

  if (m_pszRegistryKey == NULL)
    return defaultValue;
  HKEY secKey = GetSectionKey(section);
  if (secKey == NULL)
    return defaultValue;

  CStringW value;
  DWORD type, count;
  LONG result = ::RegQueryValueExW(secKey,entry,NULL,&type,NULL,&count);
  if (result == ERROR_SUCCESS)
  {
    result = ::RegQueryValueExW(secKey,entry,NULL,&type,
      (LPBYTE)value.GetBuffer(count/sizeof(WCHAR)),&count);
    value.ReleaseBuffer();
  }
  ::RegCloseKey(secKey);
  if (result == ERROR_SUCCESS)
    return value;
  return defaultValue;
}
Example #5
0
void CLogOptionsDlg::saveOptions()
{
    int nLevel = SendDlgItemMessage(IDC_CBXLEVELS,CB_GETCURSEL,0,0);
    int nSize = SendDlgItemMessage( IDC_MSGCLASSES, WM_GETTEXTLENGTH, 0, 0 );
    CStringW strClasses; 
    GetDlgItemText(IDC_MSGCLASSES, strClasses.GetBuffer(nSize), nSize+1 );
    strClasses.ReleaseBuffer();

    nSize = SendDlgItemMessage( IDC_MSGEXCLUDE, WM_GETTEXTLENGTH, 0, 0 );
    CStringW strExcludes; 
    GetDlgItemText(IDC_MSGEXCLUDE, strExcludes.GetBuffer(nSize), nSize+1 );
    strExcludes.ReleaseBuffer();

    LOGCONF().setMinSeverity(nLevel);
    LOGCONF().setEnabledCategories( CStringA(strClasses));
    LOGCONF().setDisabledCategories( CStringA(strExcludes) );
    LOGCONF().saveToFile();
}
CStringW TextFormat::UTF8ToUnicode(const CString& in)
{
  int len = ::UTF8ToUnicode(in,in.GetLength(),NULL,0);
  CStringW out;
  LPWSTR ptr = out.GetBufferSetLength(len);
  ::UTF8ToUnicode(in,in.GetLength(),ptr,len);
  out.ReleaseBuffer(len);
  return out;
}
CString NPStringToCString(NPString npstr)
{
	int nWide = MultiByteToWideChar(CP_UTF8, 0, npstr.UTF8Characters, npstr.UTF8Length + 1, NULL, 0);
	if (nWide == 0)
		return CString();
	CStringW wstr;
	MultiByteToWideChar(CP_UTF8, 0, npstr.UTF8Characters, npstr.UTF8Length + 1, wstr.GetBuffer(nWide), nWide);
	wstr.ReleaseBuffer();
	return CString(CW2T(wstr));
}
CStringW TextFormat::Latin1ToUnicode(const CString& in)
{
  CStringW text;
  int len = in.GetLength();
  LPWSTR textPtr = text.GetBufferSetLength(len);
  for (int i = 0; i < len; i++)
    textPtr[i] = (wchar_t)(unsigned char)in[i];
  text.ReleaseBuffer(len);
  return text;
}
Example #9
0
CStringW Util::String::GBKToUnicode( CStringA gbk )
{
	CStringW strUnicode;
	DWORD dwMinSize = 0;
	dwMinSize = MultiByteToWideChar(936, NULL, gbk, gbk.GetLength(),NULL, 0);
	strUnicode.GetBufferSetLength(dwMinSize);
	LPWSTR lpszStr =  strUnicode.GetBuffer();
	INT ok = MultiByteToWideChar(936, NULL, gbk, gbk.GetLength(), lpszStr, dwMinSize);
	strUnicode.ReleaseBuffer();
	return strUnicode;
}
Example #10
0
BOOL CStdioFileEx::ReadWideString(CStringW& rString)
{
   _ASSERTE(m_pStream);
   rString = L"";// empty string without deallocating
   
   if(m_bIsUnicodeText)
   {
      // If at position 0, discard byte-order mark before reading
      if(GetPosition() == 0)
      {
         wchar_t bom;
         Read(&bom, sizeof(wchar_t));
      }
      const int nMaxSize = 128;
      LPWSTR lpsz = rString.GetBuffer(nMaxSize);
      LPWSTR lpszResult;
      int nLen = 0;
      for (;;)
      {
         lpszResult = fgetws(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)lstrlenW(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) == L"\r\n")
      {
         rString.GetBufferSetLength(nLen-2);
      }
      return rString.GetLength() > 0;
   }
   else
   {
      CStringA ansiString;
      BOOL bRetval = ReadAnsiString(ansiString);
      //setlocale(LC_ALL, "chs_chn.936");//no need
      rString = ansiString;
      return bRetval;
   }
}
Example #11
0
EXTERN_C
BOOL WINAPI
RouteTheCall(
    IN HWND hWndOwner,
    IN HINSTANCE hInstance,
    IN LPCSTR lpStringArg,
    IN INT Show)
{
    CStringW path = lpStringArg;
    PathRemoveBlanksW(path.GetBuffer());
    path.ReleaseBuffer();
    path = L"\"" + path + L"\"";
    ShellExecuteW(NULL, L"open", L"explorer.exe", path.GetString(), NULL, SW_SHOWNORMAL);
    return TRUE;
}
CString TextFormat::ToXML_UTF8(const CStringW& in)
{
  // First escape any characters that will cause problems in the XML
  CStringW escText;
  int escLen = ::EscapeXML(in,in.GetLength(),NULL,0);
  LPWSTR escPtr = escText.GetBufferSetLength(escLen);
  ::EscapeXML(in,in.GetLength(),escPtr,escLen);
  escText.ReleaseBuffer(escLen);

  // Convert the escaped text to UTF-8
  CString utfText;
  int utfLen = ::AtlUnicodeToUTF8(escText,escText.GetLength(),NULL,0);
  LPSTR utfPtr = utfText.GetBufferSetLength(utfLen);
  ::AtlUnicodeToUTF8(escText,escText.GetLength(),utfPtr,utfLen);
  utfText.ReleaseBuffer(utfLen);
  return utfText;
}
Example #13
0
//Read UTF-8 format file to an unicode text buffer.
BOOL Utility::ReadU8FileToUText(LPCTSTR pszFile, CStringW& strOutText)
{
	CStringA strUTF8;
	CFile fNib;
	//Read an UTF-8 text file to pU8Buffer
	fNib.Open(pszFile, CFile::modeRead);
	int nSize = (int)fNib.GetLength();
	char *pU8Buffer = strUTF8.GetBuffer(nSize + 1);	//UTF-8 buffer
	fNib.Read(pU8Buffer, nSize);
	strUTF8.ReleaseBuffer();
	fNib.Close();

	//Convert pU8Buffer from UTF-8 to Unicode
	int count = MultiByteToWideChar(CP_UTF8, 0, strUTF8, -1 ,NULL,0);
	LPWSTR pszUnicode = strOutText.GetBuffer(count);
	MultiByteToWideChar(CP_UTF8, 0, pU8Buffer, -1, pszUnicode, count);
	strOutText.ReleaseBuffer();
	return TRUE;
}
Example #14
0
//##ModelId=474D3076034C
bool CClip_ImportExport::PlaceCF_TEXT_AND_CF_UNICODETEXT_OnClipboard(CStringA &csCF_TEXT, CStringW &csCF_UNICODETEXT)
{
	bool bRet = false;

	if(OpenClipboard(theApp.m_MainhWnd))
	{
		EmptyClipboard();

		if(csCF_TEXT.IsEmpty() == FALSE)
		{
			long lLen = csCF_TEXT.GetLength();
			HGLOBAL hGlobal = NewGlobalP(csCF_TEXT.GetBuffer(lLen), lLen+1);
			csCF_TEXT.ReleaseBuffer();
			SetClipboardData(CF_TEXT, hGlobal);

			bRet = true;
		}
		if(csCF_UNICODETEXT.IsEmpty() == FALSE)
		{
			long lLen = csCF_UNICODETEXT.GetLength() * sizeof(wchar_t);
			HGLOBAL hGlobal = NewGlobalP(csCF_UNICODETEXT.GetBuffer(lLen), lLen+1);
			csCF_UNICODETEXT.ReleaseBuffer();
			SetClipboardData(CF_UNICODETEXT, hGlobal);

			bRet = true;
		}

		CloseClipboard();
	}
	else
	{
		Log(_T("Error opening clipboard"));
	}

	return bRet;
}
Example #15
0
int CBoxScript::ParseScriptText(LPCSTR pstrText, int nCount, CStringA& strScriptText, int nIncludeFlagIndex)
{
	CStringA strTempText;
	if(nCount >= 2 && (BYTE)pstrText[0] == 0xff && (BYTE)pstrText[1] == 0xfe)
	{
/*		int _nTempCount = WideCharToMultiByte(_AtlGetConversionACP(), 0, LPWSTR(pstrText + 2), (nCount - 2) / 2, NULL, 0, NULL, NULL);
		LPSTR _pstr = strTempText.GetBuffer(_nTempCount);

		WideCharToMultiByte(_AtlGetConversionACP(), 0, LPWSTR(pstrText + 2), (nCount - 2) / 2, _pstr, _nTempCount, NULL, NULL);
		strTempText.ReleaseBuffer(_nTempCount);
*/

//发现是Unicode则检查是否已经存在CodePage,存在就转换到当前CodePage,否则转换成UTF8同时设定m_CodePage为65001
		if (m_uiCodePage == 0)
			m_uiCodePage = CP_UTF8;

		int _nTempCount = WideCharToMultiByte(m_uiCodePage, 0, LPWSTR(pstrText + 2), (nCount - 2) / 2, NULL, 0, NULL, NULL);
		LPSTR _pstr = strTempText.GetBuffer(_nTempCount);

		WideCharToMultiByte(m_uiCodePage, 0, LPWSTR(pstrText + 2), (nCount - 2) / 2, _pstr, _nTempCount, NULL, NULL);
		strTempText.ReleaseBuffer(_nTempCount);

		pstrText = strTempText;
		nCount = strTempText.GetLength();
	}
	else if(nCount >= 3 && (BYTE)pstrText[0] == 0xEF && (BYTE)pstrText[1] == 0xBB && (BYTE)pstrText[2] == 0xBF)
	{
		pstrText += 3;
		nCount -= 3;

		if (m_uiCodePage && m_uiCodePage != CP_UTF8)
		{
			CStringW strTempTextW;
			int _nTempCount = MultiByteToWideChar(CP_UTF8, 0, pstrText, nCount, NULL, 0);
			LPWSTR _pstrW = strTempTextW.GetBuffer(_nTempCount);

			MultiByteToWideChar(CP_UTF8, 0, pstrText, nCount, _pstrW, _nTempCount);
			strTempTextW.ReleaseBuffer(_nTempCount);
			
			_nTempCount = WideCharToMultiByte(m_uiCodePage, 0, strTempTextW, strTempTextW.GetLength(), NULL, 0, NULL, NULL);
			LPSTR _pstr = strTempText.GetBuffer(_nTempCount);

			WideCharToMultiByte(m_uiCodePage, 0, strTempTextW, strTempTextW.GetLength(), _pstr, _nTempCount, NULL, NULL);
			strTempText.ReleaseBuffer(_nTempCount);

			pstrText = strTempText;
			nCount = strTempText.GetLength();
		}
		else
			m_uiCodePage = CP_UTF8;
	}
	else
	{
		UINT uiCodePage = ParseScriptTextCodePage(pstrText, nCount);
		if (uiCodePage == 0)
			uiCodePage = GetACP();

		//if (m_uiCodePage == 0)
		//	m_uiCodePage = CP_UTF8;

		if (m_uiCodePage && m_uiCodePage != uiCodePage)
		{
			CStringW strTempTextW;
			int _nTempCount = MultiByteToWideChar(uiCodePage, 0, pstrText, nCount, NULL, 0);
			LPWSTR _pstrW = strTempTextW.GetBuffer(_nTempCount);

			MultiByteToWideChar(uiCodePage, 0, pstrText, nCount, _pstrW, _nTempCount);
			strTempTextW.ReleaseBuffer(_nTempCount);
			
			_nTempCount = WideCharToMultiByte(m_uiCodePage, 0, strTempTextW, strTempTextW.GetLength(), NULL, 0, NULL, NULL);
			LPSTR _pstr = strTempText.GetBuffer(_nTempCount);

			WideCharToMultiByte(m_uiCodePage, 0, strTempTextW, strTempTextW.GetLength(), _pstr, _nTempCount, NULL, NULL);
			strTempText.ReleaseBuffer(_nTempCount);

			pstrText = strTempText;
			nCount = strTempText.GetLength();
		}
		else
		{
			m_uiCodePage = uiCodePage;
		}
	}

	static struct
	{
		char *pstrName;
		int nSize;
	}CmdName[] =
	{
		{"#include", 8},
		{"#language", 9},
		{"#debug", 6},
		{"#timeout", 8},
		{"#transaction", 12},
		{"#codepage", 9}
	};
	#define CMD_COUNT (sizeof(CmdName) / sizeof(CmdName[0]))
	int i;
	LPCSTR pstrTemp, pstrTemp1;
	int nTempCount;
	int nLineCount = 1;

	while(nCount > 0 && IsBlank(pstrText[0]))
	{
		if(pstrText[0] == '\n')
			nLineCount ++;

		pstrText ++;
		nCount --;
	}

	while(nCount > 0 && pstrText[0] == '#')
	{
		for(i = 0; i < CMD_COUNT; i ++)
			if(nCount > CmdName[i].nSize &&
				!_strnicmp(pstrText, CmdName[i].pstrName, CmdName[i].nSize) &&
				IsBlankChar(pstrText[CmdName[i].nSize]))
				break;

		if(i == CMD_COUNT)
			break;

		pstrText += CmdName[i].nSize;
		nCount -= CmdName[i].nSize;

		while(nCount > 0 && IsBlankChar(pstrText[0]))
		{
			pstrText ++;
			nCount --;
		}

		if(nCount > 0 && pstrText[0] == '\"')
		{
			pstrText ++;
			nCount --;
		}

		pstrTemp = pstrText;
		nTempCount = nCount;
		while(nTempCount > 0 && !IsLineChar(pstrTemp[0]))
		{
			pstrTemp ++;
			nTempCount --;
		}

		pstrTemp1 = pstrTemp;
		while(pstrTemp1 > pstrText && IsBlankChar(pstrTemp1[0]))
			pstrTemp1 --;

		if(pstrTemp1 > pstrText && pstrTemp1[-1] == '\"')
			pstrTemp1 --;

		CStringA strValue;

		strValue.SetString(pstrText, (int)(pstrTemp1 - pstrText));

		pstrText = pstrTemp;
		nCount = nTempCount;

		switch(i)
		{
		case 0:
			strValue.MakeLower();
			if(LoadScriptFile(BOX_CA2CT(strValue), strScriptText, nLineCount))
				return 500;
			break;
		case 1:
			m_strLanguage = strValue;
			break;
		case 2:
			m_bEnableDebug = !strValue.CompareNoCase("on") || !strValue.CompareNoCase("true");
			if(!strValue.CompareNoCase("step"))
				m_bStepDebug = TRUE;
			break;
		case 3:
			m_pHost->m_nTimeout = atoi(strValue);
			break;
		case 4:
			if(!strValue.CompareNoCase("Required"))
                m_nTransaction = 3;
			else if(!strValue.CompareNoCase("Requires_New"))
				m_nTransaction = 2;
			else if(!strValue.CompareNoCase("Supported"))
				m_nTransaction = 1;
			else if(!strValue.CompareNoCase("Not_Supported"))
				m_nTransaction = 0;
			break;
		case 5:
			//(uiCodePage)
			break;
		}

		while(nCount > 0 && IsBlank(pstrText[0]))
		{
			if(pstrText[0] == '\n')
				nLineCount ++;

			pstrText ++;
			nCount --;
		}
	}

	AddLineMap(nIncludeFlagIndex, nLineCount);

	strScriptText.Append(pstrText, nCount);
	strScriptText += _T("\r\n");

	m_nScriptLine ++;

	pstrTemp = pstrText;
	nTempCount = nCount;
	while(nTempCount > 0)
	{
		if(pstrTemp[0] == '\n')
			m_nScriptLine ++;

		pstrTemp ++;
		nTempCount --;
	}

	return 0;
}
Example #16
0
CStringW CMpeg2DataParser::ConvertString(BYTE* pBuffer, size_t uLength)
{
    static const UINT16 codepages[0x20] = {
        20269,  // 00 - Default ISO/IEC 6937
        28595,  // 01 - ISO 8859-5 Cyrillic
        28596,  // 02 - ISO 8859-6 Arabic
        28597,  // 03 - ISO 8859-7 Greek
        28598,  // 04 - ISO 8859-8 Hebrew
        28599,  // 05 - ISO 8859-9 Latin 5
        28591,  // 06 - ??? - ISO/IEC 8859-10 - Latin alphabet No. 6
        28591,  // 07 - ??? - ISO/IEC 8859-11 - Latin/Thai (draft only)
        28591,  // 08 - reserved
        28603,  // 09 - ISO 8859-13 - Estonian
        28591,  // 0a - ??? - ISO/IEC 8859-14 - Latin alphabet No. 8 (Celtic)
        28605,  // 0b - ISO 8859-15 Latin 9
        28591,  // 0c - reserved
        28591,  // 0d - reserved
        28591,  // 0e - reserved
        28591,  // 0f - reserved
        0,      // 10 - See codepages10 array
        28591,  // 11 - ??? - ISO/IEC 10646 - Basic Multilingual Plane (BMP)
        28591,  // 12 - ??? - KSX1001-2004 - Korean Character Set
        20936,  // 13 - Chinese Simplified (GB2312-80)
        950,    // 14 - Chinese Traditional (Big5)
        28591,  // 15 - ??? - UTF-8 encoding of ISO/IEC 10646 - Basic Multilingual Plane (BMP)
        28591,  // 16 - reserved
        28591,  // 17 - reserved
        28591,  // 18 - reserved
        28591,  // 19 - reserved
        28591,  // 1a - reserved
        28591,  // 1b - reserved
        28591,  // 1c - reserved
        28591,  // 1d - reserved
        28591,  // 1e - reserved
        28591   // 1f - TODO!
    };

    static const UINT16 codepages10[0x10] = {
        28591,  // 00 - reserved
        28591,  // 01 - ISO 8859-1 Western European
        28592,  // 02 - ISO 8859-2 Central European
        28593,  // 03 - ISO 8859-3 Latin 3
        28594,  // 04 - ISO 8859-4 Baltic
        28595,  // 05 - ISO 8859-5 Cyrillic
        28596,  // 06 - ISO 8859-6 Arabic
        28597,  // 07 - ISO 8859-7 Greek
        28598,  // 08 - ISO 8859-8 Hebrew
        28599,  // 09 - ISO 8859-9 Turkish
        28591,  // 0a - ??? - ISO/IEC 8859-10
        28591,  // 0b - ??? - ISO/IEC 8859-11
        28591,  // 0c - ??? - ISO/IEC 8859-12
        28603,  // 0d - ISO 8859-13 Estonian
        28591,  // 0e - ??? - ISO/IEC 8859-14
        28605,  // 0f - ISO 8859-15 Latin 9

        // 0x10 to 0xFF - reserved for future use
    };

    CStringW strResult;
    if (uLength > 0) {
        UINT cp = CP_ACP;
        int nDestSize;

        if (pBuffer[0] == 0x10) {
            pBuffer++;
            uLength--;
            if (pBuffer[0] == 0x00) {
                cp = codepages10[pBuffer[1]];
            } else { // if (pBuffer[0] > 0x00)
                // reserved for future use, use default codepage
                cp = codepages[0];
            }
            pBuffer += 2;
            uLength -= 2;
        } else if (pBuffer[0] < 0x20) {
            cp = codepages[pBuffer[0]];
            pBuffer++;
            uLength--;
        } else { // No code page indication, use the default
            cp = codepages[0];
        }

        // Work around a bug in MS MultiByteToWideChar with ISO/IEC 6937 and take care of the Euro symbol special case (step 1/2)...
        CArray<size_t> euroSymbolPos;
        if (cp == 20269) {
            BYTE tmp;
            for (size_t i = 0; i < uLength - 1; i++) {
                if (pBuffer[i] >= 0xC1 && pBuffer[i] <= 0xCF && pBuffer[i] != 0xC9 && pBuffer[i] != 0xCC) {
                    // Swap the current char with the next one
                    tmp = pBuffer[i];
                    pBuffer[i] = pBuffer[i + 1];
                    pBuffer[++i] = tmp;
                } else if (pBuffer[i] == 0xA4) { // € was added as 0xA4 in the DVB spec
                    euroSymbolPos.Add(i);
                }
            }
            // Handle last symbol if it's a €
            if (pBuffer[uLength - 1] == 0xA4) {
                euroSymbolPos.Add(uLength - 1);
            }
        }

        nDestSize = MultiByteToWideChar(cp, MB_PRECOMPOSED, (LPCSTR)pBuffer, (int)uLength, nullptr, 0);
        if (nDestSize > 0) {
            LPWSTR strResultBuff = strResult.GetBuffer(nDestSize);
            MultiByteToWideChar(cp, MB_PRECOMPOSED, (LPCSTR)pBuffer, (int)uLength, strResultBuff, nDestSize);

            // Work around a bug in MS MultiByteToWideChar with ISO/IEC 6937 and take care of the Euro symbol special case (step 2/2)...
            if (cp == 20269) {
                for (size_t i = 0, len = (size_t)nDestSize; i < len; i++) {
                    switch (strResultBuff[i]) {
                        case 0x60: // grave accent
                            strResultBuff[i] = 0x0300;
                            break;
                        case 0xb4: // acute accent
                            strResultBuff[i] = 0x0301;
                            break;
                        case 0x5e: // circumflex accent
                            strResultBuff[i] = 0x0302;
                            break;
                        case 0x7e: // tilde
                            strResultBuff[i] = 0x0303;
                            break;
                        case 0xaf: // macron
                            strResultBuff[i] = 0x0304;
                            break;
                        case 0xf8f8: // dot
                            strResultBuff[i] = 0x0307;
                            break;
                    }
                }

                for (INT_PTR i = 0, len = euroSymbolPos.GetCount(); i < len; i++) {
                    strResultBuff[euroSymbolPos[i]] = _T('€');
                }
            }

            // Some strings seems to be null-terminated, we need to take that into account.
            while (nDestSize > 0 && strResultBuff[nDestSize - 1] == L'\0') {
                nDestSize--;
            }

            strResult.ReleaseBuffer(nDestSize);
        }
    }

    return strResult;
}
Example #17
0
long CBoxScript::Load(LPCTSTR pstrFile)
{
	m_error.Clear();

	m_strBasePath.Empty();
	m_arrayIncludeFlags.RemoveAll();

	m_nDiskFileCount = 0;
	m_nCacheFileCount = 0;
	m_nScriptLine = 0;

	CScriptHost* pNowScript = CScriptHost::GetCurrentScript();

	if(pNowScript != NULL)
		m_strBasePath = pNowScript->m_strScriptName;

	CBoxPath path;

	if(!m_strBasePath.IsEmpty() && pstrFile[0] != _T('\\'))
		path.Combine(m_strBasePath.Left(m_strBasePath.ReverseFind(_T('\\')) + 1), pstrFile);
	else path.Combine(pstrFile);

	InitScript();

	CStringA strScriptText;
	int iResult = LoadScriptFile(path.m_strPath, strScriptText);
	m_strBasePath.Empty();

	if(iResult != 0)
		return iResult;

	if(m_nCacheFileCount)
	{
		m_bStepDebug = FALSE;
		m_bEnableDebug = FALSE;
	}

	m_pHost->SetFileName(path.m_strPath);

	if(!m_pHost->Create(m_strLanguage, m_bEnableDebug, m_bStepDebug, m_nTransaction))
	{
		GetScriptErrorInfo();
		return 500;
	}

	m_pHost->SetScriptSite();

	if (m_uiCodePage)
	{
		CStringW strTempText;
		int _nTempCount = MultiByteToWideChar(m_uiCodePage, 0, strScriptText, strScriptText.GetLength(), NULL, 0);
		LPWSTR _pstr = strTempText.GetBuffer(_nTempCount);

		MultiByteToWideChar(m_uiCodePage, 0, strScriptText, strScriptText.GetLength(), _pstr, _nTempCount);
		strTempText.ReleaseBuffer(_nTempCount);
		
		if(m_pHost->Load(strTempText) != S_OK)
		{
			GetScriptErrorInfo();
			return 500;
		}
	}
	else
	{
		if(m_pHost->Load(BOX_CA2CT(strScriptText)) != S_OK)
		{
			GetScriptErrorInfo();
			return 500;
		}
	}

	if(AfterParse() != 0)
		return 500;

	return 0;
}