#define POCO_NO_UNWINDOWS 1
#include <Poco/Mutex.h>
#include "unicoder.h"
-#include "codepage.h"
#if !defined(__IMultiLanguage2_INTERFACE_DEFINED__) && !defined(__GNUC__)
#error "IMultiLanguage2 is not defined in mlang.h. Please install latest Platform SDK."
{
bool bsucceeded;
#ifdef POCO_ARCH_BIG_ENDIAN
- if (srcCodepage == CP_UCS2BE)
+ if (srcCodepage == ucr::CP_UCS2BE)
#else
- if (srcCodepage == CP_UCS2LE)
+ if (srcCodepage == ucr::CP_UCS2LE)
#endif
{
size_t srcwchars = *srcbytes / sizeof(wchar_t);
UINT srcsize;
HRESULT hr;
- hr = m_pmlang->CreateConvertCharset(autodetectType, CP_UCS2LE, MLCONVCHARF_AUTODETECT, &pcc);
+ hr = m_pmlang->CreateConvertCharset(autodetectType, ucr::CP_UCS2LE, MLCONVCHARF_AUTODETECT, &pcc);
if (FAILED(hr))
return defcodepage;
srcsize = static_cast<UINT>(size);
if (size < 2 || (data[0] != 0 && data[1] != 0))
{
codepagestotry[0] = defcodepage;
- codepagestotry[1] = CP_UTF8;
+ codepagestotry[1] = ucr::CP_UTF_8;
}
}
else
{
if (size < 2 || (data[0] != 0 && data[1] != 0))
- codepagestotry[0] = CP_UTF8;
+ codepagestotry[0] = ucr::CP_UTF_8;
}
codepage = defcodepage;
int i;
for (i = 0; i < sizeof(codepagestotry)/sizeof(codepagestotry[0]) - 1; i++)
{
if (codepagestotry[i] == 0) break;
- pcc->Initialize(codepagestotry[i], CP_UCS2LE, 0);
+ pcc->Initialize(codepagestotry[i], ucr::CP_UCS2LE, 0);
srcsize = static_cast<UINT>(size);
dstsize = static_cast<UINT>(size * sizeof(wchar_t));
SetLastError(0);
if (lezerocount > 0 || bezerocount > 0)
{
if ((lecrorlf == 0 && size < 512 || (lecrorlf > 0 && (size / lecrorlf > 1024))) && lezerocount > bezerocount)
- codepage = CP_UCS2LE;
+ codepage = ucr::CP_UCS2LE;
else if ((becrorlf == 0 && size < 512 || (becrorlf > 0 && (size / becrorlf > 1024))) && lezerocount < bezerocount)
- codepage = CP_UCS2BE;
+ codepage = ucr::CP_UCS2BE;
}
}
}
switch (m_unicoding)
{
case ucr::UCS2LE:
- m_codepage = CP_UCS2LE;
+ m_codepage = ucr::CP_UCS2LE;
m_charsize = 2;
m_data = lpByte + 2;
unicode = true;
break;
case ucr::UCS2BE:
- m_codepage = CP_UCS2BE;
+ m_codepage = ucr::CP_UCS2BE;
m_charsize = 2;
m_data = lpByte + 2;
unicode = true;
break;
case ucr::UTF8:
- m_codepage = CP_UTF8;
+ m_codepage = ucr::CP_UTF_8;
m_charsize = 1;
if (bom)
m_data = lpByte + 3;
switch (m_unicoding)
{
case ucr::UCS2LE:
- m_codepage = CP_UCS2LE;
+ m_codepage = ucr::CP_UCS2LE;
m_charsize = 2;
m_data = 2;
unicode = true;
break;
case ucr::UCS2BE:
- m_codepage = CP_UCS2BE;
+ m_codepage = ucr::CP_UCS2BE;
m_charsize = 2;
m_data = 2;
unicode = true;
break;
case ucr::UTF8:
- m_codepage = CP_UTF8;
+ m_codepage = ucr::CP_UTF_8;
if (bom)
m_data = 3;
else
m_codepage = codepage;
switch (m_codepage)
{
- case CP_UCS2LE:
+ case ucr::CP_UCS2LE:
m_unicoding = ucr::UCS2LE;
m_charsize = 2;
break;
- case CP_UCS2BE:
+ case ucr::CP_UCS2BE:
m_unicoding = ucr::UCS2BE;
m_charsize = 2;
break;
- case CP_UTF8:
+ case ucr::CP_UTF_8:
m_charsize = 1;
m_unicoding = ucr::UTF8;
break;
#include "ExConverter.h"
#include "paths.h"
#include "UniFile.h"
-#include "codepage.h"
#include "codepage_detect.h"
#include "Environment.h"
#include "TFile.h"
m_bCurrentIsFile = bNewIsFile;
if (bNewIsUnicode)
{
- m_codepage = CP_UCS2LE;
+ m_codepage = ucr::CP_UCS2LE;
m_nBomSize = 2;
}
else
int bom_bytes = ucr::writeBom(shmOut.begin(), ucr::UCS2LE);
// to UCS-2 conversion, from unicoder.cpp maketstring
bool lossy;
- textRealSize = ucr::CrossConvert(pchar, nchars, (char *)shmOut.begin()+bom_bytes, textForeseenSize-1, m_codepage, CP_UCS2LE, &lossy);
+ textRealSize = ucr::CrossConvert(pchar, nchars, (char *)shmOut.begin()+bom_bytes, textForeseenSize-1, m_codepage, ucr::CP_UCS2LE, &lossy);
}
// size may have changed
fileOut.setSize(textRealSize + bom_bytes);
{
// to UCS-2 conversion, from unicoder.cpp maketstring
bool lossy;
- textRealSize = ucr::CrossConvert(pchar, nchars, (char *)pbstrBuffer, textForeseenSize-1, m_codepage, CP_UCS2LE, &lossy);
+ textRealSize = ucr::CrossConvert(pchar, nchars, (char *)pbstrBuffer, textForeseenSize-1, m_codepage, ucr::CP_UCS2LE, &lossy);
SysFreeString(m_bstr);
m_bstr = SysAllocStringLen(tempBSTR.get(), textRealSize / sizeof(wchar_t));
if (!m_bstr)
if (pexconv)
{
size_t srcbytes2 = srcbytes;
- if (!pexconv->convert(codepage, CP_UTF8, (const unsigned char *)pszBuf+pos, &srcbytes2, (unsigned char *)obuf.begin(), &destbytes))
+ if (!pexconv->convert(codepage, ucr::CP_UTF_8, (const unsigned char *)pszBuf+pos, &srcbytes2, (unsigned char *)obuf.begin(), &destbytes))
throw "failed to convert file contents to utf-8";
}
else
{
bool lossy = false;
- destbytes = ucr::CrossConvert((const char *)pszBuf+pos, static_cast<unsigned>(srcbytes), obuf.begin(), static_cast<unsigned>(destbytes), codepage, CP_UTF8, &lossy);
+ destbytes = ucr::CrossConvert((const char *)pszBuf+pos, static_cast<unsigned>(srcbytes), obuf.begin(), static_cast<unsigned>(destbytes), codepage, ucr::CP_UTF_8, &lossy);
}
fout.write(obuf.begin(), destbytes);
pos += srcbytes;
#pragma once
#include "UnicodeString.h"
-#include "codepage.h"
#include <cstdint>
namespace ucr
void resize(size_t newSize);
};
+enum
+{
+ CP_UTF_8 = 65001,
+ CP_UCS2LE = 1200,
+ CP_UCS2BE = 1201
+};
+
/** @brief Known Unicode encodings. */
enum UNICODESET : char
{
#include "Plugins.h"
#include "paths.h"
#include "unicoder.h"
-#include "codepage.h"
#include "Environment.h"
#include "MergeApp.h"
#include "OptionsMgr.h"
#include "CompareStats.h"
#include "FolderCmp.h"
#include "FileFilterHelper.h"
-#include "codepage.h"
#include "IAbortable.h"
#include "FolderCmp.h"
#include "DirItem.h"
#include "FileTextEncoding.h"
#include "unicoder.h"
-#include "codepage.h"
FileTextEncoding::FileTextEncoding()
{
m_codepage = codepage;
switch (codepage)
{
- case CP_UTF8:
+ case ucr::CP_UTF_8:
m_unicoding = ucr::UTF8;
break;
- case CP_UCS2LE:
+ case ucr::CP_UCS2LE:
m_unicoding = ucr::UCS2LE;
break;
- case CP_UCS2BE:
+ case ucr::CP_UCS2BE:
m_unicoding = ucr::UCS2BE;
break;
default:
case ucr::NONE:
switch (m_codepage)
{
- case CP_UTF8:
- case CP_UCS2LE:
- case CP_UCS2BE:
+ case ucr::CP_UTF_8:
+ case ucr::CP_UCS2LE:
+ case ucr::CP_UCS2BE:
m_codepage = 0; // not sure what to do here
break;
}
break;
case ucr::UTF8:
- m_codepage = CP_UTF8;
+ m_codepage = ucr::CP_UTF_8;
break;
case ucr::UCS2LE:
- m_codepage = CP_UCS2LE;
+ m_codepage = ucr::CP_UCS2LE;
break;
case ucr::UCS2BE:
- m_codepage = CP_UCS2BE;
+ m_codepage = ucr::CP_UCS2BE;
break;
}
}
if (m_codepage <= 0)
return _T("");
- if (m_codepage == CP_UTF8)
+ if (m_codepage == ucr::CP_UTF_8)
{
// We detected codepage to be UTF-8, but unicoding was not set
return _T("UTF-8");
// convert string into UTF-8
ucr::buffer buf(string.length() * 2);
- if (codepage != CP_UTF8)
+ if (codepage != ucr::CP_UTF_8)
ucr::convert(ucr::NONE, codepage, reinterpret_cast<const unsigned char *>(string.c_str()),
- string.length(), ucr::UTF8, CP_UTF8, &buf);
+ string.length(), ucr::UTF8, ucr::CP_UTF_8, &buf);
unsigned i = 0;
while (i < count && retval == false)
#include <vector>
#include <memory>
-#define POCO_NO_UNWINDOWS 1
#include <Poco/RegularExpression.h>
-#include "codepage.h"
+#include "unicoder.h"
/**
* @brief Container for one filtering rule / compiled expression.
void AddRegExp(const std::string& regularExpression);
void RemoveAllFilters();
bool HasRegExps() const;
- bool Match(const std::string& string, int codepage = CP_UTF8);
+ bool Match(const std::string& string, int codepage = ucr::CP_UTF_8);
const char * GetLastMatchExpression() const;
private:
return false;
}
- file.SetCodepage(CP_UTF8);
+ file.SetCodepage(ucr::CP_UTF_8);
file.WriteString(
_T("<!DOCTYPE html>\n")
<PrecompiledHeader>NotUsing</PrecompiledHeader>\r
</ClCompile>\r
<ClCompile Include="Common\CMoveConstraint.cpp" />\r
- <ClCompile Include="codepage.cpp">\r
- <PrecompiledHeader>NotUsing</PrecompiledHeader>\r
- </ClCompile>\r
<ClCompile Include="codepage_detect.cpp">\r
<PrecompiledHeader>NotUsing</PrecompiledHeader>\r
</ClCompile>\r
<ClInclude Include="ChildFrm.h" />\r
<ClInclude Include="Common\ClipBoard.h" />\r
<ClInclude Include="Common\CMoveConstraint.h" />\r
- <ClInclude Include="codepage.h" />\r
<ClInclude Include="codepage_detect.h" />\r
<ClInclude Include="Common\ColorButton.h" />\r
<ClInclude Include="Common\ExConverter.h" />\r
<ClCompile Include="charsets.c">\r
<Filter>Source Files</Filter>\r
</ClCompile>\r
- <ClCompile Include="codepage.cpp">\r
- <Filter>Source Files</Filter>\r
- </ClCompile>\r
<ClCompile Include="codepage_detect.cpp">\r
<Filter>Source Files</Filter>\r
</ClCompile>\r
<ClInclude Include="charsets.h">\r
<Filter>Header Files</Filter>\r
</ClInclude>\r
- <ClInclude Include="codepage.h">\r
- <Filter>Header Files</Filter>\r
- </ClInclude>\r
<ClInclude Include="codepage_detect.h">\r
<Filter>Header Files</Filter>\r
</ClInclude>\r
#include "Merge7zFormatMergePluginImpl.h"
#include "7zCommon.h"
#include "PatchTool.h"
+#include "charsets.h"
#ifdef _DEBUG
#define new DEBUG_NEW
{
// we subvert the buffer's memory of the original file encoding
buf.setUnicoding(ucr::UTF8); // write as UTF-8 (for preprocessing)
- buf.setCodepage(CP_UTF8); // should not matter
+ buf.setCodepage(ucr::CP_UTF_8); // should not matter
buf.setHasBom(false);
}
else
m_diffWrapper.SetPaths(PathContext(m_tempFiles[0].GetPath(), m_tempFiles[1].GetPath(), m_tempFiles[2].GetPath()), true);
m_diffWrapper.SetCompareFiles(m_filePaths);
- m_diffWrapper.SetCodepage(bForceUTF8 ? CP_UTF8 : (m_ptBuf[0]->m_encoding.m_unicoding ? CP_UTF8 : m_ptBuf[0]->m_encoding.m_codepage));
+ m_diffWrapper.SetCodepage(bForceUTF8 ? ucr::CP_UTF_8 : (m_ptBuf[0]->m_encoding.m_unicoding ? CP_UTF8 : m_ptBuf[0]->m_encoding.m_codepage));
m_diffWrapper.SetCodepage(m_ptBuf[0]->m_encoding.m_unicoding ?
CP_UTF8 : m_ptBuf[0]->m_encoding.m_codepage);
{
if (!cp) // 0 is our signal value for invalid
return false;
- // Codepage must be actually installed on system
- // for us to be able to use it
- // We accept whatever codepages that codepage module says are installed
- return true;/*isCodepageInstalled(cp);*/ /* FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME */
+ return GetEncodingNameFromCodePage(cp) != NULL;
}
/**
return false;
}
- file.SetCodepage(CP_UTF8);
+ file.SetCodepage(ucr::CP_UTF_8);
String header =
string_format(
// CMarkdown wants octets, so we may need to transcode to UTF8.
// As transcoding strips the BOM, we must check for it in advance.
if (IsUnicode())
- m_codepage = CP_UTF8;
+ m_codepage = ucr::CP_UTF_8;
// The CMarkdown::File constructor cares about transcoding.
CMarkdown::File f(
reinterpret_cast<const TCHAR *>(m_base),
+++ /dev/null
-/////////////////////////////////////////////////////////////////////////////
-// WinMerge: an interactive diff/merge utility
-// Copyright (C) 1997-2000 Thingamahoochie Software
-// Author: Dean Grimm
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-//
-/////////////////////////////////////////////////////////////////////////////
-/**
- * @file codepage.cpp
- */
-
-#include "codepage.h"
-#include <windows.h>
-#include <map>
-#include <cassert>
-#include <tchar.h>
-
-using std::map;
-
-static void initialize();
-
-// map number to bit code
-enum { CP_SUPPORTED_FLAG=0x01, CP_INSTALLED_FLAG=0x10 };
-static map<int, int> f_codepage_status;
-
-/**
- * @brief Callback used by initializeCodepages
- */
-static BOOL CALLBACK EnumInstalledCodePagesProc(LPTSTR lpCodePageString)
-{
- int codepage = _ttol(lpCodePageString);
- if (codepage)
- {
- f_codepage_status[codepage] |= CP_INSTALLED_FLAG;
- }
- return TRUE; // continue enumeration
-}
-
-/**
- * @brief Callback used by initializeCodepages
- */
-static BOOL CALLBACK EnumSupportedCodePagesProc(LPTSTR lpCodePageString)
-{
- int codepage = _ttol(lpCodePageString);
- if (codepage)
- {
- f_codepage_status[codepage] |= CP_SUPPORTED_FLAG;
- }
- return TRUE; // continue enumeration
-}
-
-/**
- * @brief Load information about codepages into local cache
- */
-static void initialize()
-{
- EnumSystemCodePages(EnumInstalledCodePagesProc, CP_INSTALLED);
- EnumSystemCodePages(EnumSupportedCodePagesProc, CP_SUPPORTED);
-}
-
-/**
- * @brief Return true if specified codepage is installed on this system (according to EnumSystemCodePages)
- */
-bool isCodepageInstalled(int codepage)
-{
- static int f_bInitialized = false;
- if (!f_bInitialized)
- {
- initialize();
- f_bInitialized = true;
- }
-
- // the following line will insert an extra element in the map if not already present
- // but its value will be 0 which means not installed nor supported
- return (f_codepage_status[codepage] & CP_INSTALLED_FLAG) == CP_INSTALLED_FLAG;
-}
+++ /dev/null
-/**
- * @file codepage.h
- */
-#pragma once
-
-#ifndef CP_UTF8
-#define CP_UTF8 65001
-#define CP_ACP 0
-#define CP_THREAD_ACP 3
-#endif
-
-#ifndef CP_UCS2LE
-#define CP_UCS2LE 1200
-#define CP_UCS2BE 1201
-#endif
-
-bool isCodepageInstalled(int codepage);
#include <memory>
#include "unicoder.h"
#include "ExConverter.h"
-#include "codepage.h"
#include "charsets.h"
#include "FileTextEncoding.h"
#include "paths.h"
{
unsigned cp = ucr::getDefaultCodepage();
if (!ucr::CheckForInvalidUtf8(src, len))
- cp = CP_UTF8;
+ cp = ucr::CP_UTF_8;
else if (guessEncodingType & 2)
{
IExconverter *pexconv = Exconverter::getInstance();
{
case 8 + 2 + 0:
encoding.SetUnicoding(ucr::UCS2LE);
- encoding.SetCodepage(CP_UCS2LE);
+ encoding.SetCodepage(ucr::CP_UCS2LE);
encoding.m_bom = true;
break;
case 8 + 2 + 1:
encoding.SetUnicoding(ucr::UCS2BE);
- encoding.SetCodepage(CP_UCS2BE);
+ encoding.SetCodepage(ucr::CP_UCS2BE);
encoding.m_bom = true;
break;
case 8 + 1:
encoding.SetUnicoding(ucr::UTF8);
- encoding.SetCodepage(CP_UTF8);
+ encoding.SetCodepage(ucr::CP_UTF_8);
encoding.m_bom = true;
break;
default:
<ClCompile Include="..\..\..\Src\CompareEngines\ByteComparator.cpp" />\r
<ClCompile Include="..\..\..\Src\CompareEngines\ByteCompare.cpp" />\r
<ClCompile Include="..\..\..\Src\charsets.c" />\r
- <ClCompile Include="..\..\..\Src\codepage.cpp" />\r
<ClCompile Include="..\..\..\Src\codepage_detect.cpp" />\r
<ClCompile Include="..\..\..\Src\CompareEngines\TimeSizeCompare.cpp" />\r
<ClCompile Include="..\..\..\Src\CompareOptions.cpp" />\r
<ClCompile Include="..\ByteCompare\ByteCompare_test.cpp" />\r
<ClCompile Include="..\Encoding\charsets_test.cpp" />\r
<ClCompile Include="..\Encoding\codepage_detect_test.cpp" />\r
- <ClCompile Include="..\Encoding\codepage_test.cpp" />\r
<ClCompile Include="..\DirItem\DirItem_test.cpp" />\r
<ClCompile Include="..\Environment\Environemt_test.cpp" />\r
<ClCompile Include="..\FileFilter\FileFilterHelper_test.cpp" />\r
<ClInclude Include="..\..\..\Src\CompareEngines\ByteComparator.h" />\r
<ClInclude Include="..\..\..\Src\CompareEngines\ByteCompare.h" />\r
<ClInclude Include="..\..\..\Src\charsets.h" />\r
- <ClInclude Include="..\..\..\Src\codepage.h" />\r
<ClInclude Include="..\..\..\Src\codepage_detect.h" />\r
<ClInclude Include="..\..\..\Src\CompareEngines\TimeSizeCompare.h" />\r
<ClInclude Include="..\..\..\Src\CompareOptions.h" />\r
<ClCompile Include="..\..\..\Src\charsets.c">\r
<Filter>Source Files</Filter>\r
</ClCompile>\r
- <ClCompile Include="..\..\..\Src\codepage.cpp">\r
- <Filter>Source Files</Filter>\r
- </ClCompile>\r
<ClCompile Include="..\..\..\Src\codepage_detect.cpp">\r
<Filter>Source Files</Filter>\r
</ClCompile>\r
<ClCompile Include="..\Encoding\codepage_detect_test.cpp">\r
<Filter>Tests</Filter>\r
</ClCompile>\r
- <ClCompile Include="..\Encoding\codepage_test.cpp">\r
- <Filter>Tests</Filter>\r
- </ClCompile>\r
<ClCompile Include="..\DirItem\DirItem_test.cpp">\r
<Filter>Tests</Filter>\r
</ClCompile>\r
<ClInclude Include="..\..\..\Src\charsets.h">\r
<Filter>Header Files</Filter>\r
</ClInclude>\r
- <ClInclude Include="..\..\..\Src\codepage.h">\r
- <Filter>Header Files</Filter>\r
- </ClInclude>\r
<ClInclude Include="..\..\..\Src\codepage_detect.h">\r
<Filter>Header Files</Filter>\r
</ClInclude>\r
#include <gtest/gtest.h>
-#include "codepage.h"
#include "unicoder.h"
namespace
int n;
// UTF8->UCS2LE
- n = ucr::CrossConvert(str_utf8, strlen(str_utf8), (char *)wbuf, sizeof(wbuf), CP_UTF8, 1200, &lossy);
+ n = ucr::CrossConvert(str_utf8, strlen(str_utf8), (char *)wbuf, sizeof(wbuf), ucr::CP_UTF_8, 1200, &lossy);
EXPECT_STREQ(str_ucs2, wbuf);
EXPECT_EQ(wcslen(str_ucs2) * sizeof(wchar_t), n);
EXPECT_EQ(wcslen(str_ucs2) * sizeof(wchar_t), n);
// UTF8->UCS2BE
- n = ucr::CrossConvert(str_utf8, strlen(str_utf8), (char *)wbuf, sizeof(wbuf), CP_UTF8, 1201, &lossy);
+ n = ucr::CrossConvert(str_utf8, strlen(str_utf8), (char *)wbuf, sizeof(wbuf), ucr::CP_UTF_8, 1201, &lossy);
EXPECT_STREQ(str_ucs2be, wbuf);
EXPECT_EQ(wcslen(str_ucs2be) * sizeof(wchar_t), n);
// UCS2BE->UTF8
- n = ucr::CrossConvert((char *)str_ucs2be, wcslen(str_ucs2be) * sizeof(wchar_t), buf, sizeof(buf), 1201, CP_UTF8, &lossy);
+ n = ucr::CrossConvert((char *)str_ucs2be, wcslen(str_ucs2be) * sizeof(wchar_t), buf, sizeof(buf), 1201, ucr::CP_UTF_8, &lossy);
EXPECT_STREQ(str_utf8, buf);
EXPECT_EQ(strlen(str_utf8), n);